diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 43ec4a7d0..d74049293 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -3,6 +3,7 @@ - [Chip Senkbeil](https://github.com/chipsenkbeil) - [Dale Noe](https://github.com/dalenoe) - [Gabor Nagy](https://github.com/Aigeruth) +- [Gary Chan](https://github.com/essesoul) - [Harry Khanna](https://github.com/hkhanna) - [Ihor Dvoretskyi](https://github.com/idvoretskyi) - [Jacob Wood](https://github.com/jacoblukewood) @@ -142,4 +143,4 @@ - [Shaked8634](https://github.com/shaked8634) - [Leo Heimann Ruiz](https://leo.heitmannruiz.org/) - [Antoine "Toinux" Wam](https://github.com/itzwam) -- [Reberti Carvalho Soares](https://github.com/RebertiCS) \ No newline at end of file +- [Reberti Carvalho Soares](https://github.com/RebertiCS) diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 201f5a2ac..897d2f49c 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -16,4 +16,8 @@ [{{ .GitInfo.AbbreviatedHash }}] {{ end }} + + {{ if (findRE " + {{ end }} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index e9cad8b17..17d9bf05f 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -19,3 +19,7 @@ {{ if .IsHome }}{{ partial "head/hugo-generator.html" . }}{{ end }} {{ partial "head/extensions.html" . }} + +{{ if (findRE " +{{ end }} \ No newline at end of file diff --git a/static/css/clipboard.css b/static/css/clipboard.css new file mode 100644 index 000000000..770a4f64c --- /dev/null +++ b/static/css/clipboard.css @@ -0,0 +1,37 @@ +.clipboard-button { + position: absolute; + right: 0; + padding: 5px 7px 3px 7px; + margin: 5px; + color: #767676; + border-color: #767676; + background-color: #ededed; + border: 1px solid; + border-radius: 6px; + font-size: 0.8em; + z-index: 1; + opacity: 0; + transition: 0.1s; + } + .clipboard-button > svg { + fill: #767676; + } + .clipboard-button:hover { + cursor: pointer; + border-color: #696969; + background-color: #e0e0e0; + } + .clipboard-button:hover > svg { + fill: #696969; + } + .clipboard-button:focus { + outline: 0; + } + .highlight { + position: relative; + } + .highlight:hover > .clipboard-button { + opacity: 1; + transition: 0.2s; + } + \ No newline at end of file diff --git a/static/js/clipboard.js b/static/js/clipboard.js new file mode 100644 index 000000000..3c01556c0 --- /dev/null +++ b/static/js/clipboard.js @@ -0,0 +1,37 @@ +const svgCopy = + ''; +const svgCheck = + ''; + +const addCopyButtons = (clipboard) => { + document.querySelectorAll("pre > code").forEach((codeBlock) => { + const button = document.createElement("button"); + button.className = "clipboard-button"; + button.type = "button"; + button.innerHTML = svgCopy; + button.addEventListener("click", () => { + clipboard.writeText(codeBlock.innerText).then( + () => { + button.blur(); + button.innerHTML = svgCheck; + setTimeout(() => (button.innerHTML = svgCopy), 2000); + }, + (error) => (button.innerHTML = "Error") + ); + }); + const pre = codeBlock.parentNode; + pre.parentNode.insertBefore(button, pre); + }); +}; +if (navigator && navigator.clipboard) { + addCopyButtons(navigator.clipboard); + } else { + const script = document.createElement("script"); + script.src = + "https://cdnjs.cloudflare.com/ajax/libs/clipboard-polyfill/2.7.0/clipboard-polyfill.promise.js"; + script.integrity = "sha256-waClS2re9NUbXRsryKoof+F9qc1gjjIhc2eT7ZbIv94="; + script.crossOrigin = "anonymous"; + script.onload = () => addCopyButtons(clipboard); + document.body.appendChild(script); + } + \ No newline at end of file