Skip to content

Commit

Permalink
CLDR-17803 site: add sitemap.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
srl295 committed Sep 9, 2024
1 parent 2ebe44f commit 49db580
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/site/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules
/assets/json
/assets/vendor
/sitemap.xml
26 changes: 26 additions & 0 deletions docs/site/assets/js/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as fs from "node:fs/promises";
import * as path from "node:path";
import { default as process } from "node:process";
import { default as matter } from "gray-matter";
import { SitemapStream, streamToPromise } from "sitemap";
import { Readable } from "node:stream";

const SKIP_THESE = /(node_modules|\.jekyll-cache)/;

Expand Down Expand Up @@ -40,6 +42,28 @@ async function traverse(d, out) {
return Promise.all(promises);
}


/** replace a/b/c.md with a/b/c.html */
function md2html(p) {
return p.replace(/\.md$/, ".html");
}


async function writeSiteMaps(out) {
// simple list of links
const links = await Promise.all(out.all.map(async ({ fullPath, title }) => {
const stat = await fs.stat(fullPath);
return {
url: md2html(`/${fullPath}`),
lastmod: stat.mtime.toISOString(),
};
}));
const stream = new SitemapStream({ hostname: 'https://cldr.unicode.org'});
const data = (await streamToPromise(Readable.from(links).pipe(stream))).toString();
await fs.writeFile('./sitemap.xml', data, 'utf-8');
console.log('Wrote sitemap.xml');
}

async function main() {
const out = {
all: [],
Expand All @@ -48,6 +72,8 @@ async function main() {
await fs.mkdir("assets/json/", { recursive: true });
await traverse(".", out);
await fs.writeFile("assets/json/tree.json", JSON.stringify(out, null, " "));
console.log('Wrote assets/json/tree.json');
await writeSiteMaps(out);
}

main().then(
Expand Down
42 changes: 42 additions & 0 deletions docs/site/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"private": true,
"dependencies": {
"gray-matter": "^4.0.3",
"sitemap": "^8.0.0",
"vue": "^3.5.0"
}
}
1 change: 1 addition & 0 deletions docs/site/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sitemap: https://cldr.unicode.org/sitemap.xml

0 comments on commit 49db580

Please sign in to comment.