feat: Add all articles to sitemap

This commit is contained in:
Jesse Wierzbinski 2024-10-19 23:02:46 +02:00
parent a03124416b
commit cfd953870f
No known key found for this signature in database
2 changed files with 38 additions and 1 deletions

View file

@ -76,6 +76,6 @@
"globals": ["Bun", "HTMLRewriter", "BufferEncoding"]
},
"files": {
"ignore": ["node_modules", "dist", ".nuxt"]
"ignore": ["node_modules", "dist", ".nuxt", ".output"]
}
}

View file

@ -1,5 +1,35 @@
import { readdirSync } from "node:fs";
import { join } from "node:path";
import { defineNuxtConfig } from "nuxt/config";
/*
* Reads the content directory and returns an array of all the files in the directory and subdirectories.
*/
const getRouteRenderingPaths = () => {
const contentDir = join(process.cwd(), "content");
const paths: string[] = [];
const readDir = (dir: string) => {
const files = readdirSync(dir);
for (const file of files) {
const filePath = join(dir, file);
if (file.endsWith(".md")) {
paths.push(
filePath
.replace(contentDir, "/articles")
.replace(".md", ""),
);
} else {
readDir(filePath);
}
}
};
readDir(contentDir);
return paths;
};
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: [
@ -66,6 +96,13 @@ export default defineNuxtConfig({
image: {
domains: ["images.pexels.com"],
},
sitemap: {
sources: [...getRouteRenderingPaths(), "/"],
},
// For sitemap generation
site: {
url: "https://versia.blog",
},
nitro: {
preset: "bun",
minify: true,