-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_site.sh
More file actions
executable file
·69 lines (60 loc) · 2.13 KB
/
Copy pathcheck_site.sh
File metadata and controls
executable file
·69 lines (60 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
# check_site.sh — light validity / asset checks for the hero landing page.
#
# Runs from repo root. Exits non-zero on the first failure, with a clear
# message and an exit code that's safe for CI.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SITE="$ROOT/site"
HTML="$SITE/index.html"
CSS="$SITE/style.css"
fail() { echo "✗ $*" >&2; exit 1; }
ok() { echo "✓ $*"; }
[ -f "$HTML" ] || fail "site/index.html missing"
[ -f "$CSS" ] || fail "site/style.css missing"
ok "site/index.html and site/style.css present"
# Required meta tags / sections — grep for substrings.
need() {
grep -q -- "$1" "$HTML" || fail "site/index.html missing: $1"
}
need "<title>Python Tutor"
need 'property="og:title"'
need 'property="og:image"'
need 'name="twitter:card"'
need 'id="why"'
need 'id="loop"'
need 'id="screens"'
need 'id="start"'
ok "required <head> and section anchors present"
# Every local href/src under site/ must resolve to a real file.
# (We only check ./relative paths — external URLs are skipped.)
python3 - "$HTML" "$SITE" <<'PY'
import re, sys, os
html_path, site_dir = sys.argv[1], sys.argv[2]
src = open(html_path, encoding="utf-8").read()
refs = re.findall(r'(?:href|src)\s*=\s*"(\./[^"]+)"', src)
missing = []
for r in refs:
rel = r[2:] # drop "./"
rel = rel.split("#", 1)[0].split("?", 1)[0]
p = os.path.join(site_dir, rel)
if not os.path.exists(p):
missing.append(r)
if missing:
print("✗ missing local assets:", file=sys.stderr)
for m in missing:
print(" " + m, file=sys.stderr)
sys.exit(1)
print(f"✓ all {len(refs)} local references resolve")
PY
# Should NOT contain hard-coded localhost links (would break in prod).
if grep -nE 'href="http://localhost' "$HTML" >/dev/null; then
fail "site/index.html contains hard-coded http://localhost hrefs"
fi
ok "no hard-coded localhost hrefs"
# Cheap structural sanity check: balanced <main> tag.
opens=$(grep -c '<main' "$HTML" || true)
closes=$(grep -c '</main>' "$HTML" || true)
[ "$opens" = "$closes" ] || fail "unbalanced <main> tags ($opens open, $closes close)"
ok "<main> tags balanced"
echo "site checks passed"