Set DEPLOY_PRIME_URL to primary domain? Problems with sitemap

answered
#1

In an attempt to fix Hugo’s sitemap, I used $DEPLOY_PRIME_URL in my build script. However, instead of using my primary domain, it uses the Netlify subdomain. It is unclear whether it is intended behavior to only link to the Netfliy subdomain as the docs are slightly ambiguous:

DEPLOY_PRIME_URL : This URL represents the primary URL for an individual deploy, or a group of them, like branch deploys and Deploy Previews; for example, https://beta--open-api.netlify.com or https://deploy-preview-34--open-api.netlify.com

As can be seen, I have set my primary domain in the settings:

I am using the Victor Hugo [1] Netlify template with a slightly modified build script [2] according to attempts made by others [3]. Relevant lines:

gulp.task("hugo", (cb) => {
  let baseUrl = process.env.NODE_ENV === 'production' ? process.env.URL : process.env.DEPLOY_PRIME_URL;
  let args = baseUrl ? ['-b', baseUrl] : [];    

  buildSite(cb, args);
});
gulp.task("hugo-preview", (cb) => {
  let args = ['--buildDrafts', '--buildFuture'];
  if (process.env.DEPLOY_PRIME_URL) {
    args.push('-b')
    args.push(process.env.DEPLOY_PRIME_URL)
    }   

  buildSite(cb, args)
});

The reason why baseUrl can’t simply be “/” is that a sitemap requires the full url with protocol [4] and simply replacing it with one’s domain is not possible for local dev builds and Netlify’s preview builds

My site:

[1] github[.]com/netlify-templates/victor-hugo
[2] github[.]com/jonas-sk/pine-maastricht/blob/master/gulpfile.babel.js
[3] github[.]com/indigotree/atlas/pull/39/files
[4] github[.]com/indigotree/atlas/issues/38 and github[.]com/netlify-templates/victor-hugo/issues/142

(sorry for the weird links, can’t put in more than 2)

#2

I have had good results using process.env.CONTEXT when checking for ‘production’

#3

Thanks for the suggestion @shawn . I’d do the same and check the $CONTEXT for production, and if it comes back production, pull the URL from $URL instead of $DEPLOY_PRIME_URL . Let us know if that doesn’t work for you.