Skip to content

Commit 6434f9c

Browse files
Félix Dornclaude
andcommitted
fix AI comment interpolation, add chapter index redirects
Use Fragment set:html for the AI-facing HTML comment so template expressions are actually interpolated. Add index routes for /chapters/[chapter]/ and /chapters/[version]/[chapter]/ that redirect to the first section. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a43d01d commit 6434f9c

3 files changed

Lines changed: 75 additions & 8 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
import type { Chapter } from '@/textbook-loader';
3+
import { getTextbooks } from "@/lib/textbooks";
4+
5+
export async function getStaticPaths() {
6+
const textbooks = await getTextbooks();
7+
const sorted = textbooks.sort((a, b) => b.data.version.localeCompare(a.data.version));
8+
if (sorted.length === 0) return [];
9+
const textbook = sorted[0];
10+
11+
let paths = []
12+
13+
for (const chapter of textbook.data.chapters) {
14+
const chapterVariants = [
15+
String(chapter.number),
16+
String(chapter.number).padStart(2, '0'),
17+
chapter.slug,
18+
];
19+
20+
for (const chapterParam of chapterVariants) {
21+
paths.push({
22+
params: { chapter: chapterParam },
23+
props: {
24+
version: textbook.data.version,
25+
chapter,
26+
},
27+
})
28+
}
29+
}
30+
31+
return paths
32+
}
33+
34+
const { version, chapter } = Astro.props as { version: string; chapter: Chapter };
35+
36+
return Astro.redirect(`/chapters/${version}/${chapter.slug}/${chapter.sections[0].slug}`, 301);
37+
---

‎src/pages/chapters/[version]/[chapter]/[section].astro‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,22 @@ const chapterMarkdownUrl = `/chapters/${version}/${chapter.slug}.md`;
6868
const lecture = resolveResource(chapter.meta.lecture);
6969
const paper = resolveResource(chapter.meta.paper);
7070
---
71-
<!--
71+
<Fragment set:html={`<!--
7272
AI Safety Atlas — the open textbook for AI Safety
7373
Published by the French Center for AI Safety (CeSIA)
7474
https://ai-safety-atlas.com
7575
76-
This page: Chapter {chapter.number}, Section {section.number} — {section.title}
77-
Authors: {chapter.meta.authors.map(a => a.name).join(', ')}
78-
Version: {version}
76+
This page: Chapter ${chapter.number}, Section ${section.number} — ${section.title}
77+
Authors: ${chapter.meta.authors.map(a => a.name).join(', ')}
78+
Version: ${version}
7979
8080
Machine-readable formats:
81-
Markdown (this section): {sectionMarkdownUrl}
82-
Markdown (full chapter): {chapterMarkdownUrl}
81+
Markdown (this section): ${sectionMarkdownUrl}
82+
Markdown (full chapter): ${chapterMarkdownUrl}
8383
8484
Append .md to any section or chapter URL to get clean markdown.
85-
Citation: {siteConfig.citation}
86-
-->
85+
Citation: ${siteConfig.citation}
86+
-->`} />
8787
<Reader title={`${section.title} - Chapter ${chapter.number}`} description="" activeSection={section} textbook={textbook} markdownUrl={sectionMarkdownUrl} breadcrumbs={[
8888
{ text: `Chapter ${chapter.number}`, url: `/chapters/${version}/${chapter.slug}/${chapter.sections[0].slug}` },
8989
{ text: section.title, url: '#' }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
import type { Chapter } from '@/textbook-loader';
3+
import { getTextbooks } from "@/lib/textbooks";
4+
5+
export async function getStaticPaths() {
6+
const textbooks = await getTextbooks();
7+
let paths = []
8+
9+
for (const textbook of textbooks) {
10+
for (const chapter of textbook.data.chapters) {
11+
paths.push({
12+
params: {
13+
version: textbook.data.version,
14+
chapter: chapter.slug,
15+
},
16+
props: {
17+
version: textbook.data.version,
18+
chapter,
19+
},
20+
})
21+
}
22+
}
23+
24+
return paths
25+
}
26+
27+
const { version, chapter } = Astro.props as { version: string; chapter: Chapter };
28+
29+
return Astro.redirect(`/chapters/${version}/${chapter.slug}/${chapter.sections[0].slug}`, 301);
30+
---

0 commit comments

Comments
 (0)