From af136e8b86736430cd455324fd71fb936e79a77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20UB?= <22903142+adrian-ub@users.noreply.github.com> Date: Sun, 6 Oct 2024 17:19:38 -0500 Subject: [PATCH] feat: add autolink heading --- package.json | 4 +++- pnpm-lock.yaml | 25 +++++++++++++++++++++++++ src/index.ts | 20 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 39cd25c..16e7751 100644 --- a/package.json +++ b/package.json @@ -52,13 +52,15 @@ "unocss": "^0.63.2" }, "dependencies": { + "@astrojs/markdown-remark": "^5.2.0", "@astrojs/mdx": "^3.1.7", "@astrojs/sitemap": "^3.2.0", "bcp-47": "^2.1.0", "dayjs": "^1.11.13", "fast-glob": "^3.3.2", "i18next": "^23.15.2", - "nprogress": "^0.2.0" + "nprogress": "^0.2.0", + "rehype-autolink-headings": "^7.1.0" }, "devDependencies": { "@antfu/eslint-config": "^3.3.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 09df12b..5d1873a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@astrojs/markdown-remark': + specifier: ^5.2.0 + version: 5.2.0 '@astrojs/mdx': specifier: ^3.1.7 version: 3.1.7(astro@4.15.11(@types/node@22.7.4)(rollup@4.24.0)(typescript@5.5.4)) @@ -35,6 +38,9 @@ importers: nprogress: specifier: ^0.2.0 version: 0.2.0 + rehype-autolink-headings: + specifier: ^7.1.0 + version: 7.1.0 devDependencies: '@antfu/eslint-config': specifier: ^3.3.2 @@ -2160,6 +2166,9 @@ packages: hast-util-from-parse5@8.0.1: resolution: {integrity: sha512-Er/Iixbc7IEa7r/XLtuG52zoqn/b3Xng/w6aZQ0xGVxzhw5xUFxcRqdPzP6yFi/4HBYRaifaI5fQ1RH8n0ZeOQ==} + 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==} @@ -3016,6 +3025,9 @@ packages: resolution: {integrity: sha512-qx+xQGZVsy55CH0a1hiVwHmqjLryfh7wQyF5HO07XJ9f7dQMY/gPQHhlyDkIzJKC+x2fUCpCcUODUUUFrm7SHA==} hasBin: true + rehype-autolink-headings@7.1.0: + resolution: {integrity: sha512-rItO/pSdvnvsP4QRB1pmPiNHUskikqtPojZKJPPPAVx9Hj8i8TwMBhofrrAYRhYOOBZH9tgmG5lPqDLuIWPWmw==} + rehype-parse@9.0.1: resolution: {integrity: sha512-ksCzCD0Fgfh7trPDxr2rSylbwq9iYDkSn8TCDmEJ49ljEUBxDVCzCHv7QNzZOfODanX4+bWQ4WZqLCRWYLfhag==} @@ -6264,6 +6276,10 @@ snapshots: vfile-location: 5.0.3 web-namespaces: 2.0.1 + hast-util-heading-rank@3.0.0: + dependencies: + '@types/hast': 3.0.4 + hast-util-is-element@3.0.0: dependencies: '@types/hast': 3.0.4 @@ -7427,6 +7443,15 @@ snapshots: dependencies: jsesc: 0.5.0 + rehype-autolink-headings@7.1.0: + dependencies: + '@types/hast': 3.0.4 + '@ungap/structured-clone': 1.2.0 + hast-util-heading-rank: 3.0.0 + hast-util-is-element: 3.0.0 + unified: 11.0.5 + unist-util-visit: 5.0.0 + rehype-parse@9.0.1: dependencies: '@types/hast': 3.0.4 diff --git a/src/index.ts b/src/index.ts index b339d32..62ae0ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,9 @@ import type { AstroIntegration } from 'astro' import type { PluginTranslations, VitesseUserConfigWithPlugins } from './utils/plugins' +import { rehypeHeadingIds } from '@astrojs/markdown-remark' import mdx from '@astrojs/mdx' +import rehypeAutolinkHeadings from 'rehype-autolink-headings' import { vitesseSitemap } from './integrations/sitemap' import { vitePluginVitesseUserConfig } from './integrations/virtual-user-config' import { processI18nConfig } from './utils/i18n' @@ -93,6 +95,24 @@ export default function VitesseIntegration({ ], }, markdown: { + rehypePlugins: [ + rehypeHeadingIds, + [ + rehypeAutolinkHeadings, + { + behavior: 'append', + content: { + type: 'text', + value: '#', + }, + properties: { + ariaHidden: true, + tabIndex: -1, + className: 'header-anchor', + }, + }, + ], + ], shikiConfig: { themes: { dark: 'vitesse-dark',