Added next-sitemap example (#15997)
Co-authored-by: Luis Alvarez <luis@vercel.com>
This commit is contained in:
parent
a81ab3baee
commit
17aa4b458e
7 changed files with 147 additions and 0 deletions
23
examples/with-next-sitemap/README.md
Normal file
23
examples/with-next-sitemap/README.md
Normal 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)).
|
2
examples/with-next-sitemap/next-env.d.ts
vendored
Normal file
2
examples/with-next-sitemap/next-env.d.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/// <reference types="next" />
|
||||
/// <reference types="next/types/global" />
|
12
examples/with-next-sitemap/next-sitemap.js
Normal file
12
examples/with-next-sitemap/next-sitemap.js
Normal 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',
|
||||
],
|
||||
},
|
||||
}
|
21
examples/with-next-sitemap/package.json
Normal file
21
examples/with-next-sitemap/package.json
Normal 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"
|
||||
}
|
||||
}
|
34
examples/with-next-sitemap/pages/[dynamic].tsx
Normal file
34
examples/with-next-sitemap/pages/[dynamic].tsx
Normal 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
|
36
examples/with-next-sitemap/pages/index.tsx
Normal file
36
examples/with-next-sitemap/pages/index.tsx
Normal 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
|
19
examples/with-next-sitemap/tsconfig.json
Normal file
19
examples/with-next-sitemap/tsconfig.json
Normal 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"]
|
||||
}
|
Loading…
Reference in a new issue