fedeya / remix-sitemap

Sitemap generator for Remix applications
https://npmjs.com/remix-sitemap
MIT License
95 stars 5 forks source link

New API for generate entries #23

Closed fedeya closed 1 year ago

fedeya commented 1 year ago

Maybe can be improved the developer experience changing the api from sitemap property in handle to a sitemap function like meta or links

Reference: https://github.com/remix-run/remix/discussions/2912#discussioncomment-3048673

Example

// routes/posts.$slug.ts

export const sitemap: SitemapFunction = async ({ config, request }) => {
  const posts = await getPosts();

  return posts.map(post => ({
    loc: `/posts/${post.slug}`
  }));
}

This is very possible, for build time generation i get the all exported modules when i build each route with esbuild. And for runtime generation i can get it from the same route modules where i get the handle

Also for settings like exclude or addOptionalPaths it can be more conditional.

Example if you want to hide only one route in a collection

// routes/($lang)/posts.$slug.ts

export const sitemap: SitemapFunction = async ({ config, request }) => {
  const posts = await getPosts();

  return posts.map(post => ({
    loc: `/posts/${post.slug}`,
    exclude: post.seo?.noIndex,
    addOptionalSegments: post.isTranslated
  }));
}
fedeya commented 1 year ago

Also to change properties quickly is cleaner

Now

export const handle: SitemapHandle = {
  sitemap: {
    generateEntries: () => [{
      loc: '/about',
      priority: 0.2,
      changefreq: 'weekly',
    }]
  }
}

New API

export const sitemap: SitemapFunction = () => ({
  priority: 0.2,
  changefreq: 'weekly'
});
fedeya commented 1 year ago

this new api is in v2 branch, the discussion keeps open for feedback

https://github.com/fedeya/remix-sitemap/tree/v2