fix: restore public page share thumbnails from SVG sidecars
Serve missing *.thumbnail.png requests when the SVG sidecar exists, and schedule async PNG rasterization after public HTML is materialized so WeChat og:image URLs stop 404ing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import fs from 'node:fs';
|
||||
import fsPromises from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { ensureThumbnailPng } from './mindspace-thumbnail-png.mjs';
|
||||
import { ensureHtmlThumbnail } from './mindspace-thumbnails.mjs';
|
||||
|
||||
export function workspaceThumbnailRelativePath(htmlRelativePath) {
|
||||
@@ -15,14 +16,34 @@ export function workspaceThumbnailAbsolutePath(publishDir, htmlRelativePath) {
|
||||
return path.join(publishDir, workspaceThumbnailRelativePath(htmlRelativePath));
|
||||
}
|
||||
|
||||
function scheduleWorkspaceThumbnailPng(publishDir, htmlRelativePath) {
|
||||
queueMicrotask(() => {
|
||||
void Promise.resolve()
|
||||
.then(() => {
|
||||
const svgPath = workspaceThumbnailAbsolutePath(publishDir, htmlRelativePath);
|
||||
if (fs.existsSync(svgPath)) ensureThumbnailPng(svgPath);
|
||||
})
|
||||
.catch(() => {});
|
||||
});
|
||||
}
|
||||
|
||||
/** Fire-and-forget SVG + PNG sidecars after public HTML is written (must not block Finish/chat). */
|
||||
export function scheduleWorkspaceHtmlThumbnailSidecars(publishDir, htmlRelativePath) {
|
||||
queueMicrotask(() => {
|
||||
void ensureWorkspaceHtmlThumbnail(publishDir, htmlRelativePath).catch(() => {});
|
||||
});
|
||||
}
|
||||
|
||||
export async function ensureWorkspaceHtmlThumbnail(publishDir, htmlRelativePath, html, meta = {}) {
|
||||
const htmlPath = path.join(publishDir, htmlRelativePath);
|
||||
const content = html ?? (await fsPromises.readFile(htmlPath, 'utf8'));
|
||||
const thumbRel = workspaceThumbnailRelativePath(htmlRelativePath);
|
||||
return ensureHtmlThumbnail(publishDir, thumbRel, content, {
|
||||
const svg = await ensureHtmlThumbnail(publishDir, thumbRel, content, {
|
||||
...meta,
|
||||
contentBaseDir: path.dirname(htmlPath),
|
||||
});
|
||||
scheduleWorkspaceThumbnailPng(publishDir, htmlRelativePath);
|
||||
return svg;
|
||||
}
|
||||
|
||||
export async function readWorkspaceThumbnailIfExists(publishDir, htmlRelativePath) {
|
||||
|
||||
Reference in New Issue
Block a user