diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index d1b1658..d038bbb 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -1,7 +1,33 @@ +import { createWriteStream } from "node:fs"; +import { resolve } from "node:path"; +import { SitemapStream } from "sitemap"; import { defineConfig } from "vitepress"; +const links = []; + // https://vitepress.dev/reference/site-config export default defineConfig({ + // sitemap.xml + transformHtml: (_, id, { pageData }) => { + if (!/[\\/]404\.html$/.test(id)) + links.push({ + // you might need to change this if not using clean urls mode + url: pageData.relativePath.replace(/((^|\/)index)?\.md$/, "$2.html"), + lastmod: pageData.lastUpdated, + }); + }, + buildEnd: async ({ outDir }) => { + const sitemap = new SitemapStream({ + hostname: "https://nixos-and-flakes.thiscute.world/", + }); + const writeStream = createWriteStream(resolve(outDir, "sitemap.xml")); + sitemap.pipe(writeStream); + links.forEach((link) => sitemap.write(link)); + sitemap.end(); + await new Promise((r) => writeStream.on("finish", r)); + }, + + // markdown options markdown: { theme: "material-theme-palenight", lineNumbers: true, diff --git a/package.json b/package.json index 8db7377..17bd583 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "devDependencies": { + "sitemap": "^7.1.1", "vitepress": "1.0.0-beta.3" }, "scripts": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2a4c7e2..9883a95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,9 @@ dependencies: version: 3.0.3 devDependencies: + sitemap: + specifier: ^7.1.1 + version: 7.1.1 vitepress: specifier: 1.0.0-beta.3 version: 1.0.0-beta.3(@algolia/client-search@4.17.2)(search-insights@2.6.0) @@ -415,6 +418,16 @@ packages: resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} dev: true + /@types/node@17.0.45: + resolution: {integrity: sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==} + dev: true + + /@types/sax@1.2.4: + resolution: {integrity: sha512-pSAff4IAxJjfAXUG6tFkO7dsSbTmf8CtUpfhhZ5VhkRpC4628tJhh3+V6H1E+/Gs9piSzYKT5yzHO5M4GG9jkw==} + dependencies: + '@types/node': 17.0.45 + dev: true + /@types/web-bluetooth@0.0.17: resolution: {integrity: sha512-4p9vcSmxAayx72yn70joFoL44c9MO/0+iVEBIQXe3v2h2SiAsEIo/G5v6ObFWvNKRFjbrVadNf9LqEEZeQPzdA==} dev: true @@ -615,6 +628,10 @@ packages: resolution: {integrity: sha512-lEm8mt52to2fT8GhciPCGeCXACSz2UwIN4X2e2LJSnZ5uAbn2/dsYdOmUXq0AtWS5cpAupysIneExOgH0Vd2TQ==} dev: true + /arg@5.0.2: + resolution: {integrity: sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==} + dev: true + /body-scroll-lock@4.0.0-beta.0: resolution: {integrity: sha512-a7tP5+0Mw3YlUJcGAKUqIBkYYGlYxk2fnCasq/FUph1hadxlTRjF+gAcZksxANnaMnALjxEddmSi/H3OR8ugcQ==} dev: true @@ -725,6 +742,10 @@ packages: fsevents: 2.3.2 dev: true + /sax@1.2.4: + resolution: {integrity: sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==} + dev: true + /search-insights@2.6.0: resolution: {integrity: sha512-vU2/fJ+h/Mkm/DJOe+EaM5cafJv/1rRTZpGJTuFPf/Q5LjzgMDsqPdSaZsAe+GAWHHsfsu+rQSAn6c8IGtBEVw==} engines: {node: '>=8.16.0'} @@ -739,6 +760,17 @@ packages: vscode-textmate: 8.0.0 dev: true + /sitemap@7.1.1: + resolution: {integrity: sha512-mK3aFtjz4VdJN0igpIJrinf3EO8U8mxOPsTBzSsy06UtjZQJ3YY3o3Xa7zSc5nMqcMrRwlChHZ18Kxg0caiPBg==} + engines: {node: '>=12.0.0', npm: '>=5.6.0'} + hasBin: true + dependencies: + '@types/node': 17.0.45 + '@types/sax': 1.2.4 + arg: 5.0.2 + sax: 1.2.4 + dev: true + /source-map-js@1.0.2: resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==} engines: {node: '>=0.10.0'}