From 8ec065cbcc1328878315cb7b2b56e2f7b6b9135a Mon Sep 17 00:00:00 2001 From: paspo Date: Tue, 30 Jul 2024 21:59:50 +0200 Subject: [PATCH 1/2] pulsante copia codice --- assets/sass/custom.scss | 44 +++++++++++++++++++ .../index.it.md | 4 +- layouts/_default/single.html | 42 ++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/assets/sass/custom.scss b/assets/sass/custom.scss index 42b9f06..5398b8e 100644 --- a/assets/sass/custom.scss +++ b/assets/sass/custom.scss @@ -57,3 +57,47 @@ figcaption { font-size: smaller; font-style: italic; } + +/* pulsante copia codice */ +.copy-code-button { + color: #272822; + background-color: #f7990e,; + border-color: #272822; + border: 2px solid; + border-radius: 4px 4px 0px 0px; + min-width: auto; + + /* right-align */ + display: block; + margin-left: auto; + margin-right: 0; + margin-top: 5px; + + margin-bottom: -2px; + padding: 0px 3px; + font-size: 0.5em; + font-variant-caps: small-caps; +} + +.copy-code-button:hover { + cursor: pointer; + color: #fff; + border-color: #272822; +} + +.copy-code-button:focus { + /* Avoid an ugly focus outline on click in Chrome, + but darken the button for accessibility. + See https://stackoverflow.com/a/25298082/1481479 */ + background-color: #272822; + outline: 0; +} + +.copy-code-button:active { + background-color: #272822; +} + +.highlight pre { + /* Avoid pushing up the copy buttons. */ + margin: 0; +} diff --git a/content/posts/2023/2023-03-01-proxmox-npm-parte-3/index.it.md b/content/posts/2023/2023-03-01-proxmox-npm-parte-3/index.it.md index 9b3f8eb..4617a5c 100644 --- a/content/posts/2023/2023-03-01-proxmox-npm-parte-3/index.it.md +++ b/content/posts/2023/2023-03-01-proxmox-npm-parte-3/index.it.md @@ -44,7 +44,7 @@ smtp_helo_name = pve.nomedominio.it Creare il file `/etc/postfix/sasl_passwd` inserendo: -```conf +```text [smtp.gmail.com]:587 mia_mail@gmail.com:PASSWD ``` @@ -70,7 +70,7 @@ Inviare una mail di prova: echo "Test mail from postfix" | mail -s "Test Postfix" test@test.com ``` -```conf +```text /var/log/mail.log /var/log/mail.info /var/log/mail.warn diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 329073c..486db7c 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -41,4 +41,46 @@ {{ end }} {{- .Content }} + + {{ if (findRE " + function addCopyButtons(clipboard) { + document.querySelectorAll('pre > code').forEach(function (codeBlock) { + var button = document.createElement('button'); + button.className = 'copy-code-button'; + button.type = 'button'; + button.innerText = 'Copy'; + + button.addEventListener('click', function () { + clipboard.writeText(codeBlock.innerText).then(function () { + /* Chrome doesn't seem to blur automatically, + leaving the button in a focused state. */ + button.blur(); + + button.innerText = 'Copied!'; + + setTimeout(function () { + button.innerText = 'Copy'; + }, 2000); + }, function (error) { + button.innerText = 'Error'; + }); + }); + + var pre = codeBlock.parentNode; + if (pre.parentNode.classList.contains('highlight')) { + var highlight = pre.parentNode; + highlight.parentNode.insertBefore(button, highlight); + } else { + pre.parentNode.insertBefore(button, pre); + } + }); + } + + if (navigator && navigator.clipboard) { + addCopyButtons(navigator.clipboard); + } + + {{ end }} + {{ end }} -- 2.45.2 From 72a3f47392f54ff937f85dca8f5c3b4c742ce674 Mon Sep 17 00:00:00 2001 From: paspo Date: Tue, 30 Jul 2024 23:40:10 +0200 Subject: [PATCH 2/2] numeri di linea --- assets/sass/custom.scss | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/assets/sass/custom.scss b/assets/sass/custom.scss index 5398b8e..2cb15c0 100644 --- a/assets/sass/custom.scss +++ b/assets/sass/custom.scss @@ -101,3 +101,22 @@ figcaption { /* Avoid pushing up the copy buttons. */ margin: 0; } + +/* numerazione linee */ +div.highlight pre { + counter-reset: line; + white-space: pre-wrap; +} + +div.highlight pre code > span { + counter-increment: line; + padding-left: 1.5em; +} + +div.highlight pre code > span::before { + font-size: 0.8em; + color: #999; + content: counter(line) ". "; + display: inline-block; + padding-right: 0.2em; +} -- 2.45.2