Initial commit for Hugo site.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
|
||||
// Get code blocks
|
||||
const codeblocks = document.querySelectorAll("pre code");
|
||||
|
||||
// Iterate over each to perform modifications
|
||||
codeblocks.forEach((codeblock) => {
|
||||
// Create copy button and container element
|
||||
const copyButton = document.createElement("button");
|
||||
copyButton.className = "copy-button";
|
||||
const container = document.createElement("div");
|
||||
container.className = "code-container";
|
||||
|
||||
// Copy clicked closure
|
||||
copyButton.addEventListener("click", (e) => {
|
||||
e.target.className = "copy-success";
|
||||
setTimeout(() => {
|
||||
e.target.className = "copy-button";
|
||||
}, 1000);
|
||||
const code = codeblock.textContent;
|
||||
navigator.clipboard.writeText(code);
|
||||
});
|
||||
|
||||
// Wrap the codeblock with the container
|
||||
codeblock.parentNode.insertBefore(container, codeblock);
|
||||
container.appendChild(codeblock);
|
||||
// Add the copy button to the container
|
||||
container.appendChild(copyButton);
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
|
||||
// provides an escape for dollar sign chars if KaTeX is not desired
|
||||
let posts = document.getElementsByClassName("post");
|
||||
|
||||
for (let i = 0; i < posts.length; i++) {
|
||||
let children = posts[i].children
|
||||
for (let j = 0; j < children.length; j++) {
|
||||
if (children[j].tagName == "P") {
|
||||
children[j].innerHTML = children[j].innerHTML.replace(/\\\$/g, '<span>$</span>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderMathInElement(document.body, {
|
||||
delimiters: [
|
||||
{left: "$$", right: "$$", display: true},
|
||||
{left: "$", right: "$", display: false}
|
||||
]
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,(function(e){return function(){"use strict";var t={771:function(t){t.exports=e}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var i={};return function(){n.d(i,{default:function(){return s}});var e=n(771),t=n.n(e),r=function(e,t,r){for(var n=r,i=0,a=e.length;n<t.length;){var o=t[n];if(i<=0&&t.slice(n,n+a)===e)return n;"\\"===o?n++:"{"===o?i++:"}"===o&&i--,n++}return-1},a=/^\\begin{/,o=function(e,t){for(var n,i=[],o=new RegExp("("+t.map((function(e){return e.left.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")})).join("|")+")");-1!==(n=e.search(o));){n>0&&(i.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));var l=t.findIndex((function(t){return e.startsWith(t.left)}));if(-1===(n=r(t[l].right,e,t[l].left.length)))break;var d=e.slice(0,n+t[l].right.length),s=a.test(d)?d:e.slice(t[l].left.length,n);i.push({type:"math",data:s,rawData:d,display:t[l].display}),e=e.slice(n+t[l].right.length)}return""!==e&&i.push({type:"text",data:e}),i},l=function(e,r){var n=o(e,r.delimiters);if(1===n.length&&"text"===n[0].type)return null;for(var i=document.createDocumentFragment(),a=0;a<n.length;a++)if("text"===n[a].type)i.appendChild(document.createTextNode(n[a].data));else{var l=document.createElement("span"),d=n[a].data;r.displayMode=n[a].display;try{r.preProcess&&(d=r.preProcess(d)),t().render(d,l,r)}catch(e){if(!(e instanceof t().ParseError))throw e;r.errorCallback("KaTeX auto-render: Failed to parse `"+n[a].data+"` with ",e),i.appendChild(document.createTextNode(n[a].rawData));continue}i.appendChild(l)}return i},d=function e(t,r){for(var n=0;n<t.childNodes.length;n++){var i=t.childNodes[n];if(3===i.nodeType){for(var a=i.textContent,o=i.nextSibling,d=0;o&&o.nodeType===Node.TEXT_NODE;)a+=o.textContent,o=o.nextSibling,d++;var s=l(a,r);if(s){for(var f=0;f<d;f++)i.nextSibling.remove();n+=s.childNodes.length-1,t.replaceChild(s,i)}else n+=d}else 1===i.nodeType&&function(){var t=" "+i.className+" ";-1===r.ignoredTags.indexOf(i.nodeName.toLowerCase())&&r.ignoredClasses.every((function(e){return-1===t.indexOf(" "+e+" ")}))&&e(i,r)}()}},s=function(e,t){if(!e)throw new Error("No element provided to render");var r={};for(var n in t)t.hasOwnProperty(n)&&(r[n]=t[n]);r.delimiters=r.delimiters||[{left:"$$",right:"$$",display:!0},{left:"\\(",right:"\\)",display:!1},{left:"\\begin{equation}",right:"\\end{equation}",display:!0},{left:"\\begin{align}",right:"\\end{align}",display:!0},{left:"\\begin{alignat}",right:"\\end{alignat}",display:!0},{left:"\\begin{gather}",right:"\\end{gather}",display:!0},{left:"\\begin{CD}",right:"\\end{CD}",display:!0},{left:"\\[",right:"\\]",display:!0}],r.ignoredTags=r.ignoredTags||["script","noscript","style","textarea","pre","code","option"],r.ignoredClasses=r.ignoredClasses||[],r.errorCallback=r.errorCallback||console.error,r.macros=r.macros||{},d(e,r)}}(),i=i.default}()}));
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,39 @@
|
||||
const btn = document.querySelector(".btn-light-dark");
|
||||
const moon = document.querySelector(".moon");
|
||||
const sun = document.querySelector(".sun");
|
||||
|
||||
const themeFromLS = localStorage.getItem("theme")
|
||||
const themeFromHugo = document.body.classList.contains("dark-theme") ? "dark" : null
|
||||
const currentTheme = themeFromLS ? themeFromLS : themeFromHugo;
|
||||
|
||||
if (currentTheme == "dark") {
|
||||
document.body.classList.add("dark-theme");
|
||||
moon.style.display = 'none';
|
||||
sun.style.display = 'block';
|
||||
} else {
|
||||
document.body.classList.remove("dark-theme");
|
||||
moon.style.display = 'block';
|
||||
sun.style.display = 'none';
|
||||
}
|
||||
|
||||
btn.addEventListener("click", function () {
|
||||
document.body.classList.toggle("dark-theme");
|
||||
let hasComments = document.getElementById("remark42");
|
||||
let theme = "light";
|
||||
|
||||
if (document.body.classList.contains("dark-theme")) {
|
||||
theme = "dark";
|
||||
moon.style.display = 'none';
|
||||
sun.style.display = 'block';
|
||||
if (hasComments) {
|
||||
window.REMARK42.changeTheme("dark");
|
||||
}
|
||||
} else {
|
||||
moon.style.display = 'block';
|
||||
sun.style.display = 'none';
|
||||
if (hasComments) {
|
||||
window.REMARK42.changeTheme("light");
|
||||
}
|
||||
}
|
||||
localStorage.setItem("theme", theme);
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
plantumlElements = document.querySelectorAll('[id^="plantuml-"]');
|
||||
let plantumlInner = ""
|
||||
for (let i = 0; i < plantumlElements.length; i++) {
|
||||
element = plantumlElements[i];
|
||||
if (element.tagName == "SPAN") {
|
||||
plantumlInner = element.innerText;
|
||||
}
|
||||
if (element.tagName == "IMG") {
|
||||
element.src = "//www.plantuml.com/plantuml/img/" + window.plantumlEncoder.encode(plantumlInner);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
const tabs = document.querySelectorAll(".tab")
|
||||
|
||||
tabs.forEach(tab => {
|
||||
tab.addEventListener('click', (e) => {
|
||||
const tablist = tab.parentElement.children
|
||||
for (let i = 0; i < tablist.length; i++) {
|
||||
if (tablist[i].id == e.target.id) {
|
||||
tablist[i].classList.add('active');
|
||||
}
|
||||
else {
|
||||
tablist[i].classList.remove('active');
|
||||
}
|
||||
}
|
||||
const container = tab.parentElement.parentElement.children
|
||||
for (let i = 1; i < container.length; i++) {
|
||||
if (container[i].classList.contains(e.target.id)) {
|
||||
container[i].style.display = "block";
|
||||
}
|
||||
else {
|
||||
container[i].style.display = "none";
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Original Author: Bramus Van Damme
|
||||
Link to original: https://www.bram.us/2020/01/10/smooth-scrolling-sticky-scrollspy-navigation/
|
||||
|
||||
Most of this code comes courtesy of Bramus Van Damme, with some minor tweaks
|
||||
to get it working for my use case. Thanks, Bramus!
|
||||
*/
|
||||
|
||||
let activeElement = null;
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
const observer = new IntersectionObserver(entries => {
|
||||
if (entries) {
|
||||
const contents = document.getElementById("contents");
|
||||
if (contents) {
|
||||
contents.innerHTML = "Contents";
|
||||
}
|
||||
}
|
||||
entries.forEach(entry => {
|
||||
if (activeElement) {
|
||||
document.querySelectorAll("nav[id='TableOfContents'] li").forEach((node) => {
|
||||
node.classList.add('inactive');
|
||||
node.classList.replace('active', 'inactive');
|
||||
});
|
||||
}
|
||||
if (entry.intersectionRatio > 0) {
|
||||
activeElement = entry.target.getAttribute('id');
|
||||
}
|
||||
if (activeElement) {
|
||||
document.querySelector(`nav[id='TableOfContents'] li a[href="#${activeElement}"]`).parentElement.classList.replace('inactive', 'active');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const post = document.querySelector(".post");
|
||||
post.querySelectorAll("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]").forEach((section) => {
|
||||
observer.observe(section);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user