mirror of
https://github.com/foo-dogsquared/website.git
synced 2025-01-30 22:57:59 +00:00
Create QoL improvements for code listings
- Added a "Copy to clipboard" button for easily following in case the post is code-heavy. - Added a toggle fullscreen button for code listings that are too large. It is pretty small and limiting in those cases, after all.
This commit is contained in:
parent
26a5d90926
commit
f835f0aa6f
33
i18n/en.toml
Normal file
33
i18n/en.toml
Normal file
@ -0,0 +1,33 @@
|
||||
[siteFooterAriaLabel]
|
||||
other = "Site footer"
|
||||
|
||||
[copyButtonLabel]
|
||||
other = "Copy to clipboard"
|
||||
|
||||
[copyButtonAriaLabel]
|
||||
other = "Copy to clipboard"
|
||||
|
||||
[copyButtonDescription]
|
||||
other = "Copy the code listing content to clipboard"
|
||||
|
||||
[fullscreenButtonLabel]
|
||||
other = "Toggle fullscreen"
|
||||
|
||||
[fullscreenButtonAriaLabel]
|
||||
other = "Toggle fullscreen"
|
||||
|
||||
[fullscreenButtonDescription]
|
||||
other = "Make the code listing takes up fullscreen"
|
||||
|
||||
[generatedOn]
|
||||
other = "Generated on"
|
||||
|
||||
[siteFeaturesScriptingDisabled]
|
||||
other = """
|
||||
Some of the features of this site relies on JavaScript scripting.
|
||||
You'll be missing out on some features such as copying code listings to the clipboard, code syntax higlighting, and code listing fullscreen button.
|
||||
Also, some of the JavaScript libraries this site relies on such as interactive image zooming and MathJax rendering will be disabled.
|
||||
"""
|
||||
|
||||
[lastUpdated]
|
||||
other = "Last updated"
|
@ -1,10 +1,10 @@
|
||||
<footer aria-label="Site footer">
|
||||
<footer aria-label="{{ T "siteFooterAriaLabel" }}">
|
||||
<!-- A convenient back to top link. -->
|
||||
<p><a href="#top">{{ i18n "back_to_top" | default "Back to top" }}</a></p>
|
||||
<p><a href="#top">{{ T "back_to_top" | default "Back to top" }}</a></p>
|
||||
|
||||
<!-- Linking to other languages' homepage. -->
|
||||
{{ if $.Site.IsMultiLingual }}
|
||||
<p>{{ i18n "multilingual" }}:
|
||||
<p>{{ T "multilingual" }}:
|
||||
<span class="list site__languages">
|
||||
{{ range $.Site.Languages }}
|
||||
<a href="{{ . | relURL }}" hreflang="{{ .Lang }}">{{ with .LanguageName }}{{ . }}{{ else }}{{ .Lang }}{{ end }}</a>
|
||||
@ -47,15 +47,80 @@
|
||||
{{- end }}
|
||||
|
||||
<p>
|
||||
<small>Generated on {{ now.Format "2006-01-02 15:04:05 -0700" }}</small></p>
|
||||
<small>{{ T "generatedOn" }} {{ now.Format "2006-01-02 15:04:05 -0700" }}</small></p>
|
||||
|
||||
{{ with (getenv "LAST_COMMIT_DATE") }}
|
||||
<p>Last updated: {{ time . | dateFormat "2 Jan 2006" }}</p>
|
||||
<p>{{ T "lastUpdated" }}: {{ time . | dateFormat "2 Jan 2006" }}</p>
|
||||
{{ end }}
|
||||
|
||||
{{ $logo := resources.Get "svg/logo.svg" }}
|
||||
<div id="logo" data-tooltip="Hey there! :3">
|
||||
{{ $logo.Content | safeHTML }}
|
||||
</div>
|
||||
|
||||
<noscript>{{ T "siteFeaturesScriptingDisabled" }}</noscript>
|
||||
</footer>
|
||||
|
||||
<!-- Have these scripts as a separate file. -->
|
||||
<script>
|
||||
var logo = document.querySelector("#logo");
|
||||
var logoQuotes = [
|
||||
"Hey there! :3",
|
||||
"Just dancing in this void for at least 659 hours, how about you?",
|
||||
"How's it going, man?",
|
||||
"Having ourselves a party, yeh?",
|
||||
"Why, hello there.",
|
||||
"!!!",
|
||||
"!?! That's an interrabang."
|
||||
];
|
||||
|
||||
logo.addEventListener("mouseenter", (event) => {
|
||||
const randomItem = Math.floor(Math.random() * logoQuotes.length)
|
||||
event.target.dataset.tooltip = logoQuotes[randomItem];
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
var codeListings = document.querySelectorAll("main .listingblock > .content")
|
||||
|
||||
for (elem of codeListings) {
|
||||
var parent = elem.parentElement;
|
||||
|
||||
var fullscreenButton = document.createElement("button");
|
||||
fullscreenButton.classList.add("listingblock__fullscreen-btn");
|
||||
fullscreenButton.ariaLabel = "{{ T "fullscreenButtonAriaLabel" }}";
|
||||
fullscreenButton.title = "{{ T "fullscreenButtonLabel" }}";
|
||||
fullscreenButton.ariaDescription = "{{ T "fullscreenButtonDescription" }}";
|
||||
fullscreenButton.innerHTML = "{{ partial "components/heroicon.html" "arrows-pointing-out" }}";
|
||||
|
||||
fullscreenButton.addEventListener("click", (event) => {
|
||||
const { target } = event;
|
||||
const parent = target.closest(".listingblock");
|
||||
if (!document.fullscreenElement) {
|
||||
parent.requestFullscreen();
|
||||
} else if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
});
|
||||
|
||||
var copyButton = document.createElement("button");
|
||||
copyButton.classList.add("listingblock__copy-btn");
|
||||
copyButton.ariaLabel = "{{ T "copyButtonAriaLabel" }}";
|
||||
copyButton.title = "{{ T "copyButtonLabel" }}";
|
||||
copyButton.ariaDescription = "{{ T "copyButtonDescription" }}";
|
||||
copyButton.innerHTML = "{{ partial "components/heroicon.html" "clipboard" }}";
|
||||
|
||||
copyButton.addEventListener("click", (event) => {
|
||||
const { target } = event;
|
||||
const parent = target.closest(".listingblock");
|
||||
const codeListing = parent.querySelector(".content");
|
||||
navigator.clipboard.writeText(codeListing.textContent.trim());
|
||||
})
|
||||
|
||||
var buttonRow = document.createElement("div");
|
||||
buttonRow.classList.add("listingblock__btn-row");
|
||||
buttonRow.appendChild(copyButton);
|
||||
buttonRow.appendChild(fullscreenButton);
|
||||
parent.appendChild(buttonRow);
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user