refactor: cleanup and restructure gulp tasks (#101)

This commit is contained in:
Robert Kaussow 2021-05-05 22:44:36 +02:00 committed by GitHub
parent 6e705f7fcd
commit c05cd36f57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 1878 additions and 975 deletions

51
src/js/darkmode.js Normal file
View file

@ -0,0 +1,51 @@
const DARK_MODE = "dark";
const LIGHT_MODE = "light";
const AUTO_MODE = "auto";
const THEME = "hugo-geekdoc";
const TOGGLE_MODES = [AUTO_MODE, DARK_MODE, LIGHT_MODE];
(applyTheme = function (init = true) {
let html = document.documentElement;
let currentMode = TOGGLE_MODES.includes(localStorage.getItem(THEME))
? localStorage.getItem(THEME)
: AUTO_MODE;
html.setAttribute("class", "color-toggle-" + currentMode);
localStorage.setItem(THEME, currentMode);
if (currentMode === AUTO_MODE) {
html.removeAttribute("color-mode");
} else {
html.setAttribute("color-mode", currentMode);
}
if (!init) {
// Reload required to re-initialise e.g. Mermaid with the new theme and re-parse the Mermaid code blocks.
location.reload();
}
})();
document.addEventListener("DOMContentLoaded", (event) => {
const darkModeToggle = document.getElementById("gdoc-dark-mode");
darkModeToggle.onclick = function () {
let currentMode = localStorage.getItem(THEME);
let nextMode = toggle(TOGGLE_MODES, currentMode);
localStorage.setItem(THEME, TOGGLE_MODES[nextMode]);
applyTheme(false);
};
});
function toggle(list = [], value) {
current = list.indexOf(value);
max = list.length - 1;
next = 0;
if (current < max) {
next = current + 1;
}
return next;
}

36
src/js/groupBy.js Normal file
View file

@ -0,0 +1,36 @@
/**
* Part of [Canivete](http://canivete.leofavre.com/#deepgroupby)
*
* Groups the contents of an array by one or more iteratees.
* Unlike Lodash [`groupBy()`](https://lodash.com/docs/4.17.4#groupBy),
* this function can create nested groups, but cannot receive
* strings for iteratees.
*/
const groupBy = (e, ...t) => {
let r = e.map((e) => t.map((t) => t(e))),
a = {};
return (
r.forEach((t, r) => {
let l = (_simpleAt(a, t) || []).concat([e[r]]);
_simpleSet(a, t, l);
}),
a
);
},
_isPlainObject = (e) =>
null != e && "object" == typeof e && e.constructor == Object,
_parsePath = (e) => (Array.isArray(e) ? e : `${e}`.split(".")),
_simpleAt = (e, t) =>
_parsePath(t).reduce(
(e, t) => (null != e && e.hasOwnProperty(t) ? e[t] : void 0),
e
),
_simpleSet = (e, t, r) =>
_parsePath(t).reduce((e, t, a, l) => {
let s = a === l.length - 1;
return (
(e.hasOwnProperty(t) && (s || _isPlainObject(e[t]))) || (e[t] = {}),
s ? (e[t] = r) : e[t]
);
}, e);