[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) => {
const ref = useRef(null);
const handleClick = async () => {
const url = ref.current.querySelector("a").href;
try {
await navigator.clipboard.writeText(url);
} catch {
return
}
}
useEffect(() => {
if (observer) {
observer.observe(document.getElementById(props.id));
}
});
return React.createElement(`h${level}`, {
...props,
className: "scroll-mt-16 cursor-copy",
ref,
onClick: handleClick
className: "scroll-mt-16 cursor-pointer"
})
}

View File

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

View File

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