Skip to content

Commit b674890

Browse files
authored
Unify Cloudflare and GitHub Actions build scripts (#137)
* Unify Cloudflare and GitHub Actions build scripts * Make markdown dependency optional > Have the build_colophon.py try/except import the markdown module and if it is not available fall back to just copying in the text Refs #137 (comment) * Revert "Make markdown dependency optional" This reverts commit ac29359. I'm going to have it work on Cloudflare instead.
1 parent c2f5c11 commit b674890

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

.github/workflows/pages.yml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@ jobs:
3636
run: |
3737
python -m pip install markdown llm llm-anthropic>=0.20
3838
39-
- name: Generate links and build colophon
39+
- name: Build site
4040
env:
4141
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
42-
run: |
43-
python gather_links.py
44-
python write_docs.py
45-
python build_colophon.py
46-
python build_index.py
42+
GENERATE_LLM_DOCS: "1"
43+
run: sh build.sh
4744

4845
- name: Find modified docs stems
4946
id: docs
@@ -70,24 +67,6 @@ jobs:
7067
git commit -m "Generated docs: ${{ steps.docs.outputs.stems }}" || exit 0
7168
git push
7269
73-
- name: Inject footer.js into HTML files
74-
run: |
75-
# Get the git hash of the last commit that touched footer.js
76-
FOOTER_HASH=$(git log -1 --format="%H" -- footer.js)
77-
FOOTER_SHORT_HASH=$(echo "$FOOTER_HASH" | cut -c1-8)
78-
79-
# Insert footer.js script tag into all root-level .html files except index.html
80-
for file in *.html; do
81-
if [ -f "$file" ] && [ "$file" != "index.html" ]; then
82-
# Check if footer.js is not already included
83-
if ! grep -q 'src="footer.js' "$file"; then
84-
# Insert script tag before the LAST </body> tag only
85-
# Using tac to reverse, replace first match, then reverse back
86-
tac "$file" | sed '0,/<\/body>/s|</body>|<script src="footer.js?'"${FOOTER_SHORT_HASH}"'"></script>\n</body>|' | tac > "$file.tmp" && mv "$file.tmp" "$file"
87-
fi
88-
fi
89-
done
90-
9170
- name: Setup Pages
9271
uses: actions/configure-pages@v4
9372

build.sh

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11
#!/bin/bash
22
set -e
33

4-
# Mae sure we have the full git history for finding commit dates:
4+
# Make sure we have the full git history for finding commit dates:
55
git fetch --unshallow
66

7-
echo "=== Building tools.simonwillison.net for Cloudflare Pages ==="
7+
echo "=== Building tools.simonwillison.net ==="
88

9-
# Install Python dependencies
10-
echo "Installing Python dependencies..."
11-
pip install --quiet markdown
12-
13-
# Run Python build scripts (but NOT write_docs.py which generates LLM descriptions)
149
echo "Gathering links and metadata..."
1510
python gather_links.py
1611

12+
# Only generate LLM summaries if GENERATE_LLM_DOCS is set
13+
if [ "$GENERATE_LLM_DOCS" = "1" ]; then
14+
echo "Generating LLM documentation..."
15+
python write_docs.py
16+
fi
17+
1718
echo "Building colophon page..."
1819
python build_colophon.py
1920

20-
# Convert README.md to index.html using Python's markdown library
21-
echo "Converting README.md to index.html..."
21+
echo "Building index page..."
2222
python build_index.py
2323

24+
echo "Injecting footer.js into HTML files..."
25+
# Get the git hash of the last commit that touched footer.js
26+
FOOTER_HASH=$(git log -1 --format="%H" -- footer.js)
27+
FOOTER_SHORT_HASH=$(echo "$FOOTER_HASH" | cut -c1-8)
28+
29+
# Insert footer.js script tag into all root-level .html files except index.html
30+
for file in *.html; do
31+
if [ -f "$file" ] && [ "$file" != "index.html" ]; then
32+
# Check if footer.js is not already included
33+
if ! grep -q 'src="footer.js' "$file"; then
34+
# Insert script tag before the LAST </body> tag only
35+
# Using tac to reverse, replace first match, then reverse back
36+
tac "$file" | sed '0,/<\/body>/s|</body>|<script src="footer.js?'"${FOOTER_SHORT_HASH}"'"></script>\n</body>|' | tac > "$file.tmp" && mv "$file.tmp" "$file"
37+
fi
38+
fi
39+
done
40+
2441
echo "=== Build complete! ==="

0 commit comments

Comments
 (0)