cheatcode / joystick

A full-stack JavaScript framework for building stable, easy-to-maintain apps and websites.
https://cheatcode.co/joystick
Other
212 stars 11 forks source link

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

Open rglover opened 2 years ago

rglover commented 2 years ago

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 commented 3 months ago

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