Repository navigation
fix(rules): scope sitemap-lastmod-drift to the document's own JSON-LD node - #161
Merged
Merged
Conversation
… node schemaDateModified took the FIRST flattened node carrying any dateModified, with no @type filter, so a page whose Article.dateModified agreed with its sitemap lastmod exactly still warned when a sitewide WebSite node carried a stale date - and passed once the same two nodes were reversed. Yoast and Rank Math emit the sitewide node first in @graph, so that ordering is the common one, and the verdict should never have depended on it. Only nodes whose @type describes the DOCUMENT now feed the comparison, the guard content/date-agreement already shipped with. The two rules share one copy of it: the type vocabulary, the @type reader and the {"@value"} date unwrapper move to shared/schema-document.ts, and date-agreement drops its local copies. The vocabulary now also recognises a @type written as a full IRI (https://schema.org/Article) or against the schema: prefix, which neither rule read before; documentTypes returns the node's document types in the order written, so date-agreement keeps its own first-one-wins policy unchanged. Drift is stricter than that: an Article-family node wins wherever it sits, and a node claiming both (["WebPage","BlogPosting"]) counts as the article either way round, so no part of the verdict turns on node order. Unparseable values are skipped while scanning rather than returned, so one node's malformed date cannot hide a later node's good one. With no document node carrying a usable dateModified the answer is nothing, and the rule falls through to the page's own meta/visible dates rather than borrowing a sitewide one; a page with no signal at all stays skipped, as before. Every new fixture is asserted in both node orders, in @graph and flat-array shapes. The dual-path parity test is replaced: it ran the same rule twice on the same object and could not fail. It now feeds a DOM that contradicts the parsed scalars, so a DOM fallback would diverge the two paths. Refs #1570 Signed-off-by: Nik Cubrilovic <[email protected]>
deltaDays rounded, so the effective thresholds sat half a day past the documented ones: with the default behind_days of 7, a 7.5-day gap warned and was quoted back to the user as "8 day(s)" under a message reading "older ... by more than 7 day(s)". Both the verdict and the number overstated the gap. Truncating instead makes the rule agree with its own copy, and makes the comment above it true: with behind_days at 0 a 20-hour same-day difference no longer warns with deltaDays 1. Refs #1570 Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
fix/lastmod-drift-type-filter
branch
from
August 31, 2026 21:22
0c29a0c to
adaae05
Compare
This was referenced Aug 31, 2026
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.
crawl/sitemap-lastmod-driftcompares a sitemap'slastmodagainst the page's owndateModified. ItsschemaDateModified()took the first flattened JSON-LD node carrying anydateModified, with no@typefilter.So a page whose
Article.dateModifiedagreed with its sitemap exactly still warned, as long as a sitewide node carried a stale date and happened to be written first:Yoast and Rank Math emit the sitewide node ahead of the
Articlein@graph, so that is the common ordering, not the exotic one. The verdict should never have turned on it.What changed
Only document-describing nodes feed the comparison — the guard the sibling rule
content/date-agreementalready shipped with. Rather than a second copy, the type vocabulary, the@typereader and the{"@value"}date unwrapper move topackages/rules/src/shared/schema-document.tsand both rules use it.documentTypes(node)returns the node's document types in the order written, leaving the selection policy to each rule:content/date-agreementtakes[0]— its previous first-one-wins behaviour, unchanged.crawl/sitemap-lastmod-driftprefers an Article-family node wherever it sits, and treats a node claiming both (["WebPage","BlogPosting"]) as the article either way round. No part of its verdict depends on node order now.Unparseable values are skipped while scanning rather than returned, so a malformed date cannot hide a good one later in the graph or later in the same node's date list. With no document node carrying a usable
dateModifiedthe answer is nothing, and the rule falls through to the page's own meta/visible dates rather than borrowing a sitewide one. A page with no signal at all stays skipped, as before.Second commit, separable:
deltaDaysusedMath.round, putting the effective thresholds half a day past the documented ones. A 7.5-day gap warned and was quoted back as8 day(s)under a message reading "older ... by more than 7 day(s)" — both the verdict and the number overstated.Math.floormakes the rule agree with its own copy, and makes the comment above it true (withbehind_days: 0, a 20-hour same-day difference no longer warns withdeltaDays: 1).Behaviour changes a user could notice
@typewritten as a full IRI (https://schema.org/Article) or against theschema:prefix, and a whitespace-padded one. Neither rule read those before;content/date-agreementis affected by this widening too (such a node is now the document node rather than a reported fallback).{"@value": ...}wrapper and a list of dates, which it previously ignored in favour of weaker signals.All four are documented on the rule's docs page.
Tests
packages/rules/tests/sitemap-lastmod-drift.test.ts, 31 tests (was 20). The traps are asserted in both node orders, and in@graphand flat-array shapes, so none can pass on ordering luck. 8 of the new tests fail against the pre-fix rule, verified by checking outorigin/main's copy of the rule under the new test file.The old "dual-path parity" test called the same rule twice on the same object and could not fail. It is replaced with one that feeds a DOM contradicting the parsed scalars: verified falsifiable by mutating the rule to consult
parsed.document, which the old test did not catch.Green: 1,395 rules tests, 1,791 CLI tests,
tsgo --noEmitacross all packages,bun run format:check,make validateindocs/.Reviewed with Codex over two rounds; every finding is addressed in the branch rather than deferred.
Refs squirrelscan/repo#1570