From 82f811291d2160d2f90ced301645bd3a2e0a9982 Mon Sep 17 00:00:00 2001 From: Baptiste Parmantier Date: Fri, 21 Nov 2025 20:20:37 +0100 Subject: [PATCH] feat: implement heading anchors --- src/lib/components/content/heading/h2.astro | 32 +++++++++++++++++++++ src/lib/components/content/heading/h3.astro | 32 +++++++++++++++++++++ src/pages/docs/[...slug].astro | 15 +++++++--- 3 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 src/lib/components/content/heading/h2.astro create mode 100644 src/lib/components/content/heading/h3.astro diff --git a/src/lib/components/content/heading/h2.astro b/src/lib/components/content/heading/h2.astro new file mode 100644 index 0000000..a6519a6 --- /dev/null +++ b/src/lib/components/content/heading/h2.astro @@ -0,0 +1,32 @@ +--- +import { Icon } from "@iconify/react/dist/iconify.js"; + +const props = Astro.props; +const { slug } = Astro.params; +const { origin, pathname } = Astro.url; + +const currentAnchor = `${origin}${pathname}#${props.id}`; +--- + +

+ + + + +

diff --git a/src/lib/components/content/heading/h3.astro b/src/lib/components/content/heading/h3.astro new file mode 100644 index 0000000..c50a60b --- /dev/null +++ b/src/lib/components/content/heading/h3.astro @@ -0,0 +1,32 @@ +--- +import { Icon } from "@iconify/react/dist/iconify.js"; + +const props = Astro.props; +const { slug } = Astro.params; +const { origin, pathname } = Astro.url; + +const currentAnchor = `${origin}${pathname}#${props.id}`; +--- + +

+ + + + +

diff --git a/src/pages/docs/[...slug].astro b/src/pages/docs/[...slug].astro index de5a81e..902ee1c 100644 --- a/src/pages/docs/[...slug].astro +++ b/src/pages/docs/[...slug].astro @@ -17,6 +17,8 @@ import DocNavigationWrapper from "@/components/elements/DocNavigationWrapper.ast import { Icon } from "@iconify/react"; import BlogListWrapper from "@/plugins/blog-list/BlogListWrapper.astro"; import BlockRenderer from "@/plugins/parser/block-renderer.astro"; +import H2 from "@/components/content/heading/h2.astro"; +import H3 from "@/components/content/heading/h3.astro"; interface Props { element: CollectionEntry<"blog">; } @@ -99,7 +101,13 @@ function pascalCase(str: string) {
@@ -108,9 +116,8 @@ function pascalCase(str: string) { role="separator" class="flex items-center align-center text-center w-full flex-row pt-20" > -
+
+