render servo screenshots and share them with a cloudflare worker https://servo.arch.dog
Find a file
2024-09-04 15:58:19 +01:00
.forgejo/workflows Snapshot workflow 2024-08-15 22:27:34 +01:00
worker Update worker/src/index.js 2024-09-04 15:58:19 +01:00
Containerfile.servo Update Containerfile.servo 2024-09-04 14:40:50 +01:00
LICENSE Initial commit 2024-08-01 15:24:56 +01:00
README.md Update README with new snapshot.sh 2024-08-03 23:10:48 +01:00
snapshot.sh Default TMPDIR 2024-08-15 22:39:32 +01:00

Daily Servo

Despite the name, this doesn't (technically) render Servo images daily (at least, not automatically)

Still very much a work in progress but is generally at a point where you can fork and use it.

About

Various tools for rendering and sharing snapshots of websites using Servo, primarily to track my own site over time.

snapshot.sh is a wrapper around Docker for rendering a screenshot then producing a hash of the image. This can help indicate when Servo's rendering has changed. If you get inconsistant results with the same version and site, see this GitHub issue.

worker/ is a small Cloudflare Worker for collecting and serving the images. Currently requires manual uploading.

snapshot.sh

Generating snapshots is easy but requires a few commands to be run in sequence. snapshot.sh wraps:

  • Pulling the latest container image
  • Running the container image with a volume mount to produce a snapshot
  • Hashing the image
  • Uploading the image to a Worker endpoint (see below)

Uploading the image is optional, provided --dry-run is passed.

Worker

The main purpose of the worker is to serve as a repository for snapshots over time. It stores images in Cloudflare R2 and pointers to the image in KV, with a dedicated LATEST key pointing to the latest snapshot. The hash of the image is used as the filename (it could technically be anything, but it should be the hash).

Setup

You'll need a KV namespace and R2 bucket, which you can swap out in worker/wrangler.toml. You'll also want to set an API token with npx wrangler secret put API_TOKEN.

You can then POST to it!

 curl -X POST -H "Authorization: API_TOKEN" \
   https://daily-servo.your-name.workers.dev/new \
   -F date=(date -I) -F hash=098f6bcd4621d373cade4e832627b4f6 \
   -F file=@file.png

The hash is md5 since that's "good enough" for detecting duplicate files at the moment, but it could easily be swapped out.

Endpoints

A few endpoints are exposed

endpoint about
/ Basic HTML page
/latest Will 302 redirect to the latest snapshot's image
/latest.json Latest snapshot info with the hash, file URL and date
/list.json List of all snapshots (dates and hashes), along with a latest pointer
/new POST endpoint for uploading a new snapshot. Authorized endpoint
/<ISO-8601 date> Specific snapshot in JSON format

/latest.json | /<ISO-8601 date>

{
  "hash": string,
  "file": string,
  "date": ISO-8601 string
}

/list.json

{
  "latest": string,
  "list": [
    {
      "date": ISO-8601 string,
      "hash": string
    }
  ]
}