Compare commits

...

4 Commits

Author SHA1 Message Date
80f5994d96
Improve code block copy text
- Use JS to get it directly from the code block instead of needing a
  separate `pre.code-raw` to get it from. That makes it possible to:
- bashsession: Don't copy prompt or command output
2023-01-22 00:09:34 -06:00
342710a755
Reduce gap between elements in subsections list 2023-01-21 23:34:34 -06:00
8eb642dbc8
Remove <hr> separator before footer 2023-01-21 23:32:32 -06:00
a4be8b395b
Remove video and add remote-figure shortcodes 2023-01-21 21:32:02 -06:00
7 changed files with 20 additions and 31 deletions

View File

@ -272,7 +272,7 @@
.sections { .sections {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 40px; gap: 10px;
} }
.section { .section {
@ -583,6 +583,7 @@ body {
} }
footer { footer {
margin-top: 20px;
text-align: center; text-align: center;
} }

View File

@ -12,14 +12,19 @@ window.onscroll = function() {
window.onload = () => { window.onload = () => {
document.querySelectorAll(".code-block").forEach(codeBlock => { document.querySelectorAll(".code-block").forEach(codeBlock => {
const button = codeBlock.querySelector(".code-header > .code-copy-button"); const button = codeBlock.querySelector(".code-header > .code-copy-button");
// TODO: maybe get this from HTMLElement.innerText on the actual code block content element
// but it's hard to select it; `data-lang` attribute might not always be there (if lang is unset) // lang will not be unset because we default it to text
const rawCode = codeBlock.querySelector("pre.code-raw").innerText; // clone it so it doesn't change the actual DOM element
const codeElem = codeBlock.querySelector("code[data-lang]").cloneNode(true);
// bashsession: remove command output lines
codeElem.querySelectorAll(".go").forEach(e => e.parentNode.removeChild(e));
// bashsession: remove prompt symbol
codeElem.querySelectorAll(".gp").forEach(e => e.parentNode.removeChild(e));
const rawCode = codeElem.innerText;
const originalCopyText = button.innerHTML; const originalCopyText = button.innerHTML;
button.onclick = event => { button.onclick = event => {
navigator.clipboard.writeText(rawCode); navigator.clipboard.writeText(rawCode);
console.log(rawCode);
// TODO: maybe we could add a fancier indicator, like a flash or something // TODO: maybe we could add a fancier indicator, like a flash or something
event.target.innerHTML = "Copied!"; event.target.innerHTML = "Copied!";
setTimeout(() => { setTimeout(() => {

View File

@ -1,13 +1,15 @@
{{ $type := "text" }}
{{ with .Type }}
{{ $type = . }}
{{ end }}
<div class="code-block"> <div class="code-block">
<div class="code-header"> <div class="code-header">
<span class="code-type">{{ .Type }}</span> <span class="code-type">{{ $type }}</span>
<a class="code-copy-button"> <a class="code-copy-button">
{{ i18n "copy_to_clipboard" }} {{ i18n "copy_to_clipboard" }}
</a> </a>
</div> </div>
{{/* a div.highlight is already created by highlight function */}}
{{ highlight .Inner .Type }}
{{/* for copy to clipboard */}} {{/* a div.highlight is already created by highlight function */}}
<pre class="code-raw" style="display: none;">{{ .Inner }}</pre> {{ highlight .Inner $type }}
</div> </div>

View File

@ -21,7 +21,6 @@
</main> </main>
{{ if or .Site.Copyright .Site.Params.footer }} {{ if or .Site.Copyright .Site.Params.footer }}
<hr>
<footer> <footer>
<small> <small>
{{ with .Site.Copyright }} {{ with .Site.Copyright }}

View File

@ -1,9 +1,4 @@
{{ $resource := "" }} {{ $resource := .Page.Resources.GetMatch (.Get "src") }}
{{ if .IsNamedParams }}
{{ $resource = $.Page.Resources.GetMatch (.Get "src") }}
{{ else }}
{{ $resource = $.Page.Resources.GetMatch (.Get 0) }}
{{ end }}
{{ $noborder := false }} {{ $noborder := false }}
{{ if .Get "noborder" }} {{ if .Get "noborder" }}

View File

@ -9,5 +9,5 @@
{{ end }} {{ end }}
<p> <p>
{{ partial "remote_figure.html" (dict "src" (.Get "src") "border" $border "hidecaption" $hidecaption "type" "image" "alt" (.Get "alt")) }} {{ partial "remote_figure.html" (dict "src" (.Get "src") "border" $border "hidecaption" $hidecaption "type" (.Get "type") "alt" (.Get "alt")) }}
</p> </p>

View File

@ -1,13 +0,0 @@
{{ $border := false }}
{{ if .Get "border" }}
{{ $border = true }}
{{ end }}
{{ $hidecaption := false }}
{{ if .Get "hidecaption" }}
{{ $hidecaption = true }}
{{ end }}
<p>
{{ partial "remote_figure.html" (dict "src" (.Get "src") "border" $border "hidecaption" $hidecaption "type" "video" "alt" (.Get "alt")) }}
</p>