Repository navigation
Write valid URLs, hreflang codes and dates in every sitemap - #2
Merged
Merged
Conversation
A URL built by hand could put a space, an accent or a control character in a file, which made it unreadable. Rails locales such as pt_BR went out as hreflang="pt_BR", which search engines ignore. A lastmod string was written whatever it held, and the index took the greatest string rather than the latest time. x_default was missed when the locales block returned strings, and two languages sharing a URL listed it twice. URLs are now percent-encoded outside RFC 3986's characters, locales are written with a hyphen, lastmods are read as W3C dates and written in UTC, and a page lists each of its URLs once. The check reports URLs over 2,048 characters, hreflang values that are not language codes, lastmods that are not dates, and an index with no file or more than 50,000. Assisted-by: Claude Code
An impossible date such as 2026-13-01 crashed the build, and 2026-02-30 was written out. A date alone counted from UTC midnight, so today's date looked like the future east of UTC. A url block that forgot the locale no longer warned once its URLs were listed once per page. A protocol-relative URL got the host in front, and a % not followed by two hex digits stayed. Dates are validated, a date alone starts at UTC+14, a page whose languages share one URL is reported once per source, as is a lastmod that is not a date, and the lastmod is read once per page. An empty site no longer fails the check. Assisted-by: Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A URL built by hand could put a space, an accent or a control character in a file, and one such URL made the whole file unreadable. Rails locales such as
pt_BRwent out ashreflang="pt_BR", which search engines ignore. Alastmodstring was written whatever it held, an impossible date crashed the build, and the index took the greatest string rather than the latest time.x_defaultwas missed when thelocalesblock returned strings.URLs are now percent-encoded outside RFC 3986's characters, locales are written as hreflang codes, and lastmods are validated as W3C dates and written in UTC. The check reports what search engines would reject or ignore.
%are encoded byte by byte; a protocol-relative URL (//cdn…) takes the scheme of the host, not the host.pt_BRis writtenpt-BR,x_defaultis found whatever the type of the locales, and two languages sharing a URL list it once.Proof
55 runs, 149 assertions, green on Rails 8.1 and 8.0; RuboCop clean. New tests cover each case above, including a URL holding
Café\u0001 d\xE9j\xE0and100%, the localespt_BRanden_GB, the dates2026-13-01,2026-02-30and2026-01-15T10:00+09:00, and a date on the first day on Earth.bench/build.rb(30,000 records × 24 languages, Ruby 3.3.6 without YJIT): full build 30.2 s and 31.7 s on this branch, 26.9 s, 30.9 s and 33.8 s onmain. The spread onmainalone is wider than the difference.Generated by Claude Code