Skip to content

Commit 6ec2ce8

Browse files
committed
fix(docs): stop the sitemap lying about lastmod
Git mtime stamped five 2024 blog posts as modified 2026-06-03 because one bulk touch-up commit rewrote them all, and /blog/ never moved even though its listing is rebuilt from posts.data.ts on every new post. Google stops using lastmod for recrawl scheduling once it catches the value being inaccurate, which wastes it on the docs pages where it is true. Blog posts now carry their publish date and /blog/ tracks the newest post. robots.txt says Allow: / instead of an empty Disallow:. tools/check_sitemap.sh guards the invariants in CI: one entry per built page, nothing extra, right host, every entry dated, no future date, and robots.txt advertising the sitemap.
1 parent 1026187 commit 6ec2ce8

5 files changed

Lines changed: 93 additions & 2 deletions

File tree

‎.github/workflows/check-docs.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ jobs:
3535
- name: Build with VitePress
3636
working-directory: docs
3737
run: npm run build
38+
39+
- name: Check sitemap
40+
run: ./tools/check_sitemap.sh

‎.github/workflows/deploy-gh-pages.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ jobs:
5151
working-directory: docs
5252
run: npm run build
5353

54+
- name: Check sitemap
55+
run: ./tools/check_sitemap.sh
56+
5457
- name: Copy installer into site root
5558
run: cp install.sh docs/.vitepress/dist/install.sh
5659

‎docs/.vitepress/config.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,25 @@ export default defineConfig({
7878
},
7979

8080
sitemap: {
81-
hostname: 'https://bashunit.com'
81+
hostname: 'https://bashunit.com',
82+
// lastmod drives Google's recrawl scheduling, but only while it stays
83+
// verifiably accurate. Git mtime lies twice here: a repo-wide touch-up
84+
// re-stamps years-old announcements as fresh (five 2024 posts all claimed
85+
// 2026-06-03), and /blog/ never moves even though its listing is rebuilt
86+
// from posts.data.ts on every new post.
87+
transformItems(items) {
88+
const publishedAt = (url: string) => url.match(/^blog\/(\d{4}-\d{2}-\d{2})-/)?.[1]
89+
const newestPost = items
90+
.map((item) => publishedAt(item.url))
91+
.filter((date): date is string => !!date)
92+
.sort()
93+
.pop()
94+
95+
return items.map((item) => {
96+
const date = item.url === 'blog/' ? newestPost : publishedAt(item.url)
97+
return date ? { ...item, lastmod: new Date(`${date}T00:00:00Z`) } : item
98+
})
99+
}
82100
},
83101

84102
// Generate /llms-full.txt: the full documentation concatenated for LLMs and agents.

‎docs/public/robots.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
User-agent: *
2-
Disallow:
2+
Allow: /
3+
34
Sitemap: https://bashunit.com/sitemap.xml

‎tools/check_sitemap.sh‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
3+
# Verify the built VitePress sitemap still describes the site exactly: one entry
4+
# per published page, nothing extra, every entry dated, no date in the future.
5+
# Google only keeps using <lastmod> for recrawl scheduling while it stays
6+
# verifiably accurate, and a single leaked non-page (public/*.md has slipped in
7+
# before) is enough to poison that.
8+
#
9+
# Usage: check_sitemap.sh [dist-dir]
10+
11+
set -eu
12+
13+
dist="${1:-docs/.vitepress/dist}"
14+
sitemap="$dist/sitemap.xml"
15+
robots="$dist/robots.txt"
16+
site="https://bashunit.com"
17+
errors=0
18+
19+
fail() {
20+
printf 'sitemap: %s\n' "$1" >&2
21+
errors=$((errors + 1))
22+
}
23+
24+
if [ ! -s "$sitemap" ]; then
25+
fail "$sitemap is missing or empty"
26+
exit 1
27+
fi
28+
29+
# 404 is the only built page that must stay out of the sitemap.
30+
built=$(cd "$dist" && find . -name '*.html' \
31+
| sed 's|^\./||; s|\.html$||; s|^index$||; s|/index$|/|' \
32+
| grep -v '^404$' | sort)
33+
34+
locs=$(grep -o '<loc>[^<]*</loc>' "$sitemap" | sed 's|<loc>||; s|</loc>||')
35+
listed=$(printf '%s\n' "$locs" | sed "s|^$site/||" | sort)
36+
37+
missing=$(comm -23 <(printf '%s\n' "$built") <(printf '%s\n' "$listed"))
38+
[ -z "$missing" ] || fail "pages built but not listed: $(echo "$missing" | tr '\n' ' ')"
39+
40+
orphan=$(comm -13 <(printf '%s\n' "$built") <(printf '%s\n' "$listed"))
41+
[ -z "$orphan" ] || fail "listed but not built: $(echo "$orphan" | tr '\n' ' ')"
42+
43+
foreign=$(printf '%s\n' "$locs" | grep -v "^$site/" || true)
44+
[ -z "$foreign" ] || fail "loc outside $site: $(echo "$foreign" | tr '\n' ' ')"
45+
46+
# VitePress emits the whole sitemap on one line, so counting needs -o, not -c.
47+
urls=$(grep -o '<url>' "$sitemap" | wc -l | tr -d ' ')
48+
dated=$(grep -o '<lastmod>' "$sitemap" | wc -l | tr -d ' ')
49+
[ "$urls" = "$dated" ] || fail "$urls urls but $dated lastmod entries"
50+
51+
future=$(grep -o '<lastmod>[^<]*</lastmod>' "$sitemap" \
52+
| sed 's|<lastmod>||; s|</lastmod>||' | cut -c1-10 | sort -u \
53+
| awk -v today="$(date -u +%Y-%m-%d)" '$0 > today' || true)
54+
[ -z "$future" ] || fail "lastmod in the future: $(echo "$future" | tr '\n' ' ')"
55+
56+
if [ ! -f "$robots" ]; then
57+
fail "robots.txt is missing from $dist"
58+
elif ! grep -q "^Sitemap: $site/sitemap.xml\$" "$robots"; then
59+
fail "robots.txt does not advertise $site/sitemap.xml"
60+
fi
61+
62+
if [ "$errors" -gt 0 ]; then
63+
exit 1
64+
fi
65+
66+
printf 'sitemap: OK (%s urls, all dated, robots.txt advertises it)\n' "$urls"

0 commit comments

Comments
 (0)