Jekyll Sitemap generated with localhost domain, not the base URL

Problem

The Jekyll Sitemap plugin helps to generate sitemap.xml and robots.txt, which improves your SEO to search engines. Then you can submit them to Google Search Console for indexing.

However Google Search Console prompted the error URL not allowed - This URL is not allowed for a Sitemap at this location. when I submitted the sitemap from Jekyll Sitemap plugin.

Google Search Console error

Upon checking, the domain in sitemap.xml was actually in localhost domain.

<url>
<loc>http://localhost:4000/2017/05/28/builder-pattern-vs-constructor-vs-setter/</loc>
<lastmod>2017-05-28T00:00:00+08:00</lastmod>
</url>
<url>
<loc>http://localhost:4000/about/</loc>
</url>
<url>
<loc>http://localhost:4000/tags/</loc>
</url>
<url>
<loc>http://localhost:4000/</loc>
</url>
<url>
<loc>http://localhost:4000/style-guide/</loc>
</url>

Solution

Run the jekyll build instead of using jekyll serve

and … tada! The domain is back

<url>
<loc>https://hermannyung.com/about/</loc>
</url>
<url>
<loc>https://hermannyung.com/tags/</loc>
</url>
<url>
<loc>https://hermannyung.com/</loc>
</url>
<url>
<loc>https://hermannyung.com/style-guide/</loc>
</url>

I usually run jekyll serve for my dev and push directly to S3. However according to the documentation , serve is only for local dev, i.e. using localhost; build is actually the job that replaces your env with the one you configured in _config.yml.

Hermann Yung's Picture

About Hermann Yung

Hermann is a software developer.

Hong Kong https://hermannyung.com

Comments