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

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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695159838454/4eed6acc-b30c-4a50-bdcd-0e713a6f3c58.png align="center")

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Sitemaps are XML files that tell search engines which URLs on a website they can crawl.</div>
</div>

# **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`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695161601802/5ed6a707-5558-4167-a15d-1ef7e3d302f7.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695161628638/7d0be6cb-1c42-4816-a53d-42af2946a7b6.png align="center")

I checked several times that a sitemap [is available](https://xakpc.info/sitemap.xml). 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?

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695162198995/0bd4859d-fe95-4ea6-83f4-8292655fe9ad.png align="center")

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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695162569844/67304abf-5e1b-437f-9c50-cdfe760edf5f.png align="center")

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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695162638330/6afa1fae-2412-4e28-a4d7-90b14f93b1cc.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695162745825/cd25f744-5fee-448a-a6db-bc9fa44ad557.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695162878011/ef09ab78-9c2e-4d86-b579-639b96341dca.png align="center")

A complete code of a function is pretty simple:

* get a current sitemap
    
* deserialze invalid structure
    
* serialize without errors
    
* return as a result
    

%[https://gist.github.com/xakpc/c4ab9c023ad031ed9a992c8ca8199212] 

If you want to reproduce it yourself, [create a new Azure Function](https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-your-first-function-visual-studio) Project, add the file, and then deploy it to Azure.

If you have any questions, feel free to ping me at [@xakpc](https://x.com/xakpc)
