diff --git a/build.sh b/build.sh
index e2cf9bb..7b55acc 100755
--- a/build.sh
+++ b/build.sh
@@ -8,12 +8,15 @@ echo "=== Building tools.simonwillison.net for Cloudflare Pages ==="
# Install Python dependencies
echo "Installing Python dependencies..."
-pip install --quiet markdown
+pip install --quiet markdown shot-scraper
# Run Python build scripts (but NOT write_docs.py which generates LLM descriptions)
echo "Gathering links and metadata..."
python gather_links.py
+echo "Generating screenshots..."
+python generate_screenshots.py
+
echo "Building colophon page..."
python build_colophon.py
diff --git a/build_colophon.py b/build_colophon.py
index 0351e37..c759a71 100755
--- a/build_colophon.py
+++ b/build_colophon.py
@@ -5,6 +5,36 @@
import html
from pathlib import Path
import markdown
+import hashlib
+
+
+def get_file_hash(file_path):
+ """Calculate SHA256 hash of file content."""
+ sha256_hash = hashlib.sha256()
+ with open(file_path, "rb") as f:
+ for byte_block in iter(lambda: f.read(4096), b""):
+ sha256_hash.update(byte_block)
+ return sha256_hash.hexdigest()
+
+
+def get_screenshot_path(page_name):
+ """Get the screenshot path for a given HTML file."""
+ # Check if the HTML file exists
+ html_path = Path(page_name)
+ if not html_path.exists():
+ return None
+
+ # Calculate the hash of the HTML file
+ file_hash = get_file_hash(html_path)
+
+ # Build the expected screenshot path
+ screenshot_name = f"{html_path.stem}.{file_hash}.jpeg"
+ screenshot_path = Path("screenshots") / screenshot_name
+
+ # Return the path if it exists, otherwise None
+ if screenshot_path.exists():
+ return str(screenshot_path)
+ return None
def format_commit_message(message):
@@ -99,6 +129,15 @@ def get_most_recent_date(page_data):
margin-bottom: 2rem;
border-bottom: 1px solid #f0f0f0;
padding-bottom: 1rem;
+ overflow: auto;
+ }
+ .tool-screenshot {
+ float: right;
+ max-width: 50%;
+ margin-left: 1rem;
+ margin-bottom: 1rem;
+ border: 1px solid #ddd;
+ border-radius: 4px;
}
.tool-name {
font-weight: bold;
@@ -210,9 +249,16 @@ def get_most_recent_date(page_data):
commits = list(reversed(commits))
commit_count = len(commits)
+ # Get screenshot path if available
+ screenshot_path = get_screenshot_path(page_name)
+ screenshot_html = ""
+ if screenshot_path:
+ screenshot_html = f''
+
# Modified tool heading with the new structure
html_content += f"""