feat: src and cpy buttons in articles

This commit is contained in:
LordMZTE 2024-08-18 14:15:59 +02:00
parent f1ecac288f
commit c0ed06f7c1
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 26 additions and 2 deletions

View file

@ -5,16 +5,21 @@
<meta charset="UTF-8" />
<title><% meta.title %></title>
<link rel="stylesheet" href="/article.css" type="text/css" media="all" />
<script src="/article.js"></script>
</head>
<body>
<p id="date"><% meta.date %></p>
<div id="topright">
<p><% meta.date %></p>
<p><a href="https://git.mzte.de/LordMZTE/homepage/src/branch/master/src/a/<% meta.id %>/index.html.cgt">[src]</a></p>
</div>
<h1><% meta.title %></h1>
<p><% meta.summary %></p>
<hr />
<div id="content">
<% opt.renderMarkdown(inner) %>
</div>
<script>addCopyButtons();</script>
</body>
</html>
<! end) end end !>

View file

@ -10,8 +10,9 @@ a {
color: #cba6f7;
}
#date {
#topright {
float: right;
text-align: right;
}
#content {
@ -39,3 +40,9 @@ code,
white-space: pre-wrap;
word-wrap: break-word;
}
.codecopybtn {
cursor: copy;
float: right;
text-decoration: underline;
}

12
src/article.js Normal file
View file

@ -0,0 +1,12 @@
function addCopyButtons() {
for (let cb of document.getElementsByClassName("codeblock")) {
let cbcode = cb.getElementsByTagName("code")[0];
let copy_btn = document.createElement("a");
copy_btn.innerText = "[cpy]";
copy_btn.classList.add("codecopybtn");
copy_btn.onclick = (ev) => {
navigator.clipboard.writeText(cbcode.innerText);
};
cb.prepend(copy_btn);
}
}