-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ac4201
commit 9ba89a8
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> </urlset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { writeFileSync } from 'fs' | ||
|
||
import { globby } from 'globby' | ||
import prettier from 'prettier' | ||
|
||
async function generate() { | ||
const prettierConfig = await prettier.resolveConfig('./.prettierrc.js') | ||
const pages = await globby([ | ||
'pages/*.tsx', | ||
'data/**/*.mdx', | ||
'!data/*.mdx', | ||
'!pages/_*.tsx', | ||
'!pages/api', | ||
'!pages/404.tsx', | ||
]) | ||
|
||
const sitemap = ` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
${pages | ||
.map(page => { | ||
const path = page | ||
.replace('pages', '') | ||
.replace('data', '') | ||
.replace('.tsx', '') | ||
.replace('.mdx', '') | ||
const route = path === '/index' ? '' : path | ||
return ` | ||
<url> | ||
<loc>${`https://cretu.dev${route}`}</loc> | ||
</url> | ||
` | ||
}) | ||
.join('')} | ||
</urlset> | ||
` | ||
|
||
const formatted = prettier.format(sitemap, { | ||
...prettierConfig, | ||
parser: 'html', | ||
}) | ||
|
||
// eslint-disable-next-line no-sync | ||
writeFileSync('public/sitemap.xml', formatted) | ||
} | ||
|
||
generate() |