TIL you can use TXT files for sitemaps
Until today I had only ever used XML files for creating sitemaps for search engines like Google, but today I saw that Google can read sitemaps as TXT files, as long as there is one URL per line.
Since many of my websites are folders of HTML files, it's very simple to generate a plain text sitemap using the command line. All I needed to do was:
- empty a file named
sitemap.txtof its contents
- find all
.htmlfiles in the main folder (and subfolders)
- echo the site URL, followed by each filename as a new line in the
To do these steps I wrote a shell script that looked something like this:
true > sitemap.txt echo "Building sitemap…" for file in *.html */*.html echo " adding $file" echo "https://example.com/$file" >> sitemap.txt end echo "Sitemap built"
I'm using fish shell for my shell, but it would be similar and equally straightforward to write a script like this for bash, zsh, or any other shell you use.
Because of how simple this made my job tonight, I was able to add sitemaps to three of my websites. I hope knowing this tip makes somebody else's day easier too!