Skip to content

Commit

Permalink
chore(docs): use vitepress sitemap feature
Browse files Browse the repository at this point in the history
For some reason, using `lastUpdated` results in a `git ENOENT` error. So disabling that feature for now until I've time to investigate.
  • Loading branch information
dirkdev98 committed Jul 31, 2023
1 parent 7b0ecfb commit 28fcb18
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { processDirectoryRecursiveSync } from "@compas/stdlib";
import { resolve } from "node:path";
import { readdirSync, writeFileSync } from "node:fs";
import { readdirSync } from "node:fs";
import { defineConfig } from "vitepress";

export default defineConfig({
Expand Down Expand Up @@ -38,7 +36,7 @@ export default defineConfig({
["link", { rel: "shortcut icon", href: "/favicon/favicon.ico" }],
["meta", { name: "theme-color", content: "#3EAF7C" }],
],
lastUpdated: true,
lastUpdated: false,

themeConfig: {
logo: "/compas-icon.svg",
Expand Down Expand Up @@ -109,31 +107,8 @@ export default defineConfig({
envDir: process.cwd() + "/docs",
},

buildEnd: (config) => {
const outFile = resolve(config.outDir, "sitemap.xml");
const baseUrl = "https://compasjs.com/";

let sitemap = `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`;

processDirectoryRecursiveSync(config.outDir, (f) => {
if (!f.endsWith(".html")) {
return;
}

if (f.includes("404.html")) {
return;
}

const path = f.split("/dist/").pop();
sitemap += `<url>
<loc>${baseUrl}${path}</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>`;
});
sitemap += `</urlset>`;
writeFileSync(outFile, sitemap);
sitemap: {
hostname: "https://compasjs.com",
},
});

Expand Down

0 comments on commit 28fcb18

Please sign in to comment.