-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next-sitemap.config.js
37 lines (31 loc) · 1.14 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
const fs = require('fs');
const path = require('path');
const getPostSlugs = () => {
const postsDirectory = path.join(process.cwd(), 'public/content'); // Adjust if necessary
// Check if the directory exists
if (!fs.existsSync(postsDirectory)) {
console.error(`Directory does not exist: ${postsDirectory}`);
return [];
}
const filenames = fs.readdirSync(postsDirectory);
return filenames.map((filename) => {
const filePath = path.join(postsDirectory, filename);
const stats = fs.statSync(filePath); // Get file stats
return {
loc: `/blogposts/${filename.replace('.md', '')}`, // Adjust for your slug structure
lastmod: stats.mtime.toISOString(), // Use the file's last modified time
};
});
};
module.exports = {
siteUrl: 'https://hackerwasii.com',
generateRobotsTxt: true,
exclude: ['/api/*'],
additionalPaths: async (config) => {
const blogPosts = getPostSlugs(); // Include your blog posts here
return [
{ loc: '/', lastmod: new Date().toISOString() }, // Add homepage
...blogPosts,
];
},
};