Posted: 22/05/2021
Setting Up A Sitemap
Google works best for your website if you give it a sitemap.
This is a full list of all the Uri's of all the pages on your site.
There are several ways to do this, and Google Help will show you how.
So I need one for this site.
However this site is "static" in a sense, as it only becomes dynamic after its viewed in a browser.
Therefore I need to generate a static sitemap for google to index.
That way Google will just read my sitemap file instead of trying to download the site, then render it to find the links.
So the easiest thing to do is generate a static sitemap file every time the site is pushed to Azure.
This is easily done through a script reading all the MarkDown files of the posts, and injecting the 5 or 6 static pages (like "about me") too.
That way whenever I commit a new post, the sitemap will get updated automatically and google will find me new page easily.
So how to generate this static sitemap?
Generation
All my posts are MarkDown files, those file names dictate the layout of the Uri for the page e.g. "SettingUpASitemap.md" becomes "blog.markoliver.website/Setting-Up-A-Sitemap"
Therefore I can run a script reading these files and write out the text file.
But when should it be generated?
Because the script is so small:
# This will generate the sitemap for my website baseUrl="https://blog.markoliver.website/" echo "$baseUrl""About-Me">>SiteMap.txt while IFS='|' read date title categories; do if [[ $date != "<"* ]] then echo "$baseUrl${title// /$'-'}">>SiteMap.txt fi done < Index.md
I was thinking I can do this in my GitHub Action. I think I need to add this:
- name: Generate Sitemap run: | # make file runnable, might not be necessary chmod +x "${GITHUB_WORKSPACE}GenerateSiteMap.sh" # run script "./GenerateSiteMap.sh" cat SiteMap.txt
Then it should get auto deployed on push to Azure.
I will then be able to see it here
It works!
Final touch
The last thing to do is tell Google about it in the Google Search Console Sitemaps page, and then wait for Google to index it.
Thanks for reading this post.
If you want to reach out, catch me on Twitter!
I am always open to mentoring people, so get in touch.