#!/usr/bin/env bash
# 静态站门禁:关键文件存在 + HTML 引用的本地资源都存在
set -euo pipefail
cd "$(dirname "$0")/.."
for file in index.html robots.txt sitemap.xml llms.txt assets/css/style.css assets/js/main.js; do
[ -f "$file" ] || { echo "缺少 $file"; exit 1; }
done
grep -q 'assets/css/style.css?v=' index.html || { echo "index.html 缺少 CSS 版本参数"; exit 1; }
grep -q 'assets/js/main.js?v=' index.html || { echo "index.html 缺少 JS 版本参数"; exit 1; }
python3 - <<'PY'
import os
import re
import sys
html = open("index.html", encoding="utf-8").read()
refs = set(re.findall(r'(?:src|href)="(assets/[^"]+)"', html))
missing = sorted(ref for ref in refs if not os.path.exists(ref.split("?")[0]))
if missing:
print("index.html 引用了不存在的资源:")
print("\n".join(missing))
sys.exit(1)
print(f"资源引用检查通过({len(refs)} 个)")
PY