[components/toc][s]: fixed heading links

This commit is contained in:
olayway 2022-05-26 20:38:38 +02:00
parent 95f661eae9
commit 034bb1eb3d
3 changed files with 12 additions and 17 deletions

View File

@ -1,28 +1,16 @@
import React, { useEffect, useState, useRef } from 'react'; import React, { useEffect, useState } from 'react';
export const Heading = ({ level, observer }) => (props) => { export const Heading = ({ level, observer }) => (props) => {
const ref = useRef(null);
const handleClick = async () => {
const url = ref.current.querySelector("a").href;
try {
await navigator.clipboard.writeText(url);
} catch {
return
}
}
useEffect(() => { useEffect(() => {
if (observer) { if (observer) {
observer.observe(document.getElementById(props.id)); observer.observe(document.getElementById(props.id));
} }
}); });
return React.createElement(`h${level}`, { return React.createElement(`h${level}`, {
...props, ...props,
className: "scroll-mt-16 cursor-copy", className: "scroll-mt-16 cursor-pointer"
ref,
onClick: handleClick
}) })
} }

View File

@ -63,7 +63,7 @@ export default makeSource({
], ],
rehypePlugins: [ rehypePlugins: [
rehypeSlug, rehypeSlug,
rehypeAutolinkHeadings, [ rehypeAutolinkHeadings, { behavior: 'wrap' } ],
[ rehypeToc, { position: 'afterend' } ] [ rehypeToc, { position: 'afterend' } ]
] ]
} }

View File

@ -11,11 +11,18 @@
} }
/* OTHERS */ /* OTHERS */
html { html {
scroll-behavior: smooth; scroll-behavior: smooth;
} }
a {
@apply no-underline !important;
}
a:hover {
@apply text-yellow-li !important;
}
/* bg-neutral-800 /* bg-neutral-800
@apply bg-slate-800 @apply bg-slate-800
*/ */