Unverified Commit 0f4333a5 authored by Max Proske's avatar Max Proske Committed by GitHub

chore(examples): Convert `blog` example to TypeScript (#38095)

Converted Blog example over to TypeScript to match the Contribution guidelines.

I also simplified the example by removing `_document.js` and prettier from `package.json`.

## Documentation / Examples

- [X] Make sure the linting passes by running `pnpm lint`
- [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 3b3d249c
......@@ -33,4 +33,8 @@ yarn-error.log*
# vercel
.vercel
public/feed.xml
\ No newline at end of file
# nextra
public/feed.xml
# typescript
*.tsbuildinfo
......@@ -14,7 +14,7 @@ https://demo.vercel.blog
1. Update your name in `theme.config.js` or change the footer.
1. Update your name and site URL for the RSS feed in `scripts/gen-rss.js`.
1. Update the meta tags in `pages/_document.js`.
1. Update the meta tags in `pages/_document.tsx`.
1. Update the posts inside `pages/posts/*.md` with your own content.
## Deploy your own
......
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
const withNextra = require('nextra')('nextra-theme-blog', './theme.config.js')
module.exports = withNextra()
/** @type {import('next').NextConfig} */
const withNextra = require('nextra')({
theme: 'nextra-theme-blog',
themeConfig: './theme.config.js',
// optional: add `unstable_staticImage: true` to enable Nextra's auto image import
})
const nextConfig = {
// any configs you need
}
module.exports = withNextra(nextConfig)
......@@ -6,19 +6,18 @@
"start": "next start"
},
"dependencies": {
"gray-matter": "^4.0.2",
"gray-matter": "^4.0.3",
"next": "latest",
"nextra": "^2.0.0-beta.5",
"nextra-theme-blog": "^0.1.5",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"nextra-theme-blog": "^2.0.0-beta.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rss": "^1.2.2"
},
"prettier": {
"arrowParens": "always",
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"semi": false
"devDependencies": {
"@types/node": "^18.0.0",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"typescript": "^4.7.4"
}
}
import 'nextra-theme-blog/style.css'
import type { AppProps } from 'next/app'
import Head from 'next/head'
import '../styles/main.css'
export default function Nextra({ Component, pageProps }) {
export default function App({ Component, pageProps }: AppProps) {
return (
<>
<Head>
......
import Document, { Html, Head, Main, NextScript } from 'next/document'
import Document, {
Html,
Head,
Main,
NextScript,
DocumentContext,
} from 'next/document'
class MyDocument extends Document {
static async getInitialProps(ctx) {
static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}
......@@ -11,7 +17,7 @@ class MyDocument extends Document {
title: 'Next.js Blog Starter Kit',
description: 'Clone and deploy your own Next.js portfolio in minutes.',
image:
'https://assets.vercel.com/image/upload/q_auto/front/vercel/dps.png'
'https://assets.vercel.com/image/upload/q_auto/front/vercel/dps.png',
}
return (
......
......@@ -7,7 +7,7 @@ async function generate() {
const feed = new RSS({
title: 'Your Name',
site_url: 'https://yoursite.com',
feed_url: 'https://yoursite.com/feed.xml'
feed_url: 'https://yoursite.com/feed.xml',
})
const posts = await fs.readdir(path.join(__dirname, '..', 'pages', 'posts'))
......@@ -27,7 +27,7 @@ async function generate() {
date: frontmatter.data.date,
description: frontmatter.data.description,
categories: frontmatter.data.tag.split(', '),
author: frontmatter.data.author
author: frontmatter.data.author,
})
})
)
......
......@@ -16,5 +16,5 @@ export default {
}
`}</style>
</footer>
)
),
}
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment