Skip to content

Commit

Permalink
fix(documentation): fix documentation heading links (#3279)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidritter-dotcom authored Jul 17, 2024
1 parent 55c2edc commit dd67dfe
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-bananas-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-documentation': patch
---

Fixed the documentation heading links by adding the rehype-slug plugin
2 changes: 2 additions & 0 deletions packages/documentation/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { StorybookConfig } from '@storybook/web-components-vite';
import pkg from '@/../package.json';
import { mergeConfig } from 'vite';
import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';

const config: StorybookConfig = {
Expand Down Expand Up @@ -30,6 +31,7 @@ const config: StorybookConfig = {
mdxPluginOptions: {
mdxCompileOptions: {
rehypePlugins: [
rehypeSlug,
[
rehypeAutolinkHeadings,
{
Expand Down
4 changes: 2 additions & 2 deletions packages/documentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"react-syntax-highlighter": "15.5.0",
"rehype-autolink-headings": "^7.1.0",
"remark-autolink-headings": "7.0.1",
"rehype-autolink-headings": "7.1.0",
"rehype-slug": "6.0.0",
"rimraf": "6.0.1",
"sass": "1.77.6",
"storybook": "8.1.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/documentation/public/assets/scripts/autolink.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ window.addEventListener('storybook:contentReady', function () {
links.forEach(link => {
const anchor = link.getAttribute('href');
if (anchor.startsWith('#')) {
link.setAttribute('href', `${window.parent.location.href}${anchor}`);
link.setAttribute('href', `${window.parent.location.href.replace(/#.*/, '')}${anchor}`);
}
});
});
91 changes: 6 additions & 85 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dd67dfe

Please sign in to comment.