Skip to content

Commit

Permalink
Merge pull request #638 from iamvishnusankar/feat/static-export
Browse files Browse the repository at this point in the history
[Feat] Support Statically Exported Websites without next export
  • Loading branch information
iamvishnusankar authored May 18, 2023
2 parents f9381ec + f083088 commit 6c4c35c
Show file tree
Hide file tree
Showing 34 changed files with 502 additions and 204 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Above is the minimal configuration to split a large sitemap. When the number of
| property | description | type |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ |
| siteUrl | Base url of your website | string |
| output (optional) | Next.js output modes. [Check documentation](https://nextjs.org/docs/pages/api-reference/next-config-js/output). | `standalone`, `export` |
| changefreq (optional) | Change frequency. Default `daily` | string |
| priority (optional) | Priority. Default `0.7` | number |
| sitemapBaseFileName (optional) | The name of the generated sitemap file before the file extension. Default `"sitemap"` | string |
Expand Down
2 changes: 1 addition & 1 deletion azure-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 4.0$(rev:.r)
name: 4.1$(rev:.r)
trigger:
branches:
include:
Expand Down
6 changes: 3 additions & 3 deletions examples/amp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"postbuild": "next-sitemap"
},
"dependencies": {
"@types/react-dom": "^18.0.11",
"next": "^13.2.4",
"@types/react-dom": "^18.2.4",
"next": "^13.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react": "^18.2.6",
"next-sitemap": "*"
}
}
10 changes: 5 additions & 5 deletions examples/app-dir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"postbuild": "next-sitemap"
},
"dependencies": {
"@types/react-dom": "^18.0.11",
"next": "^13.2.4",
"@types/react-dom": "^18.2.4",
"next": "^13.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@corex/workspace": "^4.0.37",
"@types/react": "^18.2.0",
"@corex/workspace": "^4.0.43",
"@types/react": "^18.2.6",
"next-sitemap": "*",
"turbo": "^1.8.3"
"turbo": "^1.9.8"
}
}
6 changes: 3 additions & 3 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"postbuild": "next-sitemap"
},
"dependencies": {
"@types/react-dom": "^18.0.11",
"next": "^13.2.4",
"@types/react-dom": "^18.2.4",
"next": "^13.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react": "^18.2.6",
"next-sitemap": "*"
}
}
6 changes: 3 additions & 3 deletions examples/commonjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"postbuild": "next-sitemap"
},
"dependencies": {
"@types/react-dom": "^18.0.11",
"next": "^13.2.4",
"@types/react-dom": "^18.2.4",
"next": "^13.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react": "^18.2.6",
"next-sitemap": "*"
}
}
6 changes: 3 additions & 3 deletions examples/custom-config-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"postbuild": "next-sitemap --config=awesome-sitemap.config.js"
},
"dependencies": {
"@types/react-dom": "^18.0.11",
"next": "^13.2.4",
"@types/react-dom": "^18.2.4",
"next": "^13.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react": "^18.2.6",
"next-sitemap": "*"
}
}
6 changes: 3 additions & 3 deletions examples/custom-overrides/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"postbuild": "next-sitemap"
},
"dependencies": {
"@types/react-dom": "^18.0.11",
"next": "^13.2.4",
"@types/react-dom": "^18.2.4",
"next": "^13.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react": "^18.2.6",
"next-sitemap": "*"
}
}
6 changes: 3 additions & 3 deletions examples/custom-robots-txt-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"postbuild": "next-sitemap"
},
"dependencies": {
"@types/react-dom": "^18.0.11",
"next": "^13.2.4",
"@types/react-dom": "^18.2.4",
"next": "^13.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react": "^18.2.6",
"next-sitemap": "*"
}
}
6 changes: 3 additions & 3 deletions examples/no-index-sitemaps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"postbuild": "next-sitemap"
},
"dependencies": {
"@types/react-dom": "^18.0.11",
"next": "^13.2.4",
"@types/react-dom": "^18.2.4",
"next": "^13.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react": "^18.2.6",
"next-sitemap": "*"
}
}
35 changes: 35 additions & 0 deletions examples/static-export/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
34 changes: 34 additions & 0 deletions examples/static-export/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
9 changes: 9 additions & 0 deletions examples/static-export/app/about/more/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const HomePage: React.FC<any> = () => {
return (
<div>
<h1>About more page</h1>
</div>
)
}

export default HomePage
9 changes: 9 additions & 0 deletions examples/static-export/app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const HomePage: React.FC<any> = () => {
return (
<div>
<h1>About page</h1>
</div>
)
}

export default HomePage
11 changes: 11 additions & 0 deletions examples/static-export/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
9 changes: 9 additions & 0 deletions examples/static-export/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const HomePage: React.FC<any> = () => {
return (
<div>
<h1>HomePage Component</h1>
</div>
)
}

export default HomePage
9 changes: 9 additions & 0 deletions examples/static-export/next-sitemap.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/** @type {import('next-sitemap').IConfig} */
const config = {
siteUrl: process.env.SITE_URL || 'https://example.com',
generateRobotsTxt: true,
output: 'export', // Set static output here
}

module.exports = config
6 changes: 6 additions & 0 deletions examples/static-export/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
}

module.exports = nextConfig
11 changes: 11 additions & 0 deletions examples/static-export/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "static-export",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build && next-sitemap",
"start": "next start",
"lint": "next lint"
}
}
28 changes: 28 additions & 0 deletions examples/static-export/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
6 changes: 3 additions & 3 deletions examples/with-next-sitemap-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"postbuild": "next-sitemap"
},
"dependencies": {
"@types/react-dom": "^18.0.11",
"next": "^13.2.4",
"@types/react-dom": "^18.2.4",
"next": "^13.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react": "^18.2.6",
"next-sitemap": "*"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"format": "prettier --write \"**/*.{js,mjs,cjs,jsx,json,ts,tsx,md,mdx,css,html,yml,yaml,scss,less,graphql,graphqls,gql}\""
},
"devDependencies": {
"@corex/workspace": "^4.0.29",
"turbo": "^1.8.2"
"@corex/workspace": "^4.0.43",
"turbo": "^1.9.8"
}
}
3 changes: 2 additions & 1 deletion packages/next-sitemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"postbuild": "tsc --module commonjs --outDir dist/cjs"
},
"dependencies": {
"@corex/deepmerge": "^4.0.37",
"@corex/deepmerge": "^4.0.43",
"fast-glob": "^3.2.12",
"minimist": "^1.2.8"
},
"peerDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions packages/next-sitemap/src/builders/url-set-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ export class UrlSetBuilder {

// Init all page keys
const allKeys = [
...Object.keys(this.manifest?.build.pages),
...Object.keys(this.manifest?.build?.pages ?? {}),
...(this.manifest?.build?.ampFirstPages ?? []),
...(this.manifest?.preRender
? Object.keys(this.manifest?.preRender.routes)
? Object.keys(this.manifest?.preRender?.routes ?? {})
: []),
...(this.manifest?.staticExportPages ?? []),
]

// Filter out next.js internal urls and generate urls based on sitemap
Expand Down
7 changes: 5 additions & 2 deletions packages/next-sitemap/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export class CLI {
const { config, runtimePaths } = await new ConfigParser().loadConfig()

// Load next.js manifest
const manifest = await new ManifestParser().loadManifest(runtimePaths)
const manifest = await new ManifestParser().loadManifest(
config,
runtimePaths
)

// Generate url set
const urlSet = await new UrlSetBuilder(config, manifest).createUrlSet()
Expand Down Expand Up @@ -49,6 +52,6 @@ export class CLI {
* @returns
*/
async execute() {
return this.main().then(Logger.generationCompleted)
return this.main().then(Logger.generationCompleted).catch(Logger.error)
}
}
Loading

0 comments on commit 6c4c35c

Please sign in to comment.