Skip to content

Commit d822bb6

Browse files
committed
✨ Add sitemap.xml to interactors site.
We're going to use sitemaps as a standards based mechanism to compose our static websites. This adds a sitemap for the interactors website so that it can be "mounted" on frontside.com by enabling the docusaurus "sitemap" plugin. Docusaurus does a bunch of dynamic chicanery with React, Webpack and code-splitting to render a static webpage because reasons, so we add a synthetic entry to the sitemap that serves as an index for all dynamic JavaScript resources. That way, the static site generator knows to download all those resources ahead of time even though they are not referenced in any page.
1 parent 3bc4d11 commit d822bb6

File tree

6 files changed

+122
-5
lines changed

6 files changed

+122
-5
lines changed

.github/workflows/website.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Website
2+
3+
on:
4+
push:
5+
branches:
6+
- www
7+
8+
jobs:
9+
website:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: volta-cli/action@v4
18+
19+
- run: yarn install && yarn build
20+
working-directory: website
21+
22+
- uses: denoland/deployctl@v1
23+
with:
24+
project: interactors
25+
entrypoint: https://deno.land/std@0.140.0/http/file_server.ts
26+
root: website/public/interactors

website/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ build
1111
docs/**/api
1212
sidebars
1313
public
14+
/node_modules

website/docusaurus.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = {
22
title: "Interactors",
33
tagline: "Page Objects for components libraries",
4-
url: "https://frontside.com/",
5-
baseUrl: "/interactors/",
4+
url: "https://interactors.deno.dev/",
5+
baseUrl: "/",
66
onBrokenLinks: "throw",
77
favicon: "images/favicon-interactors.png",
88
organizationName: "thefrontside",
@@ -119,6 +119,7 @@ module.exports = {
119119
theme: {
120120
customCss: require.resolve("./src/css/custom.css"),
121121
},
122+
sitemap: {}
122123
},
123124
],
124125
],

website/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"start": "docusaurus start",
7-
"build": "docusaurus build --out-dir public/interactors",
7+
"build": "docusaurus build --out-dir public/interactors && node sitemap.mjs",
88
"swizzle": "docusaurus swizzle",
99
"deploy": "docusaurus deploy",
1010
"serve": "docusaurus serve --dir public/interactors"
@@ -21,7 +21,8 @@
2121
"email-validator": "^2.0.4",
2222
"jsonp": "^0.2.1",
2323
"react": "^16.8.4",
24-
"react-dom": "^16.8.4"
24+
"react-dom": "^16.8.4",
25+
"xml2js": "^0.6.2"
2526
},
2627
"browserslist": {
2728
"production": [
@@ -34,5 +35,9 @@
3435
"last 1 firefox version",
3536
"last 1 safari version"
3637
]
38+
},
39+
"volta": {
40+
"node": "16.20.2",
41+
"yarn": "1.22.22"
3742
}
3843
}

website/sitemap.mjs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Add indexes of all dynamically loaded assets so that they can be staticalized */
2+
3+
import { readFileSync, writeFileSync, readdirSync } from "node:fs";
4+
import { Parser, Builder } from "xml2js";
5+
6+
const [parser, builder] = [new Parser(), new Builder()];
7+
8+
const sitemapXML = readFileSync("./public/interactors/sitemap.xml");
9+
10+
const sitemap = await parser.parseStringPromise(sitemapXML);
11+
12+
// ideally we would use the docusaurs sitemap plugin to do this
13+
// but support for plugins came with => 3.0.0 and upgrade no thank you.
14+
sitemap.urlset.url.push({
15+
loc: 'https://interactors.deno.dev/assets/js/index.html',
16+
}, {
17+
loc: 'https://interactors.deno.dev/images/index.html'
18+
});
19+
20+
writeFileSync("./public/interactors/sitemap.xml", builder.buildObject(sitemap));
21+
22+
const assets = readdirSync("./public/interactors/assets/js");
23+
24+
writeFileSync("./public/interactors/assets/js/index.html",`
25+
<html>
26+
<head>
27+
${assets.map((asset) => ` <link rel="asset" href="${asset}"/>`).join("\n")}
28+
</head>
29+
<body>
30+
<h1> JavaScript Index</h1>
31+
<ul>
32+
33+
${assets.map((asset) => ` <li><a href="${asset}">${asset}</a></li>`).join("\n")}
34+
35+
</ul>
36+
<body>
37+
<html>
38+
39+
`);
40+
41+
const images = readdirSync("./public/interactors/images");
42+
43+
writeFileSync("./public/interactors/images/index.html",`
44+
<html>
45+
<head>
46+
${images.map((image) => ` <link rel="asset" href="${image}"/>`).join("\n")}
47+
</head>
48+
<body>
49+
<h1> JavaScript Index</h1>
50+
<ul>
51+
52+
${images.map((image) => ` <li><a href="${image}">${image}</a></li>`).join("\n")}
53+
54+
</ul>
55+
<body>
56+
<html>
57+
58+
`);

website/yarn.lock

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,7 @@
25782578
"@docusaurus/theme-classic" "2.0.0-beta.9"
25792579
"@docusaurus/theme-search-algolia" "2.0.0-beta.9"
25802580

2581-
"@docusaurus/react-loadable@5.5.2", "react-loadable@npm:@docusaurus/react-loadable@5.5.2":
2581+
"@docusaurus/react-loadable@5.5.2":
25822582
version "5.5.2"
25832583
resolved "https://registry.yarnpkg.com/@docusaurus/react-loadable/-/react-loadable-5.5.2.tgz#81aae0db81ecafbdaee3651f12804580868fa6ce"
25842584
integrity sha512-A3dYjdBGuy0IGT+wyLIGIKLRE+sAk1iNk0f1HjNDysO7u8lhL4N3VEm+FAubmJbAztn94F7MxBTPmnixbiyFdQ==
@@ -7825,6 +7825,14 @@ react-loadable-ssr-addon-v5-slorber@^1.0.1:
78257825
dependencies:
78267826
"@babel/runtime" "^7.10.3"
78277827

7828+
"react-loadable@npm:@docusaurus/react-loadable@5.5.2":
7829+
version "5.5.2"
7830+
resolved "https://registry.yarnpkg.com/@docusaurus/react-loadable/-/react-loadable-5.5.2.tgz#81aae0db81ecafbdaee3651f12804580868fa6ce"
7831+
integrity sha512-A3dYjdBGuy0IGT+wyLIGIKLRE+sAk1iNk0f1HjNDysO7u8lhL4N3VEm+FAubmJbAztn94F7MxBTPmnixbiyFdQ==
7832+
dependencies:
7833+
"@types/react" "*"
7834+
prop-types "^15.6.2"
7835+
78287836
react-router-config@^5.1.1:
78297837
version "5.1.1"
78307838
resolved "https://registry.yarnpkg.com/react-router-config/-/react-router-config-5.1.1.tgz#0f4263d1a80c6b2dc7b9c1902c9526478194a988"
@@ -8255,6 +8263,11 @@ safe-buffer@>=5.1.0, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@~5.2.0:
82558263
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
82568264
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
82578265

8266+
sax@>=0.6.0:
8267+
version "1.4.1"
8268+
resolved "https://registry.yarnpkg.com/sax/-/sax-1.4.1.tgz#44cc8988377f126304d3b3fc1010c733b929ef0f"
8269+
integrity sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==
8270+
82588271
sax@^1.2.4, sax@~1.2.4:
82598272
version "1.2.4"
82608273
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
@@ -9545,6 +9558,19 @@ xml-js@^1.6.11:
95459558
dependencies:
95469559
sax "^1.2.4"
95479560

9561+
xml2js@^0.6.2:
9562+
version "0.6.2"
9563+
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.6.2.tgz#dd0b630083aa09c161e25a4d0901e2b2a929b499"
9564+
integrity sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==
9565+
dependencies:
9566+
sax ">=0.6.0"
9567+
xmlbuilder "~11.0.0"
9568+
9569+
xmlbuilder@~11.0.0:
9570+
version "11.0.1"
9571+
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3"
9572+
integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==
9573+
95489574
xtend@^4.0.0, xtend@^4.0.1:
95499575
version "4.0.2"
95509576
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"

0 commit comments

Comments
 (0)