gatsby-plugin-advanced-sitemap icon indicating copy to clipboard operation
gatsby-plugin-advanced-sitemap copied to clipboard

Undefined URLs in sitemap with Ghost

Open eDubrovsky opened this issue 2 years ago • 6 comments

Issue Summary

When generating a sitemap with Ghost mapping, pages like sitemap-posts.xml, sitemap-tags.xml are rendered with undefined URLs like https://gatsby.ghost.org/undefined

Check your official site URLs demo :)))

https://gatsby.ghost.org/sitemap-posts.xml https://gatsby.ghost.org/sitemap-tags.xml

To Reproduce

  1. Use Gatsby with Ghost Source
  2. Build an app with a sitemap

Technical details:

  • Gatsby Version: v4.11.1

  • Node Version: v14.17.0

  • OS: macOS

  • gatsby-config.js:

resolve: "gatsby-plugin-advanced-sitemap",
            options: {
                query: "
                {
                    allGhostPost {
                        edges {
                            node {
                                id
                                slug
                                updated_at
                                created_at
                                feature_image
                            }
                        }
                    }
                    allGhostPage {
                        edges {
                            node {
                                id
                                slug
                                updated_at
                                created_at
                                feature_image
                            }
                        }
                    }
                    allGhostTag {
                        edges {
                            node {
                                id
                                slug
                                feature_image
                            }
                        }
                    }
                    allGhostAuthor {
                        edges {
                            node {
                                id
                                slug
                                profile_image
                            }
                        }
                    }
                }",
                mapping: {
                    allGhostPost: {
                        sitemap: "posts",
                    },
                    allGhostTag: {
                        sitemap: "tags",
                    },
                    allGhostAuthor: {
                        sitemap: "authors",
                    },
                    allGhostPage: {
                        sitemap: "pages",
                    },
                },
                createLinkInHead: true,
                addUncaughtPages: true,
            }"

eDubrovsky avatar Apr 05 '22 16:04 eDubrovsky

I faced the same issue with posts coming from WordPress source and I made it work using serializer option.

        {
            resolve: 'gatsby-plugin-advanced-sitemap',
            options: {
                query: `
                {
                    allWpPost(filter: { status: { eq: "publish" } }) {
                        edges {
                            node {
                                id
                                slug
                            }
                        }
                    }
                }`,
                mapping: {
                    allWpPost: {
                        sitemap: 'blog-articles',
                        serializer: (edges) => {
                            const siteMapEntries = [];
                            edges.forEach((edge) => {
                                edge.node.slug = '/blog/' + edge.node.slug;
                                siteMapEntries.push(edge);
                            });
                            return siteMapEntries;
                        },
                    },
                },
            },
        },

Note: it is necessary to specifically use edge.node instead of simply edge to make it work.

Credits to andrewdever who gave the hint in https://github.com/TryGhost/gatsby-plugin-advanced-sitemap/issues/150.

kloh-fr avatar May 07 '22 09:05 kloh-fr

#234

kloh-fr avatar Dec 04 '22 21:12 kloh-fr

This seems to be fixed, but is still unreleased. Any plans on cutting a release? Demo URLs are also still broken / exhibiting this behavior...

julrich avatar Apr 14 '23 11:04 julrich

@julrich I do not have permission to release a package. @aileen Can you please help here?

yogeshkotadiya avatar Apr 21 '23 04:04 yogeshkotadiya

I verified that fix #234 did work in my case. It would be great to see this fix released. As a workaround, you can patch it by yourself. 😉

Willis0826 avatar Aug 04 '23 22:08 Willis0826

We are facing same issue tried above solutions but its not working.

nirajtrt avatar Aug 30 '23 18:08 nirajtrt