-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·64 lines (52 loc) · 1.86 KB
/
build.sh
File metadata and controls
executable file
·64 lines (52 loc) · 1.86 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
#!/bin/bash
set -e
# Make sure we have the full git history for finding commit dates:
if [ -f .git/shallow ]; then
git fetch --unshallow
fi
echo "=== Building tools.simonwillison.net ==="
echo "Gathering links and metadata..."
python gather_links.py
# Only generate LLM summaries if GENERATE_LLM_DOCS is set
if [ "$GENERATE_LLM_DOCS" = "1" ]; then
echo "Generating LLM documentation..."
python write_docs.py
fi
echo "Building colophon page..."
python build_colophon.py
echo "Building dates.json..."
python build_dates.py
echo "Building index page..."
python build_index.py
echo "Building by-month page..."
python build_by_month.py
echo "Injecting footer.js into HTML files..."
# Get the git hash of the last commit that touched footer.js
FOOTER_HASH=$(git log -1 --format="%H" -- footer.js)
FOOTER_SHORT_HASH=$(echo "$FOOTER_HASH" | cut -c1-8)
# Insert footer.js script tag into all root-level .html files except index.html
# Only process files that are tracked in git
for file in *.html; do
if [ -f "$file" ] && [ "$file" != "index.html" ] && git ls-files --error-unmatch "$file" > /dev/null 2>&1; then
# Check if footer.js is not already included
if ! grep -q 'src="footer.js' "$file"; then
# Insert script tag before the LAST </body> tag using awk
awk -v script="<script type=\"module\" src=\"footer.js?${FOOTER_SHORT_HASH}\"></script>" '
{ lines[NR] = $0 }
/<\/body>/ { last_body = NR }
END {
for (i = 1; i <= NR; i++) {
if (i == last_body) {
sub(/<\/body>/, script "\n</body>", lines[i])
}
print lines[i]
}
}
' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
fi
fi
done
# Build redirects last so they don't get indexed in tools.json
echo "Building redirects from _redirects.json..."
python build_redirects.py
echo "=== Build complete! ==="