61 lines
2.4 KiB
Diff
61 lines
2.4 KiB
Diff
diff --git a/src/app/labs/[slug]/page.tsx b/src/app/labs/[slug]/page.tsx
|
|
index f67308f..a6aac38 100644
|
|
--- a/src/app/labs/[slug]/page.tsx
|
|
+++ b/src/app/labs/[slug]/page.tsx
|
|
@@ -462,6 +462,19 @@ function markdownToHtml(markdown: string) {
|
|
return micromark(convertGfmTables(markdown), { allowDangerousHtml: true });
|
|
}
|
|
|
|
+function addNoReferrerToExternalImages(html: string) {
|
|
+ return html.replace(/<img\b([^>]*?)>/gi, (imageTag, rawAttrs: string) => {
|
|
+ const srcMatch = /\bsrc=(['"])(https?:\/\/[^"']+)\1/i.exec(rawAttrs);
|
|
+ if (!srcMatch || /\breferrerpolicy\s*=/i.test(rawAttrs)) return imageTag;
|
|
+
|
|
+ const trimmedAttrs = rawAttrs.trimEnd();
|
|
+ const isSelfClosing = trimmedAttrs.endsWith("/");
|
|
+ const attrs = isSelfClosing ? trimmedAttrs.slice(0, -1).trimEnd() : rawAttrs;
|
|
+
|
|
+ return `<img${attrs} referrerpolicy="no-referrer"${isSelfClosing ? " /" : ""}>`;
|
|
+ });
|
|
+}
|
|
+
|
|
export async function generateStaticParams() {
|
|
return getLabSummaries().map((lab) => ({ slug: lab.slug }));
|
|
}
|
|
@@ -503,14 +516,15 @@ export default async function LabPage({
|
|
stripOrdinals: breakoutStyle === "instruction-rails",
|
|
}),
|
|
);
|
|
- const htmlContent =
|
|
+ const htmlContent = addNoReferrerToExternalImages(
|
|
breakoutStyle === "none"
|
|
? baseHtml
|
|
: transformOutsideDetails(baseHtml, (safeHtml) =>
|
|
segmentStepSections(markExplicitInstructionElements(safeHtml, {
|
|
commandPills: breakoutStyle === "command-pills",
|
|
})),
|
|
- );
|
|
+ ),
|
|
+ );
|
|
|
|
return (
|
|
<main className="mx-auto w-full max-w-5xl px-6 py-10">
|
|
diff --git a/src/components/labs/LabContent.tsx b/src/components/labs/LabContent.tsx
|
|
index 7a7ce52..8778a23 100644
|
|
--- a/src/components/labs/LabContent.tsx
|
|
+++ b/src/components/labs/LabContent.tsx
|
|
@@ -277,7 +277,12 @@ export function LabContent({ className, html }: LabContentProps) {
|
|
>
|
|
<div className="lab-image-modal__surface" onClick={(event) => event.stopPropagation()}>
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
- <img className="lab-image-modal__image" src={zoomedImage.src} alt={zoomedImage.alt} />
|
|
+ <img
|
|
+ className="lab-image-modal__image"
|
|
+ src={zoomedImage.src}
|
|
+ alt={zoomedImage.alt}
|
|
+ referrerPolicy="no-referrer"
|
|
+ />
|
|
</div>
|
|
</div>
|
|
) : null}
|