Skip to content

Commit

Permalink
✨ Add sitemap.xml to interactors site.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cowboyd committed Sep 20, 2024
1 parent 3bc4d11 commit b730c41
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 7 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/website.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Website

on:
push:
branches:
- main
- www # remove this branch once this is merged to main
paths:
- website/**

jobs:
website:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write

steps:
- uses: actions/checkout@v4
- uses: volta-cli/action@v4

- run: yarn install && yarn build
working-directory: website

- uses: denoland/deployctl@v1
with:
project: interactors
entrypoint: https://deno.land/[email protected]/http/file_server.ts
root: website/build
1 change: 1 addition & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build
docs/**/api
sidebars
public
/node_modules
3 changes: 2 additions & 1 deletion website/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
title: "Interactors",
tagline: "Page Objects for components libraries",
url: "https://frontside.com/",
url: "https://interactors.deno.dev",
baseUrl: "/interactors/",
onBrokenLinks: "throw",
favicon: "images/favicon-interactors.png",
Expand Down Expand Up @@ -119,6 +119,7 @@ module.exports = {
theme: {
customCss: require.resolve("./src/css/custom.css"),
},
sitemap: {}
},
],
],
Expand Down
13 changes: 8 additions & 5 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
"private": true,
"scripts": {
"start": "docusaurus start",
"build": "docusaurus build --out-dir public/interactors",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"serve": "docusaurus serve --dir public/interactors"
"build": "docusaurus build --out-dir build/interactors && node sitemap.mjs",
"serve": "docusaurus serve"
},
"dependencies": {
"@docusaurus/core": "2.0.0-beta.9",
Expand All @@ -21,7 +19,8 @@
"email-validator": "^2.0.4",
"jsonp": "^0.2.1",
"react": "^16.8.4",
"react-dom": "^16.8.4"
"react-dom": "^16.8.4",
"xml2js": "^0.6.2"
},
"browserslist": {
"production": [
Expand All @@ -34,5 +33,9 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"volta": {
"node": "16.20.2",
"yarn": "1.22.22"
}
}
58 changes: 58 additions & 0 deletions website/sitemap.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Add indexes of all dynamically loaded assets so that they can be staticalized */

import { readFileSync, writeFileSync, readdirSync } from "node:fs";
import { Parser, Builder } from "xml2js";

const [parser, builder] = [new Parser(), new Builder()];

const sitemapXML = readFileSync("./build/interactors/sitemap.xml");

const sitemap = await parser.parseStringPromise(sitemapXML);

// ideally we would use the docusaurs sitemap plugin to do this
// but support for plugins came with => 3.0.0 and upgrade no thank you.
sitemap.urlset.url.push({
loc: 'https://interactors.deno.dev/interactors/assets/js/index.html',
}, {
loc: 'https://interactors.deno.dev/interactors/images/index.html'
});

writeFileSync("./build/interactors/sitemap.xml", builder.buildObject(sitemap));

const assets = readdirSync("./build/interactors/assets/js");

writeFileSync("./build/interactors/assets/js/index.html",`
<html>
<head>
${assets.map((asset) => ` <link rel="asset" href="${asset}"/>`).join("\n")}
</head>
<body>
<h1> JavaScript Index</h1>
<ul>
${assets.map((asset) => ` <li><a href="${asset}">${asset}</a></li>`).join("\n")}
</ul>
<body>
<html>
`);

const images = readdirSync("./build/interactors/images");

writeFileSync("./build/interactors/images/index.html",`
<html>
<head>
${images.map((image) => ` <link rel="asset" href="${image}"/>`).join("\n")}
</head>
<body>
<h1> JavaScript Index</h1>
<ul>
${images.map((image) => ` <li><a href="${image}">${image}</a></li>`).join("\n")}
</ul>
<body>
<html>
`);
28 changes: 27 additions & 1 deletion website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2578,7 +2578,7 @@
"@docusaurus/theme-classic" "2.0.0-beta.9"
"@docusaurus/theme-search-algolia" "2.0.0-beta.9"

"@docusaurus/[email protected]", "react-loadable@npm:@docusaurus/[email protected]":
"@docusaurus/[email protected]":
version "5.5.2"
resolved "https://registry.yarnpkg.com/@docusaurus/react-loadable/-/react-loadable-5.5.2.tgz#81aae0db81ecafbdaee3651f12804580868fa6ce"
integrity sha512-A3dYjdBGuy0IGT+wyLIGIKLRE+sAk1iNk0f1HjNDysO7u8lhL4N3VEm+FAubmJbAztn94F7MxBTPmnixbiyFdQ==
Expand Down Expand Up @@ -7825,6 +7825,14 @@ react-loadable-ssr-addon-v5-slorber@^1.0.1:
dependencies:
"@babel/runtime" "^7.10.3"

"react-loadable@npm:@docusaurus/[email protected]":
version "5.5.2"
resolved "https://registry.yarnpkg.com/@docusaurus/react-loadable/-/react-loadable-5.5.2.tgz#81aae0db81ecafbdaee3651f12804580868fa6ce"
integrity sha512-A3dYjdBGuy0IGT+wyLIGIKLRE+sAk1iNk0f1HjNDysO7u8lhL4N3VEm+FAubmJbAztn94F7MxBTPmnixbiyFdQ==
dependencies:
"@types/react" "*"
prop-types "^15.6.2"

react-router-config@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/react-router-config/-/react-router-config-5.1.1.tgz#0f4263d1a80c6b2dc7b9c1902c9526478194a988"
Expand Down Expand Up @@ -8255,6 +8263,11 @@ safe-buffer@>=5.1.0, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@~5.2.0:
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==

sax@>=0.6.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.4.1.tgz#44cc8988377f126304d3b3fc1010c733b929ef0f"
integrity sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==

sax@^1.2.4, sax@~1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
Expand Down Expand Up @@ -9545,6 +9558,19 @@ xml-js@^1.6.11:
dependencies:
sax "^1.2.4"

xml2js@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.6.2.tgz#dd0b630083aa09c161e25a4d0901e2b2a929b499"
integrity sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==
dependencies:
sax ">=0.6.0"
xmlbuilder "~11.0.0"

xmlbuilder@~11.0.0:
version "11.0.1"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3"
integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==

xtend@^4.0.0, xtend@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
Expand Down

0 comments on commit b730c41

Please sign in to comment.