Skip to content

Commit

Permalink
fix(plugin-docs): use github-slugger to generate heading anchors (#8433)
Browse files Browse the repository at this point in the history
* fix(plugin-docs): use github-slugger to generate heading anchors

* fix(plugin-docs): fix dependencies

* fix: ci error

* fix: dependencies
  • Loading branch information
wyy0512 authored Jul 20, 2022
1 parent 04ffe1e commit 7a1de5c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-docs/client/theme-doc/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import cx from 'classnames';
import slugger from 'github-slugger';
import key from 'keymaster';
import React, { Fragment, useEffect, useState } from 'react';
import { useThemeContext } from './context';
import useLanguage from './useLanguage';
import getLinkFromTitle from './utils/getLinkFromTitle';

export default () => {
const { components } = useThemeContext()!;
Expand Down Expand Up @@ -168,7 +168,7 @@ function search(routes: any, keyword: string): SearchResultItem[] {
.join(' > ') +
' > ' +
title.title,
href: '/' + path + '#' + getLinkFromTitle(title.title),
href: '/' + path + '#' + slugger.slug(title.title),
});
}
});
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-docs/client/theme-doc/Toc.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import GithubSlugger from 'github-slugger';
import React from 'react';
import { Helmet } from 'react-helmet';
import { useThemeContext } from './context';
import useLanguage from './useLanguage';
import getLinkFromTitle from './utils/getLinkFromTitle';
import getTocTitle from './utils/getTocTitle';

export default () => {
const slugger = new GithubSlugger();
const { location, appData, themeConfig } = useThemeContext()!;
const lang = useLanguage();
const route =
Expand Down Expand Up @@ -48,7 +49,7 @@ export default () => {
className={`${
item.level > 2 ? 'text-sm' : 'text-base'
} break-all 2xl:break-words`}
href={'#' + getLinkFromTitle(item.title)}
href={'#' + slugger.slug(item.title)}
>
{getTocTitle(item.title)}
</a>
Expand Down
15 changes: 0 additions & 15 deletions packages/plugin-docs/client/theme-doc/utils/getLinkFromTitle.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/plugin-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
"test": "umi-scripts jest-turbo"
},
"dependencies": {
"github-slugger": "^1.4.0",
"keymaster": "1.6.2",
"react-helmet": "^6.1.0",
"rehype-pretty-code": "^0.3.1",
"shiki": "^0.10.1"
},
"devDependencies": {
"@mdx-js/mdx": "2.1.1",
"@types/github-slugger": "^1.3.0",
"@types/keymaster": "^1.6.30",
"@types/react-helmet": "^6.1.5",
"classnames": "^2.3.1",
Expand Down
Loading

1 comment on commit 7a1de5c

@vercel
Copy link

@vercel vercel bot commented on 7a1de5c Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.