wiki icon indicating copy to clipboard operation
wiki copied to clipboard

feat: XML Sitemap

Open patrickjvieira opened this issue 3 years ago • 5 comments

XML is available in /sitemap.xml if enabled in SEO settings. https://feedback.js.wiki/wiki/p/automatically-generate-a-sitemap-for-the-wiki

patrickjvieira avatar May 23 '22 02:05 patrickjvieira

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
  }
}

NGPixel avatar May 24 '22 01:05 NGPixel

How long does the cache persist? Isn't better to generate the Sitemap after saving some page?

patrickjvieira avatar May 24 '22 02:05 patrickjvieira

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.

NGPixel avatar May 24 '22 02:05 NGPixel

Nice!

myml avatar Jun 09 '22 07:06 myml

I'm happy to work on this, I can implement what @NGPixel has suggested

mrbrianevans avatar Oct 12 '22 11:10 mrbrianevans