Hashnode sitemap.xml is broken. 
Here is how I fixed it

Hashnode sitemap.xml is broken. Here is how I fixed it

·

2 min read

Hashnode is a great place to host a blog. It even gives you some options to optimize the SEO of your blog. For example, it generates a sitemap.xml file based on your blog.

💡
Sitemaps are XML files that tell search engines which URLs on a website they can crawl.

But this sitemap file is broken!

It's not a problem for most users, but if you want to help Google index your blog better, you could provide a sitemap to Google Search Console.

When I tried to do this, I got an error: Sitemap could not be read

I checked several times that a sitemap is available. I put it into an XML validator to validate it. But it simply looks like the generated sitemap is incompatible with Google Search Console.

So, what is wrong with the sitemap here?

Here is the diff between what was not working and the fixed version. It looks like the sitemap built by Hasnode is incorrect enough to confuse Google Search Console. All these spaces make me think it's generated "manually" by a concatenating string.

My fix

As a dotnet developer, I fixed this problem with code. I built a simple Azure Function that consumes the original sitemap and does a minor cleanup to create a valid sitemap.xml.

Google Search Console would not allow adding any link as a source for a sitemap file, only the link from the blog site.

Luckily, Hashnode provides a way to handle it.

Where you could map any path to any link for redirect.

That would satisfy Google, and it would accept your sitemap.xml

A complete code of a function is pretty simple:

  • get a current sitemap

  • deserialze invalid structure

  • serialize without errors

  • return as a result

If you want to reproduce it yourself, create a new Azure Function Project, add the file, and then deploy it to Azure.

If you have any questions, feel free to ping me at @xakpc