fix: wrong active item after anchor select

This commit is contained in:
iCrawl
2022-08-23 03:59:53 +02:00
parent caa5c0332f
commit af295acedc
5 changed files with 6 additions and 68 deletions

View File

@@ -65,7 +65,6 @@
"react-dom": "^18.2.0",
"react-icons": "^4.4.0",
"react-syntax-highlighter": "^15.5.0",
"rehype-highlight": "^5.0.2",
"rehype-ignore": "^1.0.1",
"rehype-raw": "^6.1.1",
"rehype-slug": "^5.0.1",

View File

@@ -102,6 +102,8 @@ export function SidebarItems({
const { classes } = useStyles();
const groupItems = groupMembers(members);
const asPathWithoutQueryAndAnchor = router.asPath.split('?')[0]?.split('#')[0];
return (
<>
{(Object.keys(groupItems) as (keyof GroupedMembers)[])
@@ -126,7 +128,7 @@ export function SidebarItems({
) : null}
</Group>
}
active={router.asPath === member.path}
active={asPathWithoutQueryAndAnchor === member.path}
variant="filled"
></NavLink>
</Link>

View File

@@ -138,8 +138,8 @@ export function SidebarLayout({
</Menu.Item>
)) ?? [];
const asPathWithoutQuery = router.asPath.split('?')[0]?.split('#')[0];
const breadcrumbs = asPathWithoutQuery?.split('/').map((path, idx, original) => (
const asPathWithoutQueryAndAnchor = router.asPath.split('?')[0]?.split('#')[0];
const breadcrumbs = asPathWithoutQueryAndAnchor?.split('/').map((path, idx, original) => (
<Link key={idx} href={original.slice(0, idx + 1).join('/')} passHref>
<Anchor component="a">{path}</Anchor>
</Link>

View File

@@ -9,7 +9,6 @@ import Head from 'next/head';
import { useRouter } from 'next/router';
import type { GetStaticPaths, GetStaticProps } from 'next/types';
import { VscChevronUp } from 'react-icons/vsc';
import rehypeHighlight from 'rehype-highlight';
import rehypeIgnore from 'rehype-ignore';
import rehypeRaw from 'rehype-raw';
import rehypeSlug from 'rehype-slug';
@@ -138,7 +137,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
mdxOptions: {
remarkPlugins: [remarkGfm],
remarkRehypeOptions: { allowDangerousHtml: true },
rehypePlugins: [rehypeRaw, rehypeIgnore, rehypeSlug, [rehypeHighlight, { ignoreMissing: true }]],
rehypePlugins: [rehypeRaw, rehypeIgnore, rehypeSlug],
format: 'md',
},
});

View File

@@ -2046,7 +2046,6 @@ __metadata:
react-dom: ^18.2.0
react-icons: ^4.4.0
react-syntax-highlighter: ^15.5.0
rehype-highlight: ^5.0.2
rehype-ignore: ^1.0.1
rehype-raw: ^6.1.1
rehype-slug: ^5.0.1
@@ -8431,15 +8430,6 @@ __metadata:
languageName: node
linkType: hard
"fault@npm:^2.0.0":
version: 2.0.1
resolution: "fault@npm:2.0.1"
dependencies:
format: ^0.2.0
checksum: c9b30f47d95769177130a9409976a899ed31eb598450fbad5b0d39f2f5f56d5f4a9ff9257e0bee8407cb0fc3ce37165657888c6aa6d78472e403893104329b72
languageName: node
linkType: hard
"fb-watchman@npm:^2.0.0":
version: 2.0.1
resolution: "fb-watchman@npm:2.0.1"
@@ -9454,17 +9444,6 @@ __metadata:
languageName: node
linkType: hard
"hast-util-to-text@npm:^3.0.0":
version: 3.1.1
resolution: "hast-util-to-text@npm:3.1.1"
dependencies:
"@types/hast": ^2.0.0
hast-util-is-element: ^2.0.0
unist-util-find-after: ^4.0.0
checksum: 2312a818c8ec7b02307b04175357e5a7a9918f48624d05366668ba60918734ca62b0ee21006a2a448e0e5a198654cd1fa4ba8c813702b465cb487e2320db523a
languageName: node
linkType: hard
"hast-util-whitespace@npm:^2.0.0":
version: 2.0.0
resolution: "hast-util-whitespace@npm:2.0.0"
@@ -9521,13 +9500,6 @@ __metadata:
languageName: node
linkType: hard
"highlight.js@npm:~11.6.0":
version: 11.6.0
resolution: "highlight.js@npm:11.6.0"
checksum: 3908eb34a4b442ca1e20c1ae6415ea935fbbcdb2b532a89948d82b0fa4ad41fc5de3802a0de4e88a0bcb7d97d4445579048cd2aab1d105ac47f59dd58a9a98ae
languageName: node
linkType: hard
"hoist-non-react-statics@npm:^3.3.1":
version: 3.3.2
resolution: "hoist-non-react-statics@npm:3.3.2"
@@ -11506,17 +11478,6 @@ __metadata:
languageName: node
linkType: hard
"lowlight@npm:^2.0.0":
version: 2.7.0
resolution: "lowlight@npm:2.7.0"
dependencies:
"@types/hast": ^2.0.0
fault: ^2.0.0
highlight.js: ~11.6.0
checksum: 6f8ed056cdeb387100ab13102b85623e59fae296a128de518cc04f5749f928a11b51eb2c2145728813f0efc3bed8130e12106129d9bc557e9110cdaaa238832f
languageName: node
linkType: hard
"lru-cache@npm:^6.0.0":
version: 6.0.0
resolution: "lru-cache@npm:6.0.0"
@@ -14332,19 +14293,6 @@ __metadata:
languageName: node
linkType: hard
"rehype-highlight@npm:^5.0.2":
version: 5.0.2
resolution: "rehype-highlight@npm:5.0.2"
dependencies:
"@types/hast": ^2.0.0
hast-util-to-text: ^3.0.0
lowlight: ^2.0.0
unified: ^10.0.0
unist-util-visit: ^4.0.0
checksum: 18ff061fdfabb7ac5b09d19f5fa23143d6e82eb6474be2670e5febe8e78e58a56e614dc7a049a1dcbb768d16bd4dee028b1f36d77b403d3c0aff7af1bab418ee
languageName: node
linkType: hard
"rehype-ignore@npm:^1.0.1":
version: 1.0.1
resolution: "rehype-ignore@npm:1.0.1"
@@ -16754,16 +16702,6 @@ __metadata:
languageName: node
linkType: hard
"unist-util-find-after@npm:^4.0.0":
version: 4.0.0
resolution: "unist-util-find-after@npm:4.0.0"
dependencies:
"@types/unist": ^2.0.0
unist-util-is: ^5.0.0
checksum: 8381ef0bad18a0b1fa1c7ee47f94a2578ab6bf572eb126a1f179526b9dca47584fc070976f2d83bbe381161fa33b9164a894d0279a30ec83e65433356d43df57
languageName: node
linkType: hard
"unist-util-generated@npm:^2.0.0":
version: 2.0.0
resolution: "unist-util-generated@npm:2.0.0"