+11
-1
src/pages/works/_components/BlockParagraph.astro
+11
-1
src/pages/works/_components/BlockParagraph.astro
···
1
1
---
2
+
import slug from "slug";
2
3
import type { InferEntrySchema } from "astro:content";
3
4
4
5
type Block =
5
6
InferEntrySchema<"works">["content"][keyof InferEntrySchema<"works">["content"]]["blocks"][number];
6
7
7
8
interface Props extends Block {}
9
+
10
+
// FIXME do this in ortfodb
11
+
const headingText =
12
+
// Get inside of <hn> tag if content is just that
13
+
Astro.props.content.match(/^<h[1-6]>(.*?)<\/h[1-6]>$/)?.[1];
14
+
const anchor = slug(headingText || "", { lower: true });
8
15
---
9
16
10
-
<div class="block-paragraph-content" set:html={Astro.props.content} />
17
+
<div
18
+
class="block-paragraph-content"
19
+
set:html={Astro.props.content.replace(/^<h([1-6])>/, `<h$1 id="${anchor}">`)}
20
+
/>
11
21
12
22
<style>
13
23
.block-paragraph-content {