[site/seo]: create script file to generate sitemap
This commit is contained in:
parent
dfb33d1c7b
commit
4c0c3770b6
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
# production
|
||||
/build
|
||||
public/sitemap.xml
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
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/!(\\[**])*.js*",
|
||||
"content/**/*.md*",
|
||||
"!pages/_*.js*",
|
||||
"!pages/api",
|
||||
"!pages/404.js*",
|
||||
]);
|
||||
|
||||
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("content", "")
|
||||
.replace(/.jsx*/, "")
|
||||
.replace(/.mdx*/, "");
|
||||
const route = path === "/index" ? "" : path;
|
||||
return `
|
||||
<url>
|
||||
<loc>${`https://web3.lifeiteself.us${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();
|
||||
Loading…
Reference in New Issue