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* ...@@ -33,4 +33,8 @@ yarn-error.log*
# vercel # vercel
.vercel .vercel
public/feed.xml # nextra
\ No newline at end of file public/feed.xml
# typescript
*.tsbuildinfo
...@@ -14,7 +14,7 @@ https://demo.vercel.blog ...@@ -14,7 +14,7 @@ https://demo.vercel.blog
1. Update your name in `theme.config.js` or change the footer. 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 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. 1. Update the posts inside `pages/posts/*.md` with your own content.
## Deploy your own ## 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') /** @type {import('next').NextConfig} */
module.exports = withNextra() 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 @@ ...@@ -6,19 +6,18 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"gray-matter": "^4.0.2", "gray-matter": "^4.0.3",
"next": "latest", "next": "latest",
"nextra": "^2.0.0-beta.5", "nextra": "^2.0.0-beta.5",
"nextra-theme-blog": "^0.1.5", "nextra-theme-blog": "^2.0.0-beta.5",
"react": "^17.0.2", "react": "^18.2.0",
"react-dom": "^17.0.2", "react-dom": "^18.2.0",
"rss": "^1.2.2" "rss": "^1.2.2"
}, },
"prettier": { "devDependencies": {
"arrowParens": "always", "@types/node": "^18.0.0",
"singleQuote": true, "@types/react": "^18.0.14",
"tabWidth": 2, "@types/react-dom": "^18.0.5",
"trailingComma": "none", "typescript": "^4.7.4"
"semi": false
} }
} }
import 'nextra-theme-blog/style.css' import 'nextra-theme-blog/style.css'
import type { AppProps } from 'next/app'
import Head from 'next/head' import Head from 'next/head'
import '../styles/main.css' import '../styles/main.css'
export default function Nextra({ Component, pageProps }) { export default function App({ Component, pageProps }: AppProps) {
return ( return (
<> <>
<Head> <Head>
......
import Document, { Html, Head, Main, NextScript } from 'next/document' import Document, {
Html,
Head,
Main,
NextScript,
DocumentContext,
} from 'next/document'
class MyDocument extends Document { class MyDocument extends Document {
static async getInitialProps(ctx) { static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.getInitialProps(ctx) const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps } return { ...initialProps }
} }
...@@ -11,7 +17,7 @@ class MyDocument extends Document { ...@@ -11,7 +17,7 @@ class MyDocument extends Document {
title: 'Next.js Blog Starter Kit', title: 'Next.js Blog Starter Kit',
description: 'Clone and deploy your own Next.js portfolio in minutes.', description: 'Clone and deploy your own Next.js portfolio in minutes.',
image: 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 ( return (
......
...@@ -7,7 +7,7 @@ async function generate() { ...@@ -7,7 +7,7 @@ async function generate() {
const feed = new RSS({ const feed = new RSS({
title: 'Your Name', title: 'Your Name',
site_url: 'https://yoursite.com', 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')) const posts = await fs.readdir(path.join(__dirname, '..', 'pages', 'posts'))
...@@ -27,7 +27,7 @@ async function generate() { ...@@ -27,7 +27,7 @@ async function generate() {
date: frontmatter.data.date, date: frontmatter.data.date,
description: frontmatter.data.description, description: frontmatter.data.description,
categories: frontmatter.data.tag.split(', '), categories: frontmatter.data.tag.split(', '),
author: frontmatter.data.author author: frontmatter.data.author,
}) })
}) })
) )
......
...@@ -16,5 +16,5 @@ export default { ...@@ -16,5 +16,5 @@ export default {
} }
`}</style> `}</style>
</footer> </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