feat: add heading anchor links

This commit is contained in:
robin committed 2026-08-05 12:52:20 +02:00
1 parent e403677a71
commit bf8e78d0ba
4 files changed
+87

No files matched your search

+26
View File
@@ -130,3 +130,29 @@ figure[data-rehype-pretty-code-figure] pre {
font-size: 0.875rem; font-size: 0.875rem;
line-height: 1.7; line-height: 1.7;
} }
h1, h2, h3, h4, h5, h6 {
scroll-margin-top: 5rem; /* <-- Höhe deines Headers + etwas Abstand */
}
html {
scroll-behavior: smooth;
}
/* Anchor-Link Styling */
.heading-anchor {
opacity: 0;
margin-right: 1em; /* Abstand zum nachfolgenden Text */
color: #3b82f6; /* Tailwind blue-500 */
text-decoration: none;
font-weight: 800;
transition: opacity 0.15s ease-in-out;
}
h1:hover .heading-anchor,
h2:hover .heading-anchor,
h3:hover .heading-anchor,
h4:hover .heading-anchor,
.heading-anchor:focus {
opacity: 1;
}
+18
View File
@@ -2,11 +2,29 @@ import { getWikiPageBySlug } from '@/lib/wiki';
import { notFound } from 'next/navigation'; import { notFound } from 'next/navigation';
import { MDXRemote } from 'next-mdx-remote/rsc'; import { MDXRemote } from 'next-mdx-remote/rsc';
import rehypePrettyCode from 'rehype-pretty-code'; import rehypePrettyCode from 'rehype-pretty-code';
import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import { Callout, Grid, Card, Steps, Step, InlineCode, CodeBlockContainer } from '@/components/mdx-components'; import { Callout, Grid, Card, Steps, Step, InlineCode, CodeBlockContainer } from '@/components/mdx-components';
const mdxOptions = { const mdxOptions = {
mdxOptions: { mdxOptions: {
rehypePlugins: [ rehypePlugins: [
rehypeSlug, // creates heading-ids automaticly
[
rehypeAutolinkHeadings,
{
behavior: 'prepend', // symbol is PRE header
properties: {
className: ['heading-anchor'],
ariaHidden: 'true',
tabIndex: -1,
},
content: {
type: 'text',
value: ' #', // symbol
},
},
],
[ [
rehypePrettyCode, rehypePrettyCode,
{ {
+2
View File
@@ -17,8 +17,10 @@
"papaparse": "^5.5.4", "papaparse": "^5.5.4",
"react": "19.2.4", "react": "19.2.4",
"react-dom": "19.2.4", "react-dom": "19.2.4",
"rehype-autolink-headings": "^7.1.0",
"rehype-highlight": "^7.0.2", "rehype-highlight": "^7.0.2",
"rehype-pretty-code": "^0.14.5", "rehype-pretty-code": "^0.14.5",
"rehype-slug": "^6.0.0",
"rehype-stringify": "^10.0.1", "rehype-stringify": "^10.0.1",
"remark": "^15.0.1", "remark": "^15.0.1",
"remark-html": "^16.0.1", "remark-html": "^16.0.1",
+41
View File
@@ -32,12 +32,18 @@ importers:
react-dom: react-dom:
specifier: 19.2.4 specifier: 19.2.4
version: 19.2.4(react@19.2.4) version: 19.2.4(react@19.2.4)
rehype-autolink-headings:
specifier: ^7.1.0
version: 7.1.0
rehype-highlight: rehype-highlight:
specifier: ^7.0.2 specifier: ^7.0.2
version: 7.0.2 version: 7.0.2
rehype-pretty-code: rehype-pretty-code:
specifier: ^0.14.5 specifier: ^0.14.5
version: 0.14.5(shiki@4.4.1) version: 0.14.5(shiki@4.4.1)
rehype-slug:
specifier: ^6.0.0
version: 6.0.0
rehype-stringify: rehype-stringify:
specifier: ^10.0.1 specifier: ^10.0.1
version: 10.0.1 version: 10.0.1
@@ -1449,6 +1455,9 @@ packages:
github-from-package@0.0.0: github-from-package@0.0.0:
resolution: {integrity: sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==} resolution: {integrity: sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==}
github-slugger@2.0.0:
resolution: {integrity: sha512-IaOQ9puYtjrkq7Y0Ygl9KDZnrf/aiUJYUpVf89y8kyaxbRG7Y1SrX/jaumrv81vc61+kiMempujsM3Yw7w5qcw==}
glob-parent@5.1.2: glob-parent@5.1.2:
resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
engines: {node: '>= 6'} engines: {node: '>= 6'}
@@ -1513,6 +1522,9 @@ packages:
hast-util-from-parse5@8.0.3: hast-util-from-parse5@8.0.3:
resolution: {integrity: sha512-3kxEVkEKt0zvcZ3hCRYI8rqrgwtlIOFMWkbclACvjlDw8Li9S2hk/d51OI0nr/gIpdMHNepwgOKqZ/sy0Clpyg==} resolution: {integrity: sha512-3kxEVkEKt0zvcZ3hCRYI8rqrgwtlIOFMWkbclACvjlDw8Li9S2hk/d51OI0nr/gIpdMHNepwgOKqZ/sy0Clpyg==}
hast-util-heading-rank@3.0.0:
resolution: {integrity: sha512-EJKb8oMUXVHcWZTDepnr+WNbfnXKFNf9duMesmr4S8SXTJBJ9M4Yok08pu9vxdJwdlGRhVumk9mEhkEvKGifwA==}
hast-util-is-element@3.0.0: hast-util-is-element@3.0.0:
resolution: {integrity: sha512-Val9mnv2IWpLbNPqc/pUem+a7Ipj2aHacCwgNfTiK0vJKl0LF+4Ba4+v1oPHFpf3bLYmreq0/l3Gud9S5OH42g==} resolution: {integrity: sha512-Val9mnv2IWpLbNPqc/pUem+a7Ipj2aHacCwgNfTiK0vJKl0LF+4Ba4+v1oPHFpf3bLYmreq0/l3Gud9S5OH42g==}
@@ -2272,6 +2284,9 @@ packages:
resolution: {integrity: sha512-dYqgNSZbDwkaJ2ceRd9ojCGjBq+mOm9LmtXnAnEGyHhN/5R7iDW2TRw3h+o/jCFxus3P2LfWIIiwowAjANm7IA==} resolution: {integrity: sha512-dYqgNSZbDwkaJ2ceRd9ojCGjBq+mOm9LmtXnAnEGyHhN/5R7iDW2TRw3h+o/jCFxus3P2LfWIIiwowAjANm7IA==}
engines: {node: '>= 0.4'} engines: {node: '>= 0.4'}
rehype-autolink-headings@7.1.0:
resolution: {integrity: sha512-rItO/pSdvnvsP4QRB1pmPiNHUskikqtPojZKJPPPAVx9Hj8i8TwMBhofrrAYRhYOOBZH9tgmG5lPqDLuIWPWmw==}
rehype-highlight@7.0.2: rehype-highlight@7.0.2:
resolution: {integrity: sha512-k158pK7wdC2qL3M5NcZROZ2tR/l7zOzjxXd5VGdcfIyoijjQqpHd3JKtYSBDpDZ38UI2WJWuFAtkMDxmx5kstA==} resolution: {integrity: sha512-k158pK7wdC2qL3M5NcZROZ2tR/l7zOzjxXd5VGdcfIyoijjQqpHd3JKtYSBDpDZ38UI2WJWuFAtkMDxmx5kstA==}
@@ -2287,6 +2302,9 @@ packages:
rehype-recma@1.0.0: rehype-recma@1.0.0:
resolution: {integrity: sha512-lqA4rGUf1JmacCNWWZx0Wv1dHqMwxzsDWYMTowuplHF3xH0N/MmrZ/G3BDZnzAkRmxDadujCjaKM2hqYdCBOGw==} resolution: {integrity: sha512-lqA4rGUf1JmacCNWWZx0Wv1dHqMwxzsDWYMTowuplHF3xH0N/MmrZ/G3BDZnzAkRmxDadujCjaKM2hqYdCBOGw==}
rehype-slug@6.0.0:
resolution: {integrity: sha512-lWyvf/jwu+oS5+hL5eClVd3hNdmwM1kAC0BUvEGD19pajQMIzcNUd/k9GsfQ+FfECvX+JE+e9/btsKH0EjJT6A==}
rehype-stringify@10.0.1: rehype-stringify@10.0.1:
resolution: {integrity: sha512-k9ecfXHmIPuFVI61B9DeLPN0qFHfawM6RsuX48hoqlaKSF61RskNjSm1lI8PhBEM0MRdLxVVm4WmTqJQccH9mA==} resolution: {integrity: sha512-k9ecfXHmIPuFVI61B9DeLPN0qFHfawM6RsuX48hoqlaKSF61RskNjSm1lI8PhBEM0MRdLxVVm4WmTqJQccH9mA==}
@@ -4206,6 +4224,8 @@ snapshots:
github-from-package@0.0.0: {} github-from-package@0.0.0: {}
github-slugger@2.0.0: {}
glob-parent@5.1.2: glob-parent@5.1.2:
dependencies: dependencies:
is-glob: 4.0.3 is-glob: 4.0.3
@@ -4276,6 +4296,10 @@ snapshots:
vfile-location: 5.0.3 vfile-location: 5.0.3
web-namespaces: 2.0.1 web-namespaces: 2.0.1
hast-util-heading-rank@3.0.0:
dependencies:
'@types/hast': 3.0.5
hast-util-is-element@3.0.0: hast-util-is-element@3.0.0:
dependencies: dependencies:
'@types/hast': 3.0.5 '@types/hast': 3.0.5
@@ -5309,6 +5333,15 @@ snapshots:
gopd: 1.2.0 gopd: 1.2.0
set-function-name: 2.0.2 set-function-name: 2.0.2
rehype-autolink-headings@7.1.0:
dependencies:
'@types/hast': 3.0.5
'@ungap/structured-clone': 1.3.3
hast-util-heading-rank: 3.0.0
hast-util-is-element: 3.0.0
unified: 11.0.5
unist-util-visit: 5.1.0
rehype-highlight@7.0.2: rehype-highlight@7.0.2:
dependencies: dependencies:
'@types/hast': 3.0.5 '@types/hast': 3.0.5
@@ -5341,6 +5374,14 @@ snapshots:
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
rehype-slug@6.0.0:
dependencies:
'@types/hast': 3.0.5
github-slugger: 2.0.0
hast-util-heading-rank: 3.0.0
hast-util-to-string: 3.0.1
unist-util-visit: 5.1.0
rehype-stringify@10.0.1: rehype-stringify@10.0.1:
dependencies: dependencies:
'@types/hast': 3.0.5 '@types/hast': 3.0.5