Repository navigation
feat(sitemap): add accurate lastmod from each doc's last content change #928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0cf7bf1
feat(sitemap): add accurate lastmod from each doc's last content change
amaan-bhati 6a697a9
fix(sitemap): skip media-only commit #896 and harden ignore-revs parsing
amaan-bhati bab6cc0
chore(merge): sync feat/sitemap-lastmod with latest main
amaan-bhati 1a60a13
fix(sitemap): strip SEO boilerplate, keep markdown structure, ignore …
amaan-bhati f43c23b
ci(sitemap): fail shallow CI builds and verify lastmod spread in PR b…
amaan-bhati 21abd92
ci(sitemap): point verify-lastmod failures at the threshold for real …
amaan-bhati ca10cce
fix(sitemap): strip only Related link lists and hidden HowTo blocks f…
amaan-bhati a45f25e
fix(sitemap): keep HowTo spans that cross into a second block as content
amaan-bhati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Commits that change doc bodies without changing what they say (a mass | ||
| # find-and-replace, a link or formatting rewrite). Doc last-update dates and | ||
| # the sitemap <lastmod> skip them. Front-matter-only and whitespace-only | ||
| # changes are already skipped automatically, so they do not need listing. | ||
| # One full commit hash per line; see src/lastUpdate/contentLastUpdate.js. | ||
|
|
||
| # #896: swapped <img> for webp and gifs for <video>; no text changed. | ||
| fd27e0f56a544fd29a59ec10a0abdee387e1cf46 | ||
|
|
||
| # #897: SEO sweep (Related footers, HowTo blocks, alt text, dashes, prettier). | ||
| 80307a582dec2bd7be9e5b5802cfe71655fb88b6 | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Asserts the built sitemap carries real per-page <lastmod> dates. Catches the | ||
| // failure mode where every page silently ships one date (a shallow clone, git | ||
| // unavailable, the sitemap `lastmod` option dropped), which a green build | ||
| // otherwise hides. See src/lastUpdate/contentLastUpdate.js. | ||
| // | ||
| // Usage: node scripts/verify-lastmod.js <build dir> | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
|
|
||
| // Thresholds. Today: ~216 URLs, ~46 distinct dates, the largest single date | ||
| // (#918, a real sitewide rewrite) covers about a third of pages. | ||
| const MIN_COVERAGE = 0.9; // share of URLs that must carry <lastmod> | ||
| const MIN_DISTINCT_DATES = 10; | ||
| const MAX_SHARE_OF_ONE_DATE = 0.5; | ||
|
|
||
| const buildDir = process.argv[2] || "build"; | ||
| const sitemapPath = path.join(buildDir, "sitemap.xml"); | ||
| const xml = fs.readFileSync(sitemapPath, "utf8"); | ||
|
|
||
| const fail = (msg) => { | ||
| console.error(`verify-lastmod: ${msg} (${sitemapPath})`); | ||
| process.exit(1); | ||
| }; | ||
|
|
||
| const urls = xml.match(/<url>[\s\S]*?<\/url>/g) || []; | ||
| if (!urls.length) fail("no <url> entries"); | ||
|
|
||
| const dates = urls | ||
| .map((url) => url.match(/<lastmod>([^<]+)<\/lastmod>/)) | ||
| .filter(Boolean) | ||
| .map((match) => match[1]); | ||
|
|
||
| const coverage = dates.length / urls.length; | ||
| if (coverage < MIN_COVERAGE) { | ||
| fail(`only ${dates.length} of ${urls.length} URLs have <lastmod>`); | ||
| } | ||
|
|
||
| const counts = {}; | ||
| for (const date of dates) counts[date] = (counts[date] || 0) + 1; | ||
| const distinct = Object.keys(counts).length; | ||
| if (distinct < MIN_DISTINCT_DATES) { | ||
| fail(`only ${distinct} distinct <lastmod> dates; is git history shallow?`); | ||
| } | ||
|
|
||
| const [topDate, topCount] = Object.entries(counts).sort( | ||
| (a, b) => b[1] - a[1] | ||
| )[0]; | ||
| if (topCount / dates.length > MAX_SHARE_OF_ONE_DATE) { | ||
| fail( | ||
| `${topCount} of ${dates.length} URLs share <lastmod> ${topDate}; ` + | ||
| "list a sweep in .lastmod-ignore-revs, or raise " + | ||
| "MAX_SHARE_OF_ONE_DATE if the change is real" | ||
| ); | ||
| } | ||
|
|
||
| console.log( | ||
| `verify-lastmod: ok (${dates.length}/${urls.length} URLs, ` + | ||
| `${distinct} distinct dates, largest ${topDate} x${topCount})` | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.