fedeya / remix-sitemap

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

Unable to set `news:publication_date` #52

Closed AjaniBilby closed 1 year ago

AjaniBilby commented 1 year ago

I'm using the following code to generate my sitemap data for a particular dynamic route:

export async function sitemap () {
    const data = await prisma.news.findMany({
        where: {
            isDraft: false
        },
        orderBy: [
            { createdAt: "desc" }
        ]
    });

    return data.map(entry => ({
        lastmod: entry.updatedAt.toISOString().split('T')[0],
        loc: `/news/${entry.id}`,
        news: [{
            title: entry.title,
            publication: {
                name: 'Signplanet',
                language: 'en'
            },
            publication_date: entry.publishAt.toISOString().split('T')[0]
        }]
    }))
};

Which then generates xml elements like:

<url>
    <loc>https://beta.signplanet.net/news/cllygso7r0001fju4xejanrra</loc>
    <lastmod>2023-09-01</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.7</priority>
    <news:news>
        <news:publication>
            <news:name>Signplanet</news:name>
            <news:language>en</news:language>
        </news:publication>
        <news:title>Welcome to the new SignPlanet.net site</news:title>
    </news:news>
</url>

The fact that publication_date is missing when it's a required field is quite a problem

fedeya commented 1 year ago

The publication_date is just date field in news object.

ex:

{
  title: entry.title,
  publication: { ... },
  date: entry.publishAt.toISOString()
}
fedeya commented 1 year ago

also using the SitemapFunction type you get autocomplete and type checking.

ex:

import type { SitemapFunction } from 'remix-sitemap';

export const sitemap: SitemapFunction = () => {}
AjaniBilby commented 1 year ago

publication_date -> date, was an unexpected transformation 😅

I'm used to swapping const functions to function functions because of the performance difference when they first started becoming popular... I should probably get out of that old habbit