put the code copy button into the markdown processor

This commit is contained in:
Oleksandr 2025-11-22 09:00:00 +02:00
parent 7f75bba052
commit b9accda035
Signed by: Xanazf
GPG key ID: 821EEC32761AC17C
20 changed files with 176 additions and 211 deletions

View file

@ -15,16 +15,18 @@ interface Props {
title: string;
description: string;
headings?: ConfigHeading[];
type?: TypeData
type?: TypeData;
}
const { title, description, headings, type } = Astro.props;
let url = Astro.url.pathname.split("/").filter(s => s !== "");
const breadcrumbs = [{
text: "custom",
href: "/",
}];
const breadcrumbs = [
{
text: "custom",
href: "/",
},
];
let linkPath = "";
if (url[0] === "docs") {
@ -90,4 +92,33 @@ for (const segment of url) {
<Footer/>
</body>
</html>
<script>
// FIXME: need to make this work properly, or fold into the markdown processor
let headings = document.getElementsByClassName("heading")
if (headings.length > 0) {
for (const heading of headings) {
let button = heading.querySelector("h2")
if (button) {
button.onclick = () => {
let link = window.location.href.split("#")[0];
link += `#${button.textContent?.trimEnd().replaceAll(" ", "-").toLowerCase()}`;
window.location.href = link
navigator.clipboard.writeText(link);
heading.classList.toggle("copied")
setTimeout(() => heading.classList.remove("copied"), 1000);
}
}
let spanButton = heading.querySelector("span")
if (spanButton) {
spanButton.onclick = () => {
let link = window.location.href.split("#")[0];
link += `#${spanButton.textContent?.trim().replaceAll(" ", "-").toLowerCase()}`;
window.location.href = link
navigator.clipboard.writeText(link);
spanButton.classList.toggle("copied")
setTimeout(() => heading.classList.remove("copied"), 1000);
}
}
}
}
</script>