Initial snapshot before transformerlab recovery

This commit is contained in:
Codex
2026-03-31 13:25:25 -06:00
commit d860318d43
49 changed files with 3864 additions and 0 deletions
@@ -0,0 +1,60 @@
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}
+51
View File
@@ -0,0 +1,51 @@
- name: Clone lab wiki
git:
repo: "{{ courseware_wiki_repo }}"
dest: "{{ courseware_wiki_repo_dir }}"
update: false
- name: Check whether wiki referrer policy patch is already applied
command:
argv:
- git
- apply
- --reverse
- --check
- "{{ role_path }}/files/referrer-policy.patch"
args:
chdir: "{{ courseware_wiki_repo_dir }}"
register: courseware_wiki_referrer_policy_patch
changed_when: false
failed_when: false
- name: Apply managed wiki referrer policy patch
command:
argv:
- git
- apply
- "{{ role_path }}/files/referrer-policy.patch"
args:
chdir: "{{ courseware_wiki_repo_dir }}"
when: courseware_wiki_referrer_policy_patch.rc != 0
- name: Install wiki dependencies with contained Node runtime
command: npm install
args:
chdir: "{{ courseware_wiki_repo_dir }}"
creates: "{{ courseware_wiki_repo_dir }}/node_modules/next/package.json"
environment:
PATH: "{{ courseware_node_runtime_bin_dir }}:{{ ansible_env.PATH }}"
- name: Stat wiki build output
stat:
path: "{{ courseware_wiki_repo_dir }}/.next/BUILD_ID"
register: courseware_wiki_build
- name: Build wiki for managed service startup
command: npm run build
args:
chdir: "{{ courseware_wiki_repo_dir }}"
environment:
PATH: "{{ courseware_node_runtime_bin_dir }}:{{ ansible_env.PATH }}"
when:
- not courseware_wiki_build.stat.exists or courseware_wiki_referrer_policy_patch.rc != 0