fedeya / remix-sitemap

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

Bug: `image:loc` and `video:*_loc` tags aren't starting with the `config.siteUrl` like top level `loc` #63

Closed AjaniBilby closed 9 months ago

AjaniBilby commented 9 months ago

Describe the bug The pre-processor before xml generation isn't properly adjusting the loc values supplied from the sitemap function to be relative to the config.siteUrl value

To Reproduce

export const sitemap: SitemapFunction = async () => {
    // ...
    return data.map(sign => ({
        loc: `/sign/${sign.id}`,
        lastmod: sign.updatedAt.toISOString(),
        priority: 1.0,
        images: [{
            loc: `/sign/${sign.id}/image-crop?thumbnail`
        }],
        videos: sign.media.length > 0
            ? sign.media.map(media => ({
                title: `Sign for ${strCapitalize(sign.title)}`,
                thumbnailLoc: `/blob/${media.blobID}/thumbnail`,
                contentLoc: `/blob/${media.blobID}/raw`,
                playerLoc: `/sign/${sign.id}`,
                publicationDate: media.blob.updatedAt.toISOString().split('T')[0],
                familyFriendly: true
            })) as any
            : undefined
    }));
};

Actual (incorrect) Output

<url>
    <loc>https://signplanet.net/sign/1</loc>
    <lastmod>2023-05-05T01:06:04.000Z</lastmod>
    <changefreq>daily</changefreq>
    <priority>1</priority>
    <image:image>
        <image:loc>/sign/1/image-crop?thumbnail</image:loc>
    </image:image>
    <video:video>
        <video:thumbnail_loc>/blob/KpLmafucrC3/thumbnail</video:thumbnail_loc>
        <video:title>Sign for Animal</video:title>
        <video:content_loc>/blob/KpLmafucrC3/raw</video:content_loc>
        <video:player_loc>/sign/1</video:player_loc>
        <video:publication_date>2023-11-22</video:publication_date>
        <video:family_friendly>yes</video:family_friendly>
    </video:video>
</url>

Expected Output

<url>
    <loc>https://signplanet.net/sign/1</loc>
    <lastmod>2023-05-05T01:06:04.000Z</lastmod>
    <changefreq>daily</changefreq>
    <priority>1</priority>
    <image:image>
        <image:loc>https://signplanet.net//sign/1/image-crop?thumbnail</image:loc>
    </image:image>
    <video:video>
        <video:thumbnail_loc>https://signplanet.net//blob/KpLmafucrC3/thumbnail</video:thumbnail_loc>
        <video:title>Sign for Animal</video:title>
        <video:content_loc>https://signplanet.net//blob/KpLmafucrC3/raw</video:content_loc>
        <video:player_loc>https://signplanet.net//sign/1</video:player_loc>
        <video:publication_date>2023-11-22</video:publication_date>
        <video:family_friendly>yes</video:family_friendly>
    </video:video>
</url>

Environment:

fedeya commented 9 months ago

Hi, this is intentional because it is too normal to have assets on another domain, if you want to use the config.siteUrl you can get it from the first argument, for example:

export const sitemap: SitemapFunction = ({ config }) => {
  config.siteUrl

  return ...
}