Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ jobs:
run: |
python -m pip install markdown llm llm-anthropic>=0.20

- name: Generate links and build colophon
- name: Build site
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
python gather_links.py
python write_docs.py
python build_colophon.py
python build_index.py
GENERATE_LLM_DOCS: "1"
run: sh build.sh

- name: Find modified docs stems
id: docs
Expand All @@ -70,24 +67,6 @@ jobs:
git commit -m "Generated docs: ${{ steps.docs.outputs.stems }}" || exit 0
git push

- name: Inject footer.js into HTML files
run: |
# 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
for file in *.html; do
if [ -f "$file" ] && [ "$file" != "index.html" ]; 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 only
# Using tac to reverse, replace first match, then reverse back
tac "$file" | sed '0,/<\/body>/s|</body>|<script src="footer.js?'"${FOOTER_SHORT_HASH}"'"></script>\n</body>|' | tac > "$file.tmp" && mv "$file.tmp" "$file"
fi
fi
done

- name: Setup Pages
uses: actions/configure-pages@v4

Expand Down
35 changes: 26 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
#!/bin/bash
set -e

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

echo "=== Building tools.simonwillison.net for Cloudflare Pages ==="
echo "=== Building tools.simonwillison.net ==="

# Install Python dependencies
echo "Installing Python dependencies..."
pip install --quiet markdown

# Run Python build scripts (but NOT write_docs.py which generates LLM descriptions)
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

# Convert README.md to index.html using Python's markdown library
echo "Converting README.md to index.html..."
echo "Building index page..."
python build_index.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
for file in *.html; do
if [ -f "$file" ] && [ "$file" != "index.html" ]; 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 only
# Using tac to reverse, replace first match, then reverse back
tac "$file" | sed '0,/<\/body>/s|</body>|<script src="footer.js?'"${FOOTER_SHORT_HASH}"'"></script>\n</body>|' | tac > "$file.tmp" && mv "$file.tmp" "$file"
fi
fi
done

echo "=== Build complete! ==="