Thomas R. Koll
Posted on November 2, 2018
For my new project Budget Fox I added sitemap_generator even though it's just a few pages that I want indexed for now.
One thing I noticed when looking at the output was the lastmod
date being the same for all entries. Can't be hard to fix that by pulling the date from the git repo I though.
Here's the code for this and as you can see, I did monkey-patch SitemapGenerator::Interpreter
.
class SitemapGenerator::Interpreter
def lastmod(view)
date = `git log --date iso -n 1 --format="%ad" app/views/#{view}*`
if date.blank?
raise "Missing file #{view}"
end
return date
end
end
SitemapGenerator::Sitemap.create(default_host: 'https://budget-fox.com', compress: false, include_root: false) do
add root_path, changefreq: 'weekly', lastmod: lastmod('welcome/index')
add team_path, priority: 0.5, lastmod: lastmod('welcome/team')
add features_path, lastmod: lastmod('welcome/features.html')
add pricing_path, lastmod: lastmod('purchase/new.html')
end
💖 💪 🙅 🚩
Thomas R. Koll
Posted on November 2, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.