projects

saturn

My website

feat: support gifs

daniel daum committed parent 4c6ee29 commit ad05320Signed, not verified

SignedGitea couldn't verify the signature.

Showing 5 changed files with 100 additions and 15 deletions.

global.css +27 −3
@@ -955,13 +955,36 @@ article:has(> .page-header--post) {955955    margin: 0;956956}957957958/* one image keeps its shape */958/* one image keeps its shape, and so do gifs and videos */959959.post-item-media img,960.post-item-video img {960.post-item-video img,961.post-item-gif > *,962.post-item-player {961963    width: auto;962964    height: auto;963965    max-height: 26rem;964966    border: 1px solid var(--borders);967    border-radius: 2px;968}969970.post-item-gif,971.post-item-player {972    align-self: flex-start;973}974975/* gif: the video loops. with reduced motion, the still frame stands in */976.post-item-gif > img {977    display: none;978}979980@media (prefers-reduced-motion: reduce) {981    .post-item-gif:has(> img) > video {982        display: none;983    }984985    .post-item-gif > img {986        display: block;987    }965988}966989967990/* two or more: a cropped grid, two across */@@ -978,7 +1001,8 @@ article:has(> .page-header--post) {9781001    object-fit: cover;9791002}9801003981/* video: bluesky's thumbnail with a play mark, links out to watch */1004/* a video that plays on bluesky (someone else's): its thumbnail with a play1005   mark, linking out */9821006.post-item-video {9831007    position: relative;9841008    align-self: flex-start;
internal/site-guide.md +2 −1
@@ -63,7 +63,8 @@ How things show up:63636464- Links, mentions and tags are clickable.6565- Images show as a single image or a 2-across grid.66- Video shows Bluesky's thumbnail and links to Bluesky to play.66- My own videos play on the page (click to play): Safari streams Bluesky's HLS copy, other browsers play the file from my PDS. Someone else's video shows Bluesky's thumbnail and links there.67- A GIF from Bluesky's picker (Klipy) loops as a small MP4 from Bluesky's proxy (`k.gifs.bsky.app`), never from Klipy. With reduced motion it shows a still frame.6768- A quote or repost shows the other person's post in a card.6869- If the PDS returns zero posts while the site still has some, the script stops without changing anything. Run it with `-- --force` only if I really deleted everything.6970
internal/styles.html +11 −1
@@ -7,7 +7,7 @@77    <meta name="viewport" content="width=device-width, initial-scale=1.0" />88    <meta name="robots" content="noindex" />99    <meta http-equiv="Content-Security-Policy"10        content="default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'unsafe-inline'; font-src 'self'; img-src 'self' https://assets.danieldaum.net;" />10        content="default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'unsafe-inline'; font-src 'self'; img-src 'self' https://assets.danieldaum.net https://pds.danieldaum.net; media-src https://k.gifs.bsky.app;" />1111    <link rel="preload" href="/assets/fonts/ioskeleymono/IoskeleyMono-Regular.woff2" as="font" type="font/woff2" crossorigin />1212    <link rel="preload" href="/assets/fonts/ioskeleymono/IoskeleyMono-Bold.woff2" as="font" type="font/woff2" crossorigin />1313    <link rel="preload" href="/assets/fonts/ioskeleymono/IoskeleyMono-SemiBold.woff2" as="font" type="font/woff2" crossorigin />@@ -546,6 +546,16 @@546546                </article>547547            </div>548548549            <div class="demo">550                <p class="demo-label">.post-item-gif: a klipy gif as a looping mp4, the still img instead with reduced motion. my own videos are a video.post-item-player (controls, preload="none")</p>551                <article class="post-item">552                    <div class="post-item-gif">553                        <video src="https://k.gifs.bsky.app/ii/a8ada81afc59159ea5c8927feffa2e31/90/ef/AZuKvFIedRnN1u55A.mp4" poster="https://pds.danieldaum.net/xrpc/com.atproto.sync.getBlob?did=did%3Aplc%3Ae3z5gj5iyuwgqao562bo4bdf&amp;cid=bafkreiftva4sy2afsdwdu4mxa7obheflx5hx73ttavojrnyr7mv5kpqnru" width="251" height="429" role="img" aria-label="Gabby Williams celebrating" autoplay loop muted playsinline></video>554                        <img src="https://pds.danieldaum.net/xrpc/com.atproto.sync.getBlob?did=did%3Aplc%3Ae3z5gj5iyuwgqao562bo4bdf&amp;cid=bafkreiftva4sy2afsdwdu4mxa7obheflx5hx73ttavojrnyr7mv5kpqnru" alt="Gabby Williams celebrating" width="251" height="429" loading="lazy" />555                    </div>556                </article>557            </div>558549559            <div class="demo">550560                <p class="demo-label">.post-item--repost: .post-item-label in the meta row, the original post in .post-item-repost</p>551561                <article class="post-item post-item--repost">
posts/index.html +1 −1
@@ -9,7 +9,7 @@99        />1010        <meta1111            http-equiv="Content-Security-Policy"12            content="default-src 'self'; style-src 'self'; font-src 'self'; img-src 'self' https://assets.danieldaum.net https://pds.danieldaum.net https://cdn.bsky.app https://video.bsky.app https://video.cdn.bsky.app; media-src 'self' https://assets.danieldaum.net;"12            content="default-src 'self'; style-src 'self'; font-src 'self'; img-src 'self' https://assets.danieldaum.net https://pds.danieldaum.net https://cdn.bsky.app https://video.bsky.app https://video.cdn.bsky.app; media-src 'self' https://assets.danieldaum.net https://pds.danieldaum.net https://k.gifs.bsky.app https://video.bsky.app https://video.cdn.bsky.app;"1313        />1414        <meta name="referrer" content="strict-origin-when-cross-origin" />1515        <link
scripts/sync-posts.mjs +59 −9
@@ -13,8 +13,9 @@1313// dropped. a repost shows the original post, the way bluesky does.1414//1515// my pds only holds my own records, so reposted posts, quoted posts and video16// thumbnails are looked up on bluesky's public api. that happens here, at sync17// time, never when a page loads. if it fails, they fall back to plain links.16// thumbnails and streams are looked up on bluesky's public api. that happens17// here, at sync time, never when a page loads. if it fails, they fall back to18// plain links.1819//1920// if the pds2021// can't be reached, or comes back empty while the site still has posts, the@@ -165,7 +166,7 @@ function renderHighlight(item) {165166    ].filter((l) => l !== null).join("\n");166167}167168168// "2 images", "video", "link", "quote"169// "2 images", "video", "gif", "link", "quote"169170function attachments(embed) {170171    switch (embed?.$type) {171172        case "app.bsky.embed.images": {@@ -175,7 +176,7 @@ function attachments(embed) {175176        case "app.bsky.embed.video":176177            return ["video"];177178        case "app.bsky.embed.external":178            return ["link"];179            return [klipyGif(embed.external?.uri) ? "gif" : "link"];179180        case "app.bsky.embed.record":180181            return ["quote"];181182        case "app.bsky.embed.recordWithMedia":@@ -229,9 +230,9 @@ function renderEmbed(embed, view, did, bsky) {229230        case "app.bsky.embed.images":230231            return renderImages(embed.images, view?.images, did);231232        case "app.bsky.embed.video":232            return renderVideo(embed, view, bsky);233            return renderVideo(embed, view, did, bsky);233234        case "app.bsky.embed.external":234            return renderCard(embed.external);235            return renderGif(embed.external, view?.external, did) ?? renderCard(embed.external);235236        case "app.bsky.embed.record":236237            return renderQuote(embed.record, view?.record);237238        case "app.bsky.embed.recordWithMedia":@@ -256,13 +257,27 @@ function renderImages(images = [], views = [], did) {256257    return [`<div class="${cls}">`, ...imgs.map((i) => `    ${i}`), `</div>`];257258}258259259// the pds can't serve range requests, so safari won't play video from it.260// show bluesky's thumbnail and send people there to watch261function renderVideo(embed, view, bsky) {260// my own videos play here, nothing loads until play. the pds can't serve261// range requests, which safari needs, so safari streams bluesky's hls copy262// and other browsers skip it for the file on the pds (no type: they try it263// whatever the container). someone else's video is bluesky's thumbnail,264// linking there to watch265function renderVideo(embed, view, did, bsky) {262266    const thumb = view?.thumbnail;263267    if (!thumb || !/^https:\/\//.test(thumb)) {264268        return [`<p class="post-item-note"><a href="${bsky}">video &rarr; watch on bluesky</a></p>`];265269    }270    const ref = embed.video?.ref?.$link;271    if (did === DID && ref && /^https:\/\//.test(view.playlist || "")) {272        const label = embed.alt ? ` aria-label="${esc(embed.alt)}"` : "";273        return [274            `<video class="post-item-player" poster="${esc(thumb)}"${sizeAttrs(embed.aspectRatio)}${label} controls preload="none" playsinline>`,275            `    <source src="${esc(view.playlist)}" type="application/vnd.apple.mpegurl" />`,276            `    <source src="${esc(blobUrl(ref))}" />`,277            `    <a href="${bsky}">video &rarr; watch on bluesky</a>`,278            `</video>`,279        ];280    }266281    const alt = embed.alt ? `${embed.alt} (video, plays on bluesky)` : "video, plays on bluesky";267282    return [268283        `<a class="post-item-video" href="${bsky}">`,@@ -271,6 +286,41 @@ function renderVideo(embed, view, bsky) {271286    ];272287}273288289// a gif from bluesky's picker is a link card to klipy. like bluesky, play its290// mp4 from bluesky's proxy, so visitors never reach klipy. the card's thumb is291// the still frame shown with reduced motion. alt text is the description,292// which bluesky saves as "Alt: ..."293function renderGif(external, view, did) {294    const gif = klipyGif(external?.uri);295    if (!gif) return null;296    const ref = external.thumb?.ref?.$link;297    const still = did === DID ? ref && blobUrl(ref) : view?.thumb;298    const alt = (external.description || external.title || "gif").replace(/^Alt: /, "");299    const size = sizeAttrs(gif.size);300    const hasStill = typeof still === "string" && /^https:\/\//.test(still);301    return [302        `<div class="post-item-gif">`,303        `    <video src="${esc(gif.src)}"${hasStill ? ` poster="${esc(still)}"` : ""}${size} role="img" aria-label="${esc(alt)}" autoplay loop muted playsinline></video>`,304        hasStill ? `    <img src="${esc(still)}" alt="${esc(alt)}"${size} loading="lazy" />` : null,305        `</div>`,306    ].filter((l) => l !== null);307}308309// static.klipy.com/ii/<path>/<name>.gif?hh=<h>&ww=<w>&mp4=<slug>310//  -> k.gifs.bsky.app/ii/<path>/<slug>.mp4, the way bluesky's app builds it311function klipyGif(uri) {312    let url;313    try {314        url = new URL(uri);315    } catch {316        return null;317    }318    const slug = url.searchParams.get("mp4");319    if (url.hostname !== "static.klipy.com" || !url.pathname.startsWith("/ii/") || !/^[\w-]+$/.test(slug || "")) return null;320    const src = new URL(url.pathname.replace(/[^/]+$/, `${slug}.mp4`), "https://k.gifs.bsky.app");321    return { src: src.href, size: { width: Number(url.searchParams.get("ww")), height: Number(url.searchParams.get("hh")) } };322}323274324function sizeAttrs(ratio) {275325    return ratio?.width && ratio?.height ? ` width="${ratio.width}" height="${ratio.height}"` : "";276326}