mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(cli): label SVG contact sheet thumbnails by file name on Windows (#6732)
createSvgContactSheet built each path with path.join and then took the
label with split("/"), so on Windows the label was the whole path and
the 60-character cell limit cut the file name off. Use basename, as the
scroll and snapshot sheets in the same file already do.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
existsSync,
|
||||
lstatSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
readFileSync,
|
||||
rmSync,
|
||||
@@ -9,14 +10,15 @@ import {
|
||||
} from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import sharp from "sharp";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import sharp, { type Sharp } from "sharp";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createContactSheet,
|
||||
createAssetContactSheet,
|
||||
createScrollContactSheet,
|
||||
createSvgContactSheet,
|
||||
} from "./contactSheet.js";
|
||||
import { loadSharp } from "../utils/optionalPackages.js";
|
||||
|
||||
function tempDir(): string {
|
||||
return mkdtempSync(join(tmpdir(), "hf-contact-sheet-test-"));
|
||||
@@ -310,4 +312,31 @@ describe("contact-sheet capture budget", () => {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
it("labels each SVG thumbnail with its file name", async () => {
|
||||
const dir = tempDir();
|
||||
const runtimeSharp = await loadSharp("contact sheets");
|
||||
const sharpProto: Sharp = Object.getPrototypeOf(
|
||||
runtimeSharp({ create: { width: 1, height: 1, channels: 3, background: "#000" } }),
|
||||
);
|
||||
const composite = vi.spyOn(sharpProto, "composite");
|
||||
try {
|
||||
const svgs = join(dir, "svgs");
|
||||
mkdirSync(svgs);
|
||||
writeFileSync(
|
||||
join(svgs, "logo-mark.svg"),
|
||||
'<svg xmlns="http://www.w3.org/2000/svg"><rect width="4" height="4"/></svg>',
|
||||
);
|
||||
|
||||
await createSvgContactSheet(svgs, join(dir, "svg-contact-sheet.png"));
|
||||
|
||||
const labelSvgs = composite.mock.calls
|
||||
.flatMap(([overlays]) => overlays ?? [])
|
||||
.map((overlay) => (Buffer.isBuffer(overlay.input) ? overlay.input.toString() : ""));
|
||||
expect(labelSvgs.some((svg) => svg.includes(">1. logo-mark</text>"))).toBe(true);
|
||||
} finally {
|
||||
composite.mockRestore();
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
}, 60_000);
|
||||
});
|
||||
|
||||
@@ -304,7 +304,7 @@ export async function createSvgContactSheet(
|
||||
if (svgPaths.length === 0) return [];
|
||||
const sharp = await loadSharp("contact sheets");
|
||||
|
||||
const svgFileNames = svgPaths.map((p) => p.split("/").pop()!);
|
||||
const svgFileNames = svgPaths.map((p) => basename(p));
|
||||
|
||||
// Render ALL SVGs to PNG thumbnails first, then paginate the sheets
|
||||
const thumbSize = 200;
|
||||
|
||||
Reference in New Issue
Block a user