diff --git a/app/globals.css b/app/globals.css index 018908e..6967dab 100644 --- a/app/globals.css +++ b/app/globals.css @@ -129,4 +129,30 @@ figure[data-rehype-pretty-code-figure] pre { overflow-x: auto; font-size: 0.875rem; 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; } \ No newline at end of file diff --git a/app/wiki/[slug]/page.tsx b/app/wiki/[slug]/page.tsx index 619bada..266e67e 100644 --- a/app/wiki/[slug]/page.tsx +++ b/app/wiki/[slug]/page.tsx @@ -2,11 +2,29 @@ import { getWikiPageBySlug } from '@/lib/wiki'; import { notFound } from 'next/navigation'; import { MDXRemote } from 'next-mdx-remote/rsc'; 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'; const mdxOptions = { mdxOptions: { 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, { diff --git a/package.json b/package.json index d1d5794..05b4aca 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,10 @@ "papaparse": "^5.5.4", "react": "19.2.4", "react-dom": "19.2.4", + "rehype-autolink-headings": "^7.1.0", "rehype-highlight": "^7.0.2", "rehype-pretty-code": "^0.14.5", + "rehype-slug": "^6.0.0", "rehype-stringify": "^10.0.1", "remark": "^15.0.1", "remark-html": "^16.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fe89c29..bbd6d8a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,12 +32,18 @@ importers: react-dom: specifier: 19.2.4 version: 19.2.4(react@19.2.4) + rehype-autolink-headings: + specifier: ^7.1.0 + version: 7.1.0 rehype-highlight: specifier: ^7.0.2 version: 7.0.2 rehype-pretty-code: specifier: ^0.14.5 version: 0.14.5(shiki@4.4.1) + rehype-slug: + specifier: ^6.0.0 + version: 6.0.0 rehype-stringify: specifier: ^10.0.1 version: 10.0.1 @@ -1449,6 +1455,9 @@ packages: github-from-package@0.0.0: resolution: {integrity: sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==} + github-slugger@2.0.0: + resolution: {integrity: sha512-IaOQ9puYtjrkq7Y0Ygl9KDZnrf/aiUJYUpVf89y8kyaxbRG7Y1SrX/jaumrv81vc61+kiMempujsM3Yw7w5qcw==} + glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} @@ -1513,6 +1522,9 @@ packages: hast-util-from-parse5@8.0.3: 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: resolution: {integrity: sha512-Val9mnv2IWpLbNPqc/pUem+a7Ipj2aHacCwgNfTiK0vJKl0LF+4Ba4+v1oPHFpf3bLYmreq0/l3Gud9S5OH42g==} @@ -2272,6 +2284,9 @@ packages: resolution: {integrity: sha512-dYqgNSZbDwkaJ2ceRd9ojCGjBq+mOm9LmtXnAnEGyHhN/5R7iDW2TRw3h+o/jCFxus3P2LfWIIiwowAjANm7IA==} engines: {node: '>= 0.4'} + rehype-autolink-headings@7.1.0: + resolution: {integrity: sha512-rItO/pSdvnvsP4QRB1pmPiNHUskikqtPojZKJPPPAVx9Hj8i8TwMBhofrrAYRhYOOBZH9tgmG5lPqDLuIWPWmw==} + rehype-highlight@7.0.2: resolution: {integrity: sha512-k158pK7wdC2qL3M5NcZROZ2tR/l7zOzjxXd5VGdcfIyoijjQqpHd3JKtYSBDpDZ38UI2WJWuFAtkMDxmx5kstA==} @@ -2287,6 +2302,9 @@ packages: rehype-recma@1.0.0: 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: resolution: {integrity: sha512-k9ecfXHmIPuFVI61B9DeLPN0qFHfawM6RsuX48hoqlaKSF61RskNjSm1lI8PhBEM0MRdLxVVm4WmTqJQccH9mA==} @@ -4206,6 +4224,8 @@ snapshots: github-from-package@0.0.0: {} + github-slugger@2.0.0: {} + glob-parent@5.1.2: dependencies: is-glob: 4.0.3 @@ -4276,6 +4296,10 @@ snapshots: vfile-location: 5.0.3 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: dependencies: '@types/hast': 3.0.5 @@ -5309,6 +5333,15 @@ snapshots: gopd: 1.2.0 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: dependencies: '@types/hast': 3.0.5 @@ -5341,6 +5374,14 @@ snapshots: transitivePeerDependencies: - 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: dependencies: '@types/hast': 3.0.5