wiki
wiki copied to clipboard
feat: XML Sitemap
XML is available in /sitemap.xml if enabled in SEO settings. https://feedback.js.wiki/wiki/p/automatically-generate-a-sitemap-for-the-wiki
You should also save the xml output to disk to avoid querying the DB on every page hit. Something like...
const cachePath = path.resolve(WIKI.ROOTPATH, WIKI.config.dataPath, `cache/sitemap.xml`)
try {
const sitemap = await fs.readFile(cachePath, 'utf8')
res.header('Content-Type', 'application/xml').send(sitemap)
} catch (err) {
if (err.code === 'ENOENT') {
// CODE TO GENERATE SITEMAP HERE
await fs.outputFile(cachePath, sitemap)
return sitemap
} else {
WIKI.logger.error(err)
throw err
}
}
How long does the cache persist? Isn't better to generate the Sitemap after saving some page?
The cache should indeed be cleared when making changes to pages. Add a line to:
https://github.com/requarks/wiki/blob/main/server/models/pages.js#L1112
to remove the sitemap.xml file. This method gets called when a page is modified / moved / deleted. It's not called when creating a new page though, so you would need to delete the sitemap in the createPage() method as well.
Nice!
I'm happy to work on this, I can implement what @NGPixel has suggested