This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the dumb-mistakes-and-gotchas category.
Last Updated: 2024-11-23
I got unexpected results (even though the code "compiled") with this code for generating a sitemap.
# Context: the `lastmod` attribute is used to communicate with search engines in
# a sitemap as to whether it's worth their while re-crawling your page.
add_sitemap_page institution_taxon_path(institution_taxon.slug, subject_taxon, lastmod: lastmod)
Specifically, the URL had an unnecessary lastmod
attribute (i.e.
/oxford/law?lastmod=999999
) whereas the sitemap entry was missing this info.
The issue was that the hash key value entry lastmod
went to the wrong function
- to my url generator institution_taxon_path()
instead of add_sitemap_page
.
Here's the fix:
add_sitemap_page(
institution_taxon_path(institution_taxon.slug, subject_taxon),
lastmod: lastmod
)
When nesting functions that both take dict-like structures, don't be shy about using parentheses to ensure arguments end up in the right function.