Skip to content

Commit

Permalink
CLDR-17803 site: add sitemap.md, fix links
Browse files Browse the repository at this point in the history
  • Loading branch information
srl295 committed Sep 9, 2024
1 parent 49db580 commit 588027f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/site/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/assets/json
/assets/vendor
/sitemap.xml
/sitemap.md
4 changes: 1 addition & 3 deletions docs/site/_layouts/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
<!-- Vue mount here -->
</div>
</div>
<div class="message"><i>This navigation UI is temporary, just to give access to the pages.</i></div>
<div class="message"><i>This navigation UI is temporary, just to give access to the pages.</i></div> <div class="bar"><a href="/sitemap" class="bar">Site Map</a></div>

<!-- <div class="bar"><a href="http://www.unicode.org" class="bar">Home</a>
| <a href="http://www.unicode.org/search/" class="bar">Search</a></div> -->
</header>


Expand Down
16 changes: 11 additions & 5 deletions docs/site/assets/js/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { default as matter } from "gray-matter";
import { SitemapStream, streamToPromise } from "sitemap";
import { Readable } from "node:stream";

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

async function processFile(d, fullPath, out) {
const f = await fs.readFile(fullPath, "utf-8");
Expand Down Expand Up @@ -43,9 +43,9 @@ async function traverse(d, out) {
}


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


Expand All @@ -54,14 +54,20 @@ async function writeSiteMaps(out) {
const links = await Promise.all(out.all.map(async ({ fullPath, title }) => {
const stat = await fs.stat(fullPath);
return {
url: md2html(`/${fullPath}`),
url: dropmd(`/${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');
const coll = new Intl.Collator(['und']);
const allSorted = [...out.all].sort((a, b) => coll.compare(a.fullPath, b.fullPath));
await fs.writeFile('./sitemap.md', `---\ntitle: Site Map\n---\n\n` +
allSorted.map(({fullPath, title})=>
`- [/${fullPath}](/${dropmd(fullPath)}) - ${title}`).join('\n'), 'utf-8');
console.log('Wrote sitemap.md');
}

async function main() {
Expand Down

0 comments on commit 588027f

Please sign in to comment.