-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Blackhole1123/main
Added Sitemap Generator
- Loading branch information
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() |
34fd754
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
codeedit-app – ./
codeedit-app.vercel.app
codeedit-app-codeedit.vercel.app
www.codeedit.app
codeedit.app
codeedit-app-git-main-codeedit.vercel.app