From a113c152fa453d8efa2126666ae228094fa3efb6 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Thu, 19 Sep 2024 09:29:20 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20sitemap.xml=20to=20interactor?= =?UTF-8?q?s=20site.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .github/workflows/website.yaml | 26 +++++++++++++++ website/.gitignore | 1 + website/docusaurus.config.js | 3 +- website/package.json | 13 +++++--- website/sitemap.mjs | 58 ++++++++++++++++++++++++++++++++++ website/yarn.lock | 28 +++++++++++++++- 6 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/website.yaml create mode 100644 website/sitemap.mjs diff --git a/.github/workflows/website.yaml b/.github/workflows/website.yaml new file mode 100644 index 00000000..088a4b5c --- /dev/null +++ b/.github/workflows/website.yaml @@ -0,0 +1,26 @@ +name: Website + +on: + push: + branches: + - www + +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/std@0.224.0/http/file_server.ts + root: website/build diff --git a/website/.gitignore b/website/.gitignore index 550a50e6..80c13723 100644 --- a/website/.gitignore +++ b/website/.gitignore @@ -11,3 +11,4 @@ build docs/**/api sidebars public +/node_modules diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index d7375bdf..ffe9d84c 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -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", @@ -119,6 +119,7 @@ module.exports = { theme: { customCss: require.resolve("./src/css/custom.css"), }, + sitemap: {} }, ], ], diff --git a/website/package.json b/website/package.json index f8cf789d..c3b75a4a 100644 --- a/website/package.json +++ b/website/package.json @@ -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", @@ -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": [ @@ -34,5 +33,9 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "volta": { + "node": "16.20.2", + "yarn": "1.22.22" } } diff --git a/website/sitemap.mjs b/website/sitemap.mjs new file mode 100644 index 00000000..028e8ccb --- /dev/null +++ b/website/sitemap.mjs @@ -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",` + + +${assets.map((asset) => ` `).join("\n")} + + +

JavaScript Index

+ + + + +`); + +const images = readdirSync("./build/interactors/images"); + +writeFileSync("./build/interactors/images/index.html",` + + +${images.map((image) => ` `).join("\n")} + + +

JavaScript Index

+ + + + +`); diff --git a/website/yarn.lock b/website/yarn.lock index 12b41aaa..878daf36 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -2578,7 +2578,7 @@ "@docusaurus/theme-classic" "2.0.0-beta.9" "@docusaurus/theme-search-algolia" "2.0.0-beta.9" -"@docusaurus/react-loadable@5.5.2", "react-loadable@npm:@docusaurus/react-loadable@5.5.2": +"@docusaurus/react-loadable@5.5.2": 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== @@ -7825,6 +7825,14 @@ react-loadable-ssr-addon-v5-slorber@^1.0.1: dependencies: "@babel/runtime" "^7.10.3" +"react-loadable@npm:@docusaurus/react-loadable@5.5.2": + 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" @@ -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" @@ -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"