update sitemap
This commit is contained in:
parent
18ecac9990
commit
d104f0292b
|
@ -1,3 +1,4 @@
|
|||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
Sitemap: https://grammar.lingdocs.com/sitemap.xml
|
||||
|
|
|
@ -7,32 +7,38 @@ console.log("generating sitemap.xml");
|
|||
const indexText = fs.readFileSync("./src/content/index.ts", "utf-8");
|
||||
const contentTreeRaw = indexText.split("/* content-tree */")[1];
|
||||
const safeContentTreeText = contentTreeRaw
|
||||
.split("\n")
|
||||
.filter(l => !l.includes(`"import":`))
|
||||
.join("\n");
|
||||
.split("\n")
|
||||
.filter((l) => !l.includes(`"import":`))
|
||||
.join("\n");
|
||||
const contentTree = JSON.parse(safeContentTreeText);
|
||||
|
||||
const urls = contentTree.reduce((acc, section) => {
|
||||
const urls = contentTree.reduce(
|
||||
(acc, section) => {
|
||||
if ("slug" in section) {
|
||||
return [
|
||||
...acc,
|
||||
`${base}/${section.slug}`,
|
||||
];
|
||||
return [...acc, `${base}/${section.slug}/`];
|
||||
} else {
|
||||
return [
|
||||
...acc,
|
||||
...section.chapters.map(x => `${base}/${section.subdirectory}/${x.slug}`),
|
||||
];
|
||||
return [
|
||||
...acc,
|
||||
...section.chapters.map(
|
||||
(x) => `${base}/${section.subdirectory}/${x.slug}/`
|
||||
),
|
||||
];
|
||||
}
|
||||
}, [base]);
|
||||
},
|
||||
[`${base}`]
|
||||
);
|
||||
|
||||
const siteMap = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${urls.map(u => ` <url>
|
||||
${urls
|
||||
.map(
|
||||
(u) => ` <url>
|
||||
<loc>${u}</loc>
|
||||
</url>
|
||||
`).join("")}
|
||||
</urlset>
|
||||
`
|
||||
)
|
||||
.join("")}
|
||||
</urlset>
|
||||
`;
|
||||
|
||||
fs.writeFileSync("./public/sitemap.xml", siteMap);
|
||||
|
|
Loading…
Reference in New Issue