Added next-sitemap example (#15997)

Co-authored-by: Luis Alvarez <luis@vercel.com>
This commit is contained in:
Vishnu Sankar 2020-08-18 09:46:42 +05:30 committed by GitHub
parent a81ab3baee
commit 17aa4b458e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 147 additions and 0 deletions

View file

@ -0,0 +1,23 @@
# next-sitemap example
This example uses [`next-sitemap`](https://github.com/iamvishnusankar/next-sitemap) to generate a sitemap file for all pages (including all pre-rendered/static pages).
`next-sitemap` allows the generation of sitemaps along with `robots.txt` and provides the feature to split large sitemaps into multiple files. Checkout the [`next-sitemap` documentation](https://github.com/iamvishnusankar/next-sitemap) to learn more.
## Deploy your own
Deploy the example using [Vercel](https://vercel.com):
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/with-next-sitemap)
## How to use
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
```bash
npx create-next-app --example with-next-sitemap with-next-sitemap-app
# or
yarn create next-app --example with-next-sitemap with-next-sitemap-app
```
Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).

View file

@ -0,0 +1,2 @@
/// <reference types="next" />
/// <reference types="next/types/global" />

View file

@ -0,0 +1,12 @@
module.exports = {
siteUrl: 'https://example.com',
generateRobotsTxt: true,
// optional
robotsTxtOptions: {
additionalSitemaps: [
'https://example.com/my-custom-sitemap-1.xml',
'https://example.com/my-custom-sitemap-2.xml',
'https://example.com/my-custom-sitemap-3.xml',
],
},
}

View file

@ -0,0 +1,21 @@
{
"name": "with-next-sitemap",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"postbuild": "next-sitemap"
},
"dependencies": {
"next": "latest",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@types/node": "14.6.0",
"@types/react": "^16.9.45",
"next-sitemap": "latest"
}
}

View file

@ -0,0 +1,34 @@
import { GetStaticPaths, GetStaticProps } from 'next'
import { useRouter } from 'next/router'
const DynamicPage = () => {
const { query } = useRouter()
return (
<div>
<h1>Dynamic Page</h1>
<h2>Query: {query.dynamic}</h2>
</div>
)
}
export const getStaticProps: GetStaticProps = async () => {
return {
props: {
dynamic: 'hello',
},
}
}
export const getStaticPaths: GetStaticPaths = async () => {
return {
paths: [...Array(10000)].map((_, index) => ({
params: {
dynamic: `page-${index}`,
},
})),
fallback: false,
}
}
export default DynamicPage

View file

@ -0,0 +1,36 @@
import Link from 'next/link'
const HelloWorld = () => (
<div>
<h1>Hello World Page</h1>
<ol>
<li>
<Link href="/[dynamic]" as="/page-1">
<a>Link to dynamic page 1</a>
</Link>
</li>
<li>
<Link href="/[dynamic]" as="/page-2">
<a>Link to dynamic page 2</a>
</Link>
</li>
<li>
<Link href="/[dynamic]" as="/page-3">
<a>Link to dynamic page 3</a>
</Link>
</li>
<li>
<Link href="/[dynamic]" as="/page-4">
<a>Link to dynamic page 4</a>
</Link>
</li>
<li>
<Link href="/[dynamic]" as="/page-5">
<a>Link to dynamic page 5</a>
</Link>
</li>
</ol>
</div>
)
export default HelloWorld

View file

@ -0,0 +1,19 @@
{
"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"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}