joystick
joystick copied to clipboard
Add a helper function for generating a sitemap to @joystick.js/node
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.
Maybe do this as res.sitemap() so it's even easier?