Start a personal dev blog on your domain for free with Hashnode and grow your readership.
Get Started

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.txt of its contents
  • find all .html files in the main folder (and subfolders)
  • echo the site URL, followed by each filename as a new line in the sitemap.txt file

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 "$file" >> sitemap.txt

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!

Start a personal dev blog on your domain for free and grow your readership.

3.4K+ developers have started their personal blogs on Hashnode in the last one month.

Write in Markdown · Publish articles on custom domain · Gain readership on day zero · Automatic GitHub backup and more

No Comments Yet