joystick icon indicating copy to clipboard operation
joystick copied to clipboard

Add a helper function for generating a sitemap to @joystick.js/node

Open rglover opened this issue 3 years ago • 1 comments

This is just big enough of a pain in the butt that Joystick should pick up the weight. Just do something like...

import joystick, { sitemap } from '@joystick.js/node';

joystick.app({
  routes: {
    '/sitemap.xml': async (req = {}, res = {}) => {
       sitemap(res, {
         static: [
           { path: '/' },
           { path: '/about' },
           { path: '/terms' }
         ],
         dynamic: [
           ...(
             (await process.databases.mongodb.collection('posts').find().toArray())?.map((post) => ({ path: `/posts/${post.slug}`, lastModified: post?.updatedAt }))
           )
         ],
      });
    },
  }
});

Idea above is that objects are taken in and mapped over to the appropriate XML format and the res object has the appropriate Content-Type set.

rglover avatar Nov 15 '22 17:11 rglover

Maybe do this as res.sitemap() so it's even easier?

rglover avatar Jul 23 '24 21:07 rglover