Search code examples
gatsbynetlifyghost-blog

Gatsby sitemap.xml and rss feed using wrong domain name


I'm using Ghost with gatsby-starter-ghost and running into an issue with the generated sitemap.xml from gatsby-plugin-advanced-sitemap as well as the RSS feed URL.

My domain name is https://www.officehomelife.com/ and is hosted on https://officehomelife.netlify.app/

The problem is https://www.officehomelife.com/sitemap.xml is generating URLs based off of the netlify domain name and not my domain name. It is also using the netlify domain name for the RSS feed https://feedly.com/i/subscription/feed/https://officehomelife.netlify.app/rss/

I believe this value should be coming from gatsby-starter-ghost\src\utils\siteConfig.js where I have it defined:

    siteUrl: `https://www.officehomelife.com`, // Site domain. Do not include a trailing slash!

    postsPerPage: 12, // Number of posts shown on paginated pages (changes this requires sometimes to delete the cache)

    siteTitleMeta: `Office Home Life`, // This allows an alternative site title for meta data for pages.
    siteDescriptionMeta: `The essential guide to working from home`, // This allows an alternative site description for meta data for pages.

    shareImageWidth: 1000, // Change to the width of your default share image
    shareImageHeight: 523, // Change to the height of your default share image

    shortTitle: `Office`, // Used for App manifest e.g. Mobile Home Screen
    siteIcon: `favicon.png`, // Logo in /static dir used for SEO, RSS, and App manifest
    backgroundColor: `#e9e9e9`, // Used for Offline Manifest
    themeColor: `#15171A`, // Used for Offline Manifest
}

I tried deleting a .cache folder but that did not help, any other ideas?

Thanks


Solution

  • Dealing with environment variables it's a little bit tricky, you have to prefix the variables with GATSBY_ to make them available to the server (Netlify) in the browser-side:

    In addition to these Project Environment Variables defined in .env.* files, you could also define OS Env Vars. OS Env Vars which are prefixed with GATSBY_ will become available in browser JavaScript.

    So, your process.env.SITEURL should become:

    siteMetadata: { siteUrl: process.env.GATSBY_SITEURL || config.siteUrl, }
    

    And so on for the rest of the environment variables.