[components/toc][s]: fixed heading links
This commit is contained in:
parent
95f661eae9
commit
034bb1eb3d
|
|
@ -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
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ export default makeSource({
|
||||||
],
|
],
|
||||||
rehypePlugins: [
|
rehypePlugins: [
|
||||||
rehypeSlug,
|
rehypeSlug,
|
||||||
rehypeAutolinkHeadings,
|
[ rehypeAutolinkHeadings, { behavior: 'wrap' } ],
|
||||||
[ rehypeToc, { position: 'afterend' } ]
|
[ rehypeToc, { position: 'afterend' } ]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue