Skip to content

Commit 94b1655

Browse files
Add playground links to sitemap (#75)
1 parent f7261e7 commit 94b1655

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

build.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const marked = require('marked');
44
let sidebar = require('./src/sidebar');
55
const redirects = require('./src/redirects');
66
const menuItems = require('./src/menu.js');
7+
const examples = require('./src/examples');
78
const { encode } = require('html-entities');
89
const { JSDOM } = require('jsdom');
910
const yaml = require('js-yaml');
@@ -597,14 +598,13 @@ function generateRedirects() {
597598
function generateSitemap() {
598599
const urls = [
599600
`${site}/`,
600-
`${site}/playground/`,
601601
];
602-
602+
603603
sidebar.forEach((item) => {
604604
if (item.path) {
605605
urls.push(`${site}${item.path}/`);
606606
}
607-
607+
608608
if (item.children && Array.isArray(item.children)) {
609609
item.children.forEach((child) => {
610610
if (child.path) {
@@ -613,18 +613,32 @@ function generateSitemap() {
613613
});
614614
}
615615
});
616-
616+
617+
examples.forEach((category) => {
618+
if (category.children && Array.isArray(category.children)) {
619+
category.children.forEach((example) => {
620+
if (example.slug !== undefined) {
621+
if (example.slug === '') {
622+
urls.push(`${site}/playground/`);
623+
} else {
624+
urls.push(`${site}/playground/${example.slug}/`);
625+
}
626+
}
627+
});
628+
}
629+
});
630+
617631
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n';
618632
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n';
619-
633+
620634
urls.forEach((url) => {
621635
xml += " <url>\n";
622636
xml += ` <loc>${url}</loc>\n`;
623637
xml += " </url>\n";
624638
});
625-
639+
626640
xml += "</urlset>";
627-
641+
628642
const currentDir = process.cwd();
629643
const distDir = path.join(currentDir, 'dist');
630644
fs.writeFileSync(path.join(distDir, 'sitemap.xml'), xml);

0 commit comments

Comments
 (0)