~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/knotless

git that lives in your Atmosphere account

Forked from chadtmiller.com/knotless

0
0
28 lines · 1.2 KB Raw History
// What a page's screenshot follows from, in one browser: its HTML, which
// carries the styles and scripts too, so compare.mjs shoots only the
// pages whose digest differs from the base's. Less what differs between
// worlds (DIDs, record keys, in links and in the data the page carries,
// and the port it is served on) and between builds of the same pages
// (SvelteKit's version, the time of the build, and the name of its state,
// made from it).

import { createHash } from 'node:crypto'

export const digest = (html) =>
  createHash('sha256')
    .update(
      html
        .replace(/did:plc:[a-z2-7]{24}/g, 'did')
        .replace(/127\.0\.0\.1:\d+/g, 'host')
        .replace(/\/[2-7a-z]{13}(?=["/?#\\])/g, '/rkey')
        .replace(/__sveltekit_[a-z0-9]+/g, '__sveltekit')
        .replace(/version: "\d+"/g, 'version'),
    )
    .digest('hex')

/// The path of the social card a page names, which carries a hash of what
/// the card shows: all its pixels follow from, but the renderer.
export const card = (html) => {
  const url = html.match(/<meta property="og:image" content="([^"]+)"/)[1].replaceAll('&amp;', '&')
  return new URL(url).pathname + new URL(url).search
}