forked from owolfdev/mdx-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext-sitemap.config.js
99 lines (92 loc) · 2.17 KB
/
next-sitemap.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// next-sitemap.config.js
const fs = require("node:fs").promises;
const path = require("node:path");
/** @type {import('next-sitemap').IConfig} */
const config = {
siteUrl: process.env.SITE_URL || "https://www.mdxblog.io/",
generateRobotsTxt: true,
generateIndexSitemap: true,
exclude: [
"/api/*",
"/auth/*",
"/(auth-pages)/*",
"/admin/*",
"/actions/*",
"/post/create/*",
"/post/edit/*",
"/page/create/*",
"/page/edit/*",
"/*.png",
"/*.jpg",
"/*.ico",
"/favicon.ico",
"/apple-icon.png",
"/not-found",
"/loading",
"/error",
],
robotsTxtOptions: {
policies: [
{
userAgent: "*",
allow: "/",
disallow: [
"/api/*",
"/auth/*",
"/admin/*",
"/post/create/*",
"/post/edit/*",
"/page/create/*",
"/page/edit/*",
],
},
],
},
outDir: "public",
additionalPaths: async (config) => {
const result = [];
// Add static routes
const staticRoutes = [
"/",
"/about",
"/blog",
"/contact",
"/contact/thank-you",
"/install",
"/privacy",
];
for (const route of staticRoutes) {
result.push({
loc: route,
changefreq: "daily",
priority: route === "/" ? 1.0 : 0.7,
lastmod: new Date().toISOString(),
});
}
// Read blog posts from the content directory
try {
// Adjust this path to match your blog posts location
const contentDir = path.join(process.cwd(), "content", "posts");
const files = await fs.readdir(contentDir);
// Add each blog post to the sitemap
for (const file of files) {
if (file.endsWith(".mdx") || file.endsWith(".md")) {
const slug = file.replace(/\.mdx?$/, "");
result.push({
loc: `/blog/${slug}`,
changefreq: "daily",
priority: 0.7,
lastmod: new Date().toISOString(),
});
}
}
} catch (error) {
console.warn(
"Warning: Could not read blog posts directory:",
error.message
);
}
return result;
},
};
module.exports = config;