diff --git a/assets/js/src/anchor.js b/assets/js/src/anchor.js
index 72b3aee0..06d33ffc 100644
--- a/assets/js/src/anchor.js
+++ b/assets/js/src/anchor.js
@@ -1,7 +1,7 @@
import SimpleAnchor from "simple-anchor";
const anchors = new SimpleAnchor({
- icon: "",
+ icon: null,
});
anchors.add("div#content h2, div#content h3, div#content h4");
diff --git a/assets/js/src/clipboard.js b/assets/js/src/clipboard.js
index 56f8ea9a..d6801851 100644
--- a/assets/js/src/clipboard.js
+++ b/assets/js/src/clipboard.js
@@ -5,8 +5,8 @@ import trimNewlines from "trim-newlines";
const defaultTerm = "Copy";
const successTerm = "Copied!";
-// immediately give up if not supported
-if (ClipboardJS.isSupported()) {
+// immediately give up if not supported or if there are no code blocks
+if (ClipboardJS.isSupported() && document.querySelector("div.highlight")) {
// loop through each code fence on page (if any)
document.querySelectorAll("div.highlight").forEach((highlightDiv) => {
const wrapperDiv = document.createElement("div");
@@ -22,10 +22,10 @@ if (ClipboardJS.isSupported()) {
wrapperDiv.insertBefore(button, wrapperDiv.firstChild);
});
+ // now that all the buttons are in place, bind them to the copy action
new ClipboardJS("button.copy-button", {
- // actual code element will (should) have class "language-*", even if plaintext
text: (trigger) =>
- // eslint-disable-next-line quotes
+ // actual code element will have class "language-*", even if plaintext
trimNewlines(trigger.parentElement.querySelector('code[class^="language-"]').innerText),
}).on("success", (e) => {
// show a subtle indication of success
diff --git a/assets/js/src/counter.js b/assets/js/src/counter.js
index 1835fec8..c739d872 100644
--- a/assets/js/src/counter.js
+++ b/assets/js/src/counter.js
@@ -8,18 +8,18 @@ const HITS_ENDPOINT = "/api/hits/";
// don't continue if there isn't a span#meta-hits element on this page
const wrapper = document.getElementById("meta-hits");
-// use to deduce a consistent identifier for this page
-const canonical = canonicalUrl({
- normalize: true,
- normalizeOptions: {
- removeTrailingSlash: true,
- removeQueryParameters: true,
- stripHash: true,
- },
-});
-
// page must have both span#meta-hits and canonical URL to enter
-if (wrapper && canonical) {
+if (wrapper) {
+ // use to deduce a consistent identifier for this page
+ const canonical = canonicalUrl({
+ normalize: true,
+ normalizeOptions: {
+ removeTrailingSlash: true,
+ removeQueryParameters: true,
+ stripHash: true,
+ },
+ });
+
// javascript is enabled so show the loading indicator
wrapper.style.display = "inline-flex";
diff --git a/assets/js/src/dark-mode.js b/assets/js/src/dark-mode.js
index fe0c7f8a..c794df4b 100644
--- a/assets/js/src/dark-mode.js
+++ b/assets/js/src/dark-mode.js
@@ -17,7 +17,8 @@ initDarkMode({
// make toggle visible now that we know JS is enabled
t.style.display = "block";
- // HACK: re-enable theme transitions after a very short delay, otherwise there's a weird race condition (2/2)
+ // HACK: re-enable theme transitions after a very short delay, otherwise
+ // there's a weird race condition (2/2)
setTimeout(() => {
document.head.removeChild(disableTransitionCSSHack);
}, 500);