mirror of
https://github.com/versia-pub/blog.git
synced 2025-12-06 00:48:18 +01:00
feat: ✨ Add all articles to sitemap
This commit is contained in:
parent
a03124416b
commit
cfd953870f
|
|
@ -76,6 +76,6 @@
|
|||
"globals": ["Bun", "HTMLRewriter", "BufferEncoding"]
|
||||
},
|
||||
"files": {
|
||||
"ignore": ["node_modules", "dist", ".nuxt"]
|
||||
"ignore": ["node_modules", "dist", ".nuxt", ".output"]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue