Skip to content

Commit 1d726d7

Browse files
committed
add fallback embed thumbnail on loading error
1 parent 6f1886d commit 1d726d7

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

public/icons/website.svg

Lines changed: 3 additions & 0 deletions
Loading

public/link.png

-1.91 KB
Binary file not shown.

src/utils/markdown/astro-integration-copy-generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "node:path";
44
import { fileURLToPath } from "node:url";
55

66
const copyFiles = async (srcDir: string, destDir: string) => {
7+
await fs.promises.mkdir(destDir, { recursive: true });
78
const readDir = await fs.promises.readdir(srcDir);
89

910
await Promise.all(

src/utils/markdown/iframes/iframe-placeholder.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface IFramePlaceholderProps {
1313
propsToPreserve: string;
1414
pageTitle: string;
1515
pageIcon: string;
16+
pageIconFallback: string;
1617
}
1718

1819
/** @jsxImportSource hastscript */
@@ -35,6 +36,9 @@ export function IFramePlaceholder({
3536
decoding="async"
3637
data-nozoom="true"
3738
data-dont-round="true"
39+
{...{
40+
onerror: `this.src='${props.pageIconFallback}';this.onerror='';`,
41+
}}
3842
/>
3943
</div>
4044
<div class="embed__header__info">

src/utils/markdown/iframes/rehype-transform.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface RehypeUnicornIFrameClickToRunProps {
2121
}
2222

2323
// default icon, used if a frame's favicon cannot be resolved
24-
const defaultPageIcon = "/link.png";
24+
const defaultPageIcon = "/icons/website.svg";
2525

2626
function getIconPath(src: URL) {
2727
return `generated/${src.hostname}.favicon`;
@@ -215,6 +215,7 @@ export const rehypeUnicornIFrameClickToRun: Plugin<
215215
src: String(src),
216216
pageTitle: String(dataFrameTitle ?? "") || info.title || "",
217217
pageIcon: info.iconFile,
218+
pageIconFallback: defaultPageIcon,
218219
propsToPreserve: JSON.stringify(propsToPreserve),
219220
});
220221

0 commit comments

Comments
 (0)