Skip to content

Commit a6118f3

Browse files
committed
fix(preview): treat string previews that look like HTML as inline content instead of reading as a file (fixes .kit/main/<div></div> ENOENT)
1 parent f9c2174 commit a6118f3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/api/kit.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,8 +1909,16 @@ export let processWithStringPreview = async (s: Script, infoBlock: string) => {
19091909
processedPreview = `<div/>`
19101910
} else {
19111911
try {
1912-
let content = await readFile(path.resolve(path.dirname(s.filePath), s?.preview as string), 'utf-8')
1913-
processedPreview = infoBlock ? md(infoBlock) : `` + md(content)
1912+
const val = String(s?.preview || '').trim()
1913+
// If the preview looks like inline HTML, return it directly
1914+
if (val.startsWith('<')) {
1915+
processedPreview = (infoBlock ? md(infoBlock) : ``) + val
1916+
} else {
1917+
// Treat string as a relative doc path next to the script
1918+
const docPath = path.resolve(path.dirname(s.filePath), val)
1919+
const content = await readFile(docPath, 'utf-8')
1920+
processedPreview = (infoBlock ? md(infoBlock) : ``) + md(content)
1921+
}
19141922
} catch (error) {
19151923
processedPreview = `Error: ${error.message}`
19161924
}

0 commit comments

Comments
 (0)