From c776c2c6068df0f5910424eff3270e312f5f10ce Mon Sep 17 00:00:00 2001 From: clover caruso Date: Mon, 2 Feb 2026 03:43:13 -0800 Subject: [PATCH] feat: various changes during january friends blog resolves #60 --- run.js | 13 ++++++++----- src/bin/download-db.ts | 4 ++-- src/file-viewer/rsync.ts | 5 +++-- src/tags/photo-grid.tsx | 8 +++++++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/run.js b/run.js index a6973cba68c5a09d492428663f3db62848d153a3..e3ae6f9eeedd93f7d017125e7497288638071c41 100644 --- a/run.js +++ b/run.js @@ -17,13 +17,13 @@ process.emit = function (event, error) { let hot; try { - // required APIs + // zstd is not supported in node 22 await new Promise((resolve) => zlib.zstdCompress(new Uint8Array(), resolve)); - // seems to fail in bun + // seems to fail in bun, run it earlier to catch (await import("source-map-support")).install({ hookRequire: true }); - // Init hooks + // init hooks. some runtimes have bugs here. and long term this system should be rebuilt hot = await import("./framework/hot.ts"); hot.load("./lib/log.ts"); } catch (e) { @@ -70,9 +70,12 @@ if (process.argv[1].startsWith(import.meta.filename.slice(0, -".js".length))) { process.exit(1); } let found; - for (const dir of ["./", "./src/", "./framework/"]) { + for (const dir of fs.globSync("{lib,{src,framework},{src,lib}/**/bin}")) { try { - found = hot.resolveFrom(import.meta.filename, dir + process.argv[2]); + found = hot.resolveFrom( + import.meta.filename, + `./${dir}/${process.argv[2]}`, + ); break; } catch (e) { continue; diff --git a/src/bin/download-db.ts b/src/bin/download-db.ts index 7d7c5d374881d51179febf520d28a23da5131b76..1d40fa9c87384595eec28702481f2c88df3e1553 100644 --- a/src/bin/download-db.ts +++ b/src/bin/download-db.ts @@ -1,6 +1,6 @@ export async function main() { await rsync.spawn({ - cwd: Path.resolve(import.meta.dirname).parent!.toString(), + cwd: Path.resolve("."), args: [ "-a", "--progress", @@ -10,7 +10,7 @@ export async function main() { progress: progress.start("download file cache"), }); await rsync.spawn({ - cwd: Path.resolve(import.meta.dirname).parent!.toString(), + cwd: Path.resolve("."), args: [ "-a", "--progress", diff --git a/src/file-viewer/rsync.ts b/src/file-viewer/rsync.ts index 83b8fb8fa4e0a5daa9186816da67e2a0cf46d74a..403c9999094c70793e6c89d73003b1a8ab632116 100644 --- a/src/file-viewer/rsync.ts +++ b/src/file-viewer/rsync.ts @@ -25,7 +25,7 @@ export interface SpawnOptions { args: string[]; rsync?: string; progress: progress.Node; - cwd?: string; + cwd?: Path; } export async function spawn(options: SpawnOptions) { @@ -33,7 +33,7 @@ export async function spawn(options: SpawnOptions) { using node = options.progress; const proc = child_process.spawn(rsync, [...defaultExtraOptions, ...args], { stdio: ["ignore", "pipe", "pipe"], - cwd, + cwd: cwd?.toString(), }); const parser = new Parse(); let running = true; @@ -186,3 +186,4 @@ import events from "node:events"; import * as progress from "lib/progress.ts"; import { formatSize } from "@/file-viewer/format.ts"; import { UNWRAP } from "lib/assert.ts"; +import { Path } from "#sitegen/path"; diff --git a/src/tags/photo-grid.tsx b/src/tags/photo-grid.tsx index fbcd549157633c0d6d9c029ee0ef951749295da1..452137277a30ae42b246299880ae5439103fb8fe 100644 --- a/src/tags/photo-grid.tsx +++ b/src/tags/photo-grid.tsx @@ -12,6 +12,7 @@ export interface PhotoGridProps { type Item = [img: string, options?: ItemOptions]; interface ItemOptions { + s?: number; w?: number; h?: number; align?: keyof typeof alignments; @@ -55,9 +56,14 @@ export function PhotoGrid({ let y = 0; let contents = []; for (const item of items) { - const [img, { w = 1, h = 1, align } = {}] = isArray(item) ? item : [item]; + const [ + img, + { w = 1, h = 1, align, s } = {}, + ] = isArray(item) ? item : [item]; if (w > width) throw new Error(`Item ${img} too wide (${w} > ${width})`); + x += s ?? 0; + while (anyCollide(x, y, w, h)) { x += 1; if (x > width - w) x = 0, y += 1; -- 2.54.0