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