simonw / til

Today I Learned

Home Page:https://til.simonwillison.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Avoid retaking all screenshots on publish unless strictly necessary

simonw opened this issue · comments

Deploy will take half an hour because it's going to need to rebuild all 450 screenshots due to an (invisible) change to the entry HTML.

Originally posted by @simonw in #81 (comment)

Changes to the content of a TIL should generate a new screenshot of that TIL.

But, right now, even the tiniest tweak to the base or entry templates (including changes that wouldn't visibly affect the shots at all) triggers a 450+ screenshot generation process.

Easiest fix: instead of incorporating the hash of the HTML templates themselves, switch to a SCREENSHOT_VERSION constant. I can then manually change that any time I want to trigger a full re-render.

I could set the first version of that to the current hash, to avoid recalculating all 450 existing shots when I deploy this change.

SHOT_HASH_PATHS = [
(root / "templates" / "pages" / "{topic}" / "{slug}.html"),
(root / "templates" / "til_base.html"),
]

shot_html_hash = hashlib.md5()
for filepath in SHOT_HASH_PATHS:
shot_html_hash.update(filepath.read_text().encode("utf-8"))
shot_html_hash = shot_html_hash.hexdigest()

Since those hashes are added in sequence, the constant would need to be a list in order to capture the current state.

If I got this right, the deploy should not recreate any screenshots.

Yes that worked:

CleanShot 2023-08-19 at 09 18 03@2x