fix: format complex changes

Formats all the general js files. Separate in case these should be
treated differently for any reason. This commit includes all javascript
and HTML files.
This commit is contained in:
FireIsGood committed 2024-05-16 14:37:00 -07:00
1 parent bc3e778e80
commit ef823489fe
15 files changed
+1123 -1115

No files matched your search

+37 -30
View File
@@ -1,37 +1,44 @@
const gulp = require('gulp');
const htmlmin = require('gulp-htmlmin');
const htmlclean = require('gulp-htmlclean');
const version = require('gulp-version-number');
const terser = require('gulp-terser');
const gulp = require("gulp");
const htmlmin = require("gulp-htmlmin");
const htmlclean = require("gulp-htmlclean");
const version = require("gulp-version-number");
const terser = require("gulp-terser");
// Compress js files
gulp.task('js', function () {
return gulp.src(['./public/js/main.js'])
.pipe(terser({
compress: true
}))
.pipe(gulp.dest('./public/js'));
gulp.task("js", function () {
return gulp
.src(["./public/js/main.js"])
.pipe(
terser({
compress: true,
}),
)
.pipe(gulp.dest("./public/js"));
});
// Build html files
gulp.task('html', function () {
return gulp.src('./public/**/*.html')
.pipe(htmlclean())
.pipe(htmlmin({
removeComments: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
}))
.pipe(version({
'append': {
'key': '_v',
'cover': 1,
'to': ['css', 'js', 'png', 'jpg', 'woff2']
}
}))
.pipe(gulp.dest('./public'));
gulp.task("html", function () {
return gulp
.src("./public/**/*.html")
.pipe(htmlclean())
.pipe(
htmlmin({
removeComments: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
}),
)
.pipe(
version({
append: {
key: "_v",
cover: 1,
to: ["css", "js", "png", "jpg", "woff2"],
},
}),
)
.pipe(gulp.dest("./public"));
});
gulp.task('default', gulp.parallel('js', 'html'));
gulp.task("default", gulp.parallel("js", "html"));
+7 -7
View File
@@ -1,8 +1,8 @@
module.exports = {
plugins: {
'postcss-import': {path: 'themes/coo/source/css'},
'tailwindcss': {config: './tailwind.config.js'},
'autoprefixer': {},
'postcss-minify':{},
}
};
plugins: {
"postcss-import": { path: "themes/coo/source/css" },
tailwindcss: { config: "./tailwind.config.js" },
autoprefixer: {},
"postcss-minify": {},
},
};
+144 -144
View File
@@ -1,171 +1,171 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>404 Page NotFound</title>
<link href="https://fonts.googleapis.com/css?family=Quicksand:700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Quicksand:700" rel="stylesheet" />
<style>
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
}
body {
padding: 0;
margin: 0;
}
#notfound {
position: relative;
height: 100vh;
background-color: #fafbfd;
}
#notfound {
position: relative;
height: 100vh;
background-color: #fafbfd;
}
#notfound .notfound {
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
#notfound .notfound {
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.notfound {
max-width: 520px;
width: 100%;
text-align: center;
}
.notfound {
max-width: 520px;
width: 100%;
text-align: center;
}
.notfound .notfound-bg {
position: absolute;
left: 0px;
right: 0px;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
z-index: -1;
}
.notfound .notfound-bg > div {
width: 100%;
background: #fff;
border-radius: 90px;
height: 125px;
}
.notfound .notfound-bg > div:nth-child(1) {
-webkit-box-shadow: 5px 5px 0px 0px #f3f3f3;
box-shadow: 5px 5px 0px 0px #f3f3f3;
}
.notfound .notfound-bg > div:nth-child(2) {
-webkit-transform: scale(1.3);
-ms-transform: scale(1.3);
transform: scale(1.3);
-webkit-box-shadow: 5px 5px 0px 0px #f3f3f3;
box-shadow: 5px 5px 0px 0px #f3f3f3;
position: relative;
z-index: 10;
}
.notfound .notfound-bg > div:nth-child(3) {
-webkit-box-shadow: 5px 5px 0px 0px #f3f3f3;
box-shadow: 5px 5px 0px 0px #f3f3f3;
position: relative;
z-index: 90;
}
.notfound h1 {
font-family: "Quicksand", sans-serif;
font-size: 86px;
text-transform: uppercase;
font-weight: 700;
margin-top: 0;
margin-bottom: 8px;
color: #4d4d4d;
}
.notfound h2 {
font-family: "Quicksand", sans-serif;
font-size: 26px;
margin: 0;
font-weight: 700;
color: #4d4d4d;
}
.notfound a {
font-family: "Quicksand", sans-serif;
font-size: 14px;
text-decoration: none;
text-transform: uppercase;
background: #23b883;
display: inline-block;
padding: 15px 30px;
border-radius: 5px;
color: #fff;
font-weight: 700;
margin-top: 20px;
}
.notfound-social {
margin-top: 20px;
}
.notfound-social > a {
display: inline-block;
height: 40px;
line-height: 40px;
width: 40px;
font-size: 14px;
color: #fff;
background-color: #dedede;
margin: 3px;
padding: 0px;
-webkit-transition: 0.2s all;
transition: 0.2s all;
}
.notfound-social > a:hover {
background-color: #18e06f;
}
@media only screen and (max-width: 767px) {
.notfound .notfound-bg {
position: absolute;
left: 0px;
right: 0px;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
z-index: -1;
width: 287px;
margin: auto;
}
.notfound .notfound-bg > div {
width: 100%;
background: #fff;
border-radius: 90px;
height: 125px;
}
.notfound .notfound-bg > div:nth-child(1) {
-webkit-box-shadow: 5px 5px 0px 0px #f3f3f3;
box-shadow: 5px 5px 0px 0px #f3f3f3;
}
.notfound .notfound-bg > div:nth-child(2) {
-webkit-transform: scale(1.3);
-ms-transform: scale(1.3);
transform: scale(1.3);
-webkit-box-shadow: 5px 5px 0px 0px #f3f3f3;
box-shadow: 5px 5px 0px 0px #f3f3f3;
position: relative;
z-index: 10;
}
.notfound .notfound-bg > div:nth-child(3) {
-webkit-box-shadow: 5px 5px 0px 0px #f3f3f3;
box-shadow: 5px 5px 0px 0px #f3f3f3;
position: relative;
z-index: 90;
height: 85px;
}
}
@media only screen and (max-width: 480px) {
.notfound h1 {
font-family: 'Quicksand', sans-serif;
font-size: 86px;
text-transform: uppercase;
font-weight: 700;
margin-top: 0;
margin-bottom: 8px;
color: #4d4d4d;
font-size: 68px;
}
.notfound h2 {
font-family: 'Quicksand', sans-serif;
font-size: 26px;
margin: 0;
font-weight: 700;
color: #4d4d4d;
}
.notfound a {
font-family: 'Quicksand', sans-serif;
font-size: 14px;
text-decoration: none;
text-transform: uppercase;
background: #23b883;
display: inline-block;
padding: 15px 30px;
border-radius: 5px;
color: #fff;
font-weight: 700;
margin-top: 20px;
}
.notfound-social {
margin-top: 20px;
}
.notfound-social > a {
display: inline-block;
height: 40px;
line-height: 40px;
width: 40px;
font-size: 14px;
color: #fff;
background-color: #dedede;
margin: 3px;
padding: 0px;
-webkit-transition: 0.2s all;
transition: 0.2s all;
}
.notfound-social > a:hover {
background-color: #18e06f;
}
@media only screen and (max-width: 767px) {
.notfound .notfound-bg {
width: 287px;
margin: auto;
}
.notfound .notfound-bg > div {
height: 85px;
}
}
@media only screen and (max-width: 480px) {
.notfound h1 {
font-size: 68px;
}
.notfound h2 {
font-size: 18px;
}
font-size: 18px;
}
}
</style>
</head>
<body>
<div id="notfound">
<div class="notfound">
</head>
<body>
<div id="notfound">
<div class="notfound">
<div class="notfound-bg">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<h1>oops!</h1>
<h2>Error 404 : Page Not Found</h2>
<a href="https://cheatsheets.zip">go back</a>
</div>
</div>
</div>
</body>
</body>
</html>
+99 -96
View File
@@ -1,95 +1,102 @@
<div class="flex items-center justify-center mt-8 mb-3">
<div class="w-1/3 px-2">
<p class="font-medium text-right">Permissions: </p>
</div>
<div class="w-1/3 px-2">
<input class="appearance-none block w-full bg-grey-lighter dark:bg-slate-800 text-grey-darker border border-red rounded py-2 px-3 focus:outline-none focus:border-emerald-500" id="num" placeholder="777" maxlength="3" type="text">
</div>
<div class="w-1/3 px-2 ">
<input class="appearance-none block w-full bg-grey-lighter dark-bg-slate-800 text-grey-darker border border-grey-lighter rounded py-2 px-3 focus:outline-none focus:border-emerald-500" id="let" placeholder="rwxrwxrwx" maxlength="9" type="text">
</div>
<div class="mb-3 mt-8 flex items-center justify-center">
<div class="w-1/3 px-2">
<p class="text-right font-medium">Permissions:</p>
</div>
<div class="w-1/3 px-2">
<input
class="bg-grey-lighter text-grey-darker border-red block w-full appearance-none rounded border px-3 py-2 focus:border-emerald-500 focus:outline-none dark:bg-slate-800"
id="num"
placeholder="777"
maxlength="3"
type="text"
/>
</div>
<div class="w-1/3 px-2">
<input
class="bg-grey-lighter dark-bg-slate-800 text-grey-darker border-grey-lighter block w-full appearance-none rounded border px-3 py-2 focus:border-emerald-500 focus:outline-none"
id="let"
placeholder="rwxrwxrwx"
maxlength="9"
type="text"
/>
</div>
</div>
<table class="show-header center-text">
<thead>
<thead>
<tr>
<th></th>
<th>User</th>
<th>Group</th>
<th>Other</th>
<th></th>
<th>User</th>
<th>Group</th>
<th>Other</th>
</tr>
</thead>
<tbody>
</thead>
<tbody>
<tr>
<td style="text-align: right">Read</td>
<td><input checked="" id="1" type="checkbox"></td>
<td><input checked="" id="4" type="checkbox"></td>
<td><input checked="" id="7" type="checkbox"></td>
<td style="text-align: right">Read</td>
<td><input checked="" id="1" type="checkbox" /></td>
<td><input checked="" id="4" type="checkbox" /></td>
<td><input checked="" id="7" type="checkbox" /></td>
</tr>
<tr>
<td style="text-align: right">Write</td>
<td><input checked="" id="2" type="checkbox"></td>
<td><input checked="" id="5" type="checkbox"></td>
<td><input checked="" id="8" type="checkbox"></td>
<td style="text-align: right">Write</td>
<td><input checked="" id="2" type="checkbox" /></td>
<td><input checked="" id="5" type="checkbox" /></td>
<td><input checked="" id="8" type="checkbox" /></td>
</tr>
<tr>
<td style="text-align: right">Execute</td>
<td><input checked="" id="3" type="checkbox"></td>
<td><input checked="" id="6" type="checkbox"></td>
<td><input checked="" id="9" type="checkbox"></td>
<td style="text-align: right">Execute</td>
<td><input checked="" id="3" type="checkbox" /></td>
<td><input checked="" id="6" type="checkbox" /></td>
<td><input checked="" id="9" type="checkbox" /></td>
</tr>
</tbody>
</tbody>
</table>
<script>
const reg_num = /^[0-7]{3}$/; // some regex to check the num input
const reg_let = /^([r\-]{1}[w\-]{1}[x\-]{1}){3}$/; // some regex to check the text input
window.addEventListener("DOMContentLoaded", function () {
// loop over all the check boxes
for (let i = 1; i < 10; i++) {
let checkBox = document.getElementById(`${i}`);
checkBox.addEventListener('change', function () {
checkBox.addEventListener("change", function () {
change_occured(true, false, false);
// get rid of bad input classes
document.getElementById('num').classList.remove('bad-input');
document.getElementById("num").classList.remove("bad-input");
document.getElementById('let').classList.remove('bad-input');
document.getElementById("let").classList.remove("bad-input");
});
}
// the octal input
let num_input = document.getElementById('num');
let num_input = document.getElementById("num");
let num_fn = function () {
// check for bad input
if (!reg_num.test(this.value)) {
this.classList.add('bad-input');
this.classList.add("bad-input");
} else {
this.classList.remove('bad-input');
this.classList.remove("bad-input");
change_occured(false, true, false);
}
};
num_input.addEventListener('change', num_fn);
num_input.addEventListener('keyup', num_fn);
num_input.addEventListener("change", num_fn);
num_input.addEventListener("keyup", num_fn);
// the let input
let let_input = document.getElementById('let');
let let_input = document.getElementById("let");
let let_fn = function () {
// check for bad input
if (!reg_let.test(this.value)) {
this.classList.add('bad-input');
this.classList.add("bad-input");
} else {
this.classList.remove('bad-input');
this.classList.remove("bad-input");
change_occured(false, false, true);
}
};
let_input.addEventListener('change',let_fn);
let_input.addEventListener('keyup',let_fn);
let_input.addEventListener("change", let_fn);
let_input.addEventListener("keyup", let_fn);
});
/* SETUP
@@ -98,18 +105,20 @@
x-1-3 x-1-6 x-1-9
*/
// define a function that runs when a change occures
function change_occured(caller_was_check, caller_was_num, caller_was_let) {
let num1 = 0, num2 = 0, num3 = 0; // these are the three numbers for the octal
let perm_string = ''; // holds the permision string ex. rw-x--r--
let num1 = 0,
num2 = 0,
num3 = 0; // these are the three numbers for the octal
let perm_string = ""; // holds the permision string ex. rw-x--r--
if (caller_was_check) {
// loop over all the check boxes and get the permisions
for (let i = 1; i < 10; i++) {
let checkBox = document.getElementById(`${i}`);
if (checkBox.checked) { // if checked
if (checkBox.checked) {
// if checked
let current_perm = check_to_octal_and_text(i);
perm_string += `${current_perm.perm_let}`;
@@ -120,19 +129,18 @@
} else {
num3 += current_perm.perm_num;
}
} else { // if not checked
perm_string += '-';
} else {
// if not checked
perm_string += "-";
}
}
// set the permision input text
document.getElementById('let').value = perm_string;
document.getElementById('num').value = `${num1}${num2}${num3}`;
document.getElementById("let").value = perm_string;
document.getElementById("num").value = `${num1}${num2}${num3}`;
} else if (caller_was_num) {
// get the individual numbers
let num_input_val = document.getElementById('num').value;
let num_input_val = document.getElementById("num").value;
num1 = num_input_val.substring(0, 1);
num2 = num_input_val.substring(1, 2);
num3 = num_input_val.substring(2, 3);
@@ -143,63 +151,59 @@
perm_string += octal_to_check_and_txt(num3, 2); //Owner
// set the permision input text
document.getElementById('let').value = perm_string;
document.getElementById("let").value = perm_string;
} else if (caller_was_let) {
// get the text input
let perm_text = document.getElementById('let').value;
let perm_text = document.getElementById("let").value;
num1 = text_to_check_and_octal(perm_text.substring(0, 3), 0)
num2 = text_to_check_and_octal(perm_text.substring(3, 6), 3)
num3 = text_to_check_and_octal(perm_text.substring(6, 9), 6)
num1 = text_to_check_and_octal(perm_text.substring(0, 3), 0);
num2 = text_to_check_and_octal(perm_text.substring(3, 6), 3);
num3 = text_to_check_and_octal(perm_text.substring(6, 9), 6);
// set the octal value
document.getElementById('num').value = `${num1}${num2}${num3}`;
document.getElementById("num").value = `${num1}${num2}${num3}`;
}
}
// define a function to converts the checkbox # to the respective permissions
// returns perm_num, perm_let
function check_to_octal_and_text(check_num) {
let perm_num = 0;
let perm_let = '-';
let perm_let = "-";
switch (check_num) {
case 1:
case 4:
case 7:
perm_num = 4;
perm_let = 'r';
perm_let = "r";
break;
case 2:
case 5:
case 8:
perm_num = 2;
perm_let = 'w';
perm_let = "w";
break;
case 3:
case 6:
case 9:
perm_num = 1;
perm_let = 'x';
perm_let = "x";
break;
default:
perm_num = 0;
perm_let = '-';
perm_let = "-";
}
// return values
return {
perm_num,
perm_let
perm_let,
};
}
/**
Takes a number 1-7 and which class it is in:
0 = owner
@@ -209,69 +213,68 @@
Returns: perm text (ex. "rwx") and sets the appropriate checkboxes
*/
function octal_to_check_and_txt(octal_num, class_num) {
let perm_text = '';
let perm_text = "";
let offset = class_num * 3;
switch (octal_num) {
case '1':
case "1":
document.getElementById(`${1 + offset}`).checked = false;
document.getElementById(`${2 + offset}`).checked = false;
document.getElementById(`${3 + offset}`).checked = true;
perm_text = '--x';
perm_text = "--x";
break;
case '2':
case "2":
document.getElementById(`${1 + offset}`).checked = false;
document.getElementById(`${2 + offset}`).checked = true;
document.getElementById(`${3 + offset}`).checked = false;
perm_text = '-w-';
perm_text = "-w-";
break;
case '3':
case "3":
document.getElementById(`${1 + offset}`).checked = false;
document.getElementById(`${2 + offset}`).checked = true;
document.getElementById(`${3 + offset}`).checked = true;
perm_text = '-wx';
perm_text = "-wx";
break;
case '4':
case "4":
document.getElementById(`${1 + offset}`).checked = true;
document.getElementById(`${2 + offset}`).checked = false;
document.getElementById(`${3 + offset}`).checked = false;
perm_text = 'r--';
perm_text = "r--";
break;
case '5':
case "5":
document.getElementById(`${1 + offset}`).checked = true;
document.getElementById(`${2 + offset}`).checked = false;
document.getElementById(`${3 + offset}`).checked = true;
perm_text = 'r-x';
perm_text = "r-x";
break;
case '6':
case "6":
document.getElementById(`${1 + offset}`).checked = true;
document.getElementById(`${2 + offset}`).checked = true;
document.getElementById(`${3 + offset}`).checked = false;
perm_text = 'rw-';
perm_text = "rw-";
break;
case '7':
case "7":
document.getElementById(`${1 + offset}`).checked = true;
document.getElementById(`${2 + offset}`).checked = true;
document.getElementById(`${3 + offset}`).checked = true;
perm_text = 'rwx';
perm_text = "rwx";
break;
default:
document.getElementById(`${1 + offset}`).checked = false;
document.getElementById(`${2 + offset}`).checked = false;
document.getElementById(`${3 + offset}`).checked = false;
perm_text = '---';
perm_text = "---";
}
return perm_text;
}
/**
Takes 3 letters (r, w, x, - ex. 'rw-') and an offset (0,3,6)
Returns the octal num and sets the appropriate checkboxes
@@ -282,13 +285,13 @@
// add up the oct num and set the check boxes
for (let i = 0; i < 3; i++) {
current_let = letters.substring(i, i + 1);
if (current_let == 'r') {
if (current_let == "r") {
document.getElementById(`${i + 1 + offset}`).checked = true;
perm_num += 4;
} else if (current_let == 'w') {
} else if (current_let == "w") {
document.getElementById(`${i + 1 + offset}`).checked = true;
perm_num += 2;
} else if (current_let == 'x') {
} else if (current_let == "x") {
document.getElementById(`${i + 1 + offset}`).checked = true;
perm_num += 1;
} else {
@@ -297,4 +300,4 @@
}
return perm_num;
}
</script>
</script>
+22 -22
View File
@@ -1,26 +1,26 @@
module.exports = {
darkMode: 'class', // or 'media' or 'class'
plugins: [
// https://github.com/jamiebuilds/tailwindcss-animate
require("tailwindcss-animate"),
],
theme: {
boxShadow: {
/* Customized */
DEFAULT: '0 6px 8px rgba(102, 119, 136, 0.03), 0 1px 2px rgba(102, 119, 136, 0.3)',
md: '0 4px 6px -1px rgba(102, 119, 136, 0.05), 0 2px 4px -1px rgba(102, 119, 136, 0.35)',
darkMode: "class", // or 'media' or 'class'
plugins: [
// https://github.com/jamiebuilds/tailwindcss-animate
require("tailwindcss-animate"),
],
theme: {
boxShadow: {
/* Customized */
DEFAULT: "0 6px 8px rgba(102, 119, 136, 0.03), 0 1px 2px rgba(102, 119, 136, 0.3)",
md: "0 4px 6px -1px rgba(102, 119, 136, 0.05), 0 2px 4px -1px rgba(102, 119, 136, 0.35)",
/* Default */
sm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
'2xl': '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
'3xl': '0 35px 60px -15px rgba(0, 0, 0, 0.3)',
inner: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',
none: 'none',
}
/* Default */
sm: "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
lg: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",
xl: "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",
"2xl": "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
"3xl": "0 35px 60px -15px rgba(0, 0, 0, 0.3)",
inner: "inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)",
none: "none",
},
content: {
files: ['**/*.{ejs,md}', '**/widget/*.html', '**/js/main.js'],
}
},
content: {
files: ["**/*.{ejs,md}", "**/widget/*.html", "**/js/main.js"],
},
};
+41 -42
View File
@@ -1,51 +1,50 @@
const h2_re = /<h2 id=".*"><a class="h-anchor" href="(#.*)">#<\/a>(.*)<\/h2>/gm;
const h3_re = /<h3 id=".*"><a class="h-anchor" href="(#.*)">#<\/a>(.*)<\/h3>/gm;
hexo.extend.filter.register("after_post_render", function (data) {
let h2_m;
let h2_list = [];
while ((h2_m = h2_re.exec(data.content)) !== null) {
h2_list.push({
anchor: h2_m[1].trim(),
title: h2_m[2].trim(),
start: h2_m.index
})
}
let h2_m;
let h2_list = [];
while ((h2_m = h2_re.exec(data.content)) !== null) {
h2_list.push({
anchor: h2_m[1].trim(),
title: h2_m[2].trim(),
start: h2_m.index,
});
}
let h3_list = [];
for (let i = 0; i < h2_list.length; i++) {
let start = h2_list[i].start;
let end = data.content.length;
let next = h2_list[i + 1];
if (next !== undefined) {
end = next.start;
}
const h2_section = data.content.substring(start, end);
let h3_m;
let h3_items = [];
while ((h3_m = h3_re.exec(h2_section)) !== null) {
h3_items.push({
anchor: h3_m[1].trim(),
title: h3_m[2].trim()
});
}
h2_list[i] = h2_list[i];
h3_list.push(h3_items);
let h3_list = [];
for (let i = 0; i < h2_list.length; i++) {
let start = h2_list[i].start;
let end = data.content.length;
let next = h2_list[i + 1];
if (next !== undefined) {
end = next.start;
}
let cards = []
for (let i = 0; i < h2_list.length; i++) {
if (h3_list[i].length === 0) {
continue;
}
delete h2_list[i]['start'];
cards.push({
h2: h2_list[i],
h3: h3_list[i]
});
const h2_section = data.content.substring(start, end);
let h3_m;
let h3_items = [];
while ((h3_m = h3_re.exec(h2_section)) !== null) {
h3_items.push({
anchor: h3_m[1].trim(),
title: h3_m[2].trim(),
});
}
h2_list[i] = h2_list[i];
h3_list.push(h3_items);
}
data.sections = cards;
return data;
let cards = [];
for (let i = 0; i < h2_list.length; i++) {
if (h3_list[i].length === 0) {
continue;
}
delete h2_list[i]["start"];
cards.push({
h2: h2_list[i],
h3: h3_list[i],
});
}
data.sections = cards;
return data;
});
+9 -10
View File
@@ -1,17 +1,16 @@
hexo.extend.helper.register("request_cheatsheet", function () {
return `https://github.com/Fechin/reference/issues/new?title=Cheatsheet+request%3A+&labels=request&template=cheatsheet-request.md&assignee=Fechin`;
return `https://github.com/Fechin/reference/issues/new?title=Cheatsheet+request%3A+&labels=request&template=cheatsheet-request.md&assignee=Fechin`;
});
hexo.extend.helper.register("contributing", function () {
return `https://github.com/Fechin/reference`;
return `https://github.com/Fechin/reference`;
});
hexo.extend.helper.register("edit_page", function () {
let postPage = this.page['layout'] === 'post';
let url = "https://github.com/Fechin/reference";
if (postPage) {
url += `/blob/main/source/_posts/${this.page.slug}.md`;
}
return url;
});
let postPage = this.page["layout"] === "post";
let url = "https://github.com/Fechin/reference";
if (postPage) {
url += `/blob/main/source/_posts/${this.page.slug}.md`;
}
return url;
});
+66 -64
View File
@@ -1,82 +1,84 @@
const fs = require('fs');
const path = require('path');
const fs = require("fs");
const path = require("path");
hexo.extend.helper.register("icon", (name) => svgIcon(name));
hexo.extend.generator.register('json', function (locals) {
hexo.extend.generator.register("json", function (locals) {
let searchName = "search.json";
let datas = locals.posts.sort("date") || [];
let searchName = "search.json";
let datas = locals.posts.sort('date') || [];
let res = [];
let index = 0;
let res = []
let index = 0
datas.each(function (data) {
if (data.indexing !== undefined && !data.indexing) return;
if (data.layout === "note") return;
let temp_data = {};
datas.each(function (data) {
if (data.indexing !== undefined && !data.indexing) return;
if (data.layout === "note") return;
let temp_data = {}
temp_data.index = index;
temp_data.title = data.title;
temp_data.path = data.permalink.replace(hexo.config.url, "");
temp_data.icon = svgIcon(data.slug);
temp_data.background = data.background;
temp_data.intro = data.intro;
temp_data.index = index;
temp_data.title = data.title;
temp_data.path = data.permalink.replace(hexo.config.url, "");
temp_data.icon = svgIcon(data.slug);
temp_data.background = data.background;
temp_data.intro = data.intro;
// categories
temp_data.categories = [];
if (data.categories && data.categories.length > 0) {
data.categories.forEach(function (category) {
temp_data.categories.push(category.name);
});
}
// categories
temp_data.categories = [];
if (data.categories && data.categories.length > 0) {
data.categories.forEach(function (category) {
temp_data.categories.push(category.name);
});
}
// tags
temp_data.tags = [];
if (data.tags && data.tags.length > 0) {
data.tags.forEach(function (tag) {
temp_data.tags.push(tag.name);
});
}
// sections
temp_data.sections = data.sections;
// tags
temp_data.tags = [];
if (data.tags && data.tags.length > 0) {
data.tags.forEach(function (tag) {
temp_data.tags.push(tag.name);
});
}
// sections
temp_data.sections = data.sections;
res[index] = temp_data;
index += 1;
});
res[index] = temp_data;
index += 1;
});
let json = JSON.stringify(res);
return {path: searchName, data: json};
let json = JSON.stringify(res);
return { path: searchName, data: json };
});
hexo.extend.generator.register("list", function (locals) {
const themeConfig = hexo.theme.config;
let content = "";
hexo.extend.generator.register('list', function (locals) {
const themeConfig = hexo.theme.config;
let content = "";
themeConfig.index_categories.forEach(function (category) {
content += `<details>\n<summary>${category}</summary>\n\n`;
locals.categories
.findOne({ name: category })
.posts.sort("-date")
.map(function (post) {
content += `- [${post.title}](https://cheatsheets.zip/${post.path}): ${post.intro.trim()}\n`;
});
content += `\n</details>\n\n`;
});
themeConfig.index_categories.forEach(function (category) {
content += `<details>\n<summary>${category}</summary>\n\n`;
locals.categories.findOne({name: category}).posts.sort('-date').map(function (post) {
content += `- [${post.title}](https://cheatsheets.zip/${post.path}): ${post.intro.trim()}\n`;
})
content += `\n</details>\n\n`;
});
return {
path: 'list.md',
data: content
};
return {
path: "list.md",
data: content,
};
});
function svgIcon(name) {
// Check file exists
let svgPath = path.resolve("./", "source/assets/icon/", `${name}.svg`);
if (fs.existsSync(svgPath)) {
return fs.readFileSync(svgPath, 'utf8')
} else {
return "<svg viewBox=\"0 0 1024 1024\" xmlns=\"http://www.w3.org/2000/svg\" fill=\"currentColor\" height=\"1em\" width=\"1em\">\n" +
" <path d=\"M886.25058594 98.67324219L137.8385 98.67324219c-39.31382813 0-71.47256836 29.21941406-71.47256836 68.59713867l0 687.8025c0 39.37675781 32.15786133 71.60036133 71.47256836 71.60036133l754.3764 0c39.31382813 0 68.51162109-32.22360352 68.51162109-71.60036133L960.72652109 167.2703C960.72558594 127.89256836 925.56529297 98.67324219 886.25058594 98.67324219zM354.49103516 200.47132812c60.54662109 0 109.63617188 49.04727539 109.63617187 109.5516211 0 60.50425781-49.08867187 109.55162109-109.63617187 109.55162109s-109.63617188-49.04727539-109.63617188-109.55162109C244.85477539 249.51772461 293.94353516 200.47132812 354.49103516 200.47132812zM167.03632813 839.84574219c-8.22058594 0-16.50506836-2.83227539-23.23441407-8.62646485-14.99308594-12.86279297-16.73912109-35.45727539-3.87632812-50.47286132l164.34720703-247.7241211c12.20396484-14.26860352 33.32970703-16.65448242 48.42896484-5.47286133l145.00977539 107.69668946 259.82191407-295.15227539c12.30925781-15.44036133 77.58448242-88.16853516 115.79036132-5.68529297 0.04227539-0.12779297 0.08551758 109.06110352 0.12779297 220.54948242 0.04227539 116.28272461 0.06389648 284.78162109 0.06389649 284.78162109C872.72808594 839.54603516 167.37646484 839.84574219 167.03632813 839.84574219z\"></path>\n" +
"</svg>";
}
// Check file exists
let svgPath = path.resolve("./", "source/assets/icon/", `${name}.svg`);
if (fs.existsSync(svgPath)) {
return fs.readFileSync(svgPath, "utf8");
} else {
return (
'<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">\n' +
' <path d="M886.25058594 98.67324219L137.8385 98.67324219c-39.31382813 0-71.47256836 29.21941406-71.47256836 68.59713867l0 687.8025c0 39.37675781 32.15786133 71.60036133 71.47256836 71.60036133l754.3764 0c39.31382813 0 68.51162109-32.22360352 68.51162109-71.60036133L960.72652109 167.2703C960.72558594 127.89256836 925.56529297 98.67324219 886.25058594 98.67324219zM354.49103516 200.47132812c60.54662109 0 109.63617188 49.04727539 109.63617187 109.5516211 0 60.50425781-49.08867187 109.55162109-109.63617187 109.55162109s-109.63617188-49.04727539-109.63617188-109.55162109C244.85477539 249.51772461 293.94353516 200.47132812 354.49103516 200.47132812zM167.03632813 839.84574219c-8.22058594 0-16.50506836-2.83227539-23.23441407-8.62646485-14.99308594-12.86279297-16.73912109-35.45727539-3.87632812-50.47286132l164.34720703-247.7241211c12.20396484-14.26860352 33.32970703-16.65448242 48.42896484-5.47286133l145.00977539 107.69668946 259.82191407-295.15227539c12.30925781-15.44036133 77.58448242-88.16853516 115.79036132-5.68529297 0.04227539-0.12779297 0.08551758 109.06110352 0.12779297 220.54948242 0.04227539 116.28272461 0.06389648 284.78162109 0.06389649 284.78162109C872.72808594 839.54603516 167.37646484 839.84574219 167.03632813 839.84574219z"></path>\n' +
"</svg>"
);
}
}
+157 -157
View File
@@ -1,172 +1,172 @@
const fs = require('fs');
const path = require('path');
const fs = require("fs");
const path = require("path");
hexo.extend.filter.register('markdown-it:renderer', function (md) {
md.use(require('markdown-it-abbr'), {});
md.use(require('markdown-it-footnote'), {});
md.use(require('markdown-it-ins'), {});
md.use(require('markdown-it-sub'), {});
md.use(require('markdown-it-sup'), {});
md.use(require('markdown-it-task-lists'), {});
md.use(require('markdown-it-emoji'), {});
md.use(require('markdown-it-attrs'), {});
md.use(require('markdown-it-highlightjs'), {});
md.use(require('markdown-it-checkbox'), {});
md.use(require('markdown-it-multimd-table'), {
multiline: false,
rowspan: true,
headerless: false,
});
md.use(require('markdown-it-shortcode-tag'), {
widget: {
render: function (attrs, env) {
let widgetPath = path.resolve(`./source/widget/${attrs.name}.html`);
if (fs.existsSync(widgetPath)) {
return fs.readFileSync(widgetPath, 'utf8').trim();
} else {
let error = `Error: ${attrs.name} widget not Found!`;
console.log(error);
return error;
}
}
hexo.extend.filter.register("markdown-it:renderer", function (md) {
md.use(require("markdown-it-abbr"), {});
md.use(require("markdown-it-footnote"), {});
md.use(require("markdown-it-ins"), {});
md.use(require("markdown-it-sub"), {});
md.use(require("markdown-it-sup"), {});
md.use(require("markdown-it-task-lists"), {});
md.use(require("markdown-it-emoji"), {});
md.use(require("markdown-it-attrs"), {});
md.use(require("markdown-it-highlightjs"), {});
md.use(require("markdown-it-checkbox"), {});
md.use(require("markdown-it-multimd-table"), {
multiline: false,
rowspan: true,
headerless: false,
});
md.use(require("markdown-it-shortcode-tag"), {
widget: {
render: function (attrs, env) {
let widgetPath = path.resolve(`./source/widget/${attrs.name}.html`);
if (fs.existsSync(widgetPath)) {
return fs.readFileSync(widgetPath, "utf8").trim();
} else {
let error = `Error: ${attrs.name} widget not Found!`;
console.log(error);
return error;
}
});
headerSections(md, {
h2: {
wrapperClass: 'h2-wrap',
innerClass: 'h3-wrap-list',
},
h3: {
wrapperClass: 'h3-wrap',
innerClass: 'section',
},
tagName: "div"
});
},
},
});
headerSections(md, {
h2: {
wrapperClass: "h2-wrap",
innerClass: "h3-wrap-list",
},
h3: {
wrapperClass: "h3-wrap",
innerClass: "section",
},
tagName: "div",
});
});
function headerSections(md, options) {
const opts = Object.assign({}, options);
const opts = Object.assign({}, options);
function addSections(state) {
let tokens = []; // output
let Token = state.Token;
let sections = [];
let nestedLevel = 0;
function addSections(state) {
let tokens = []; // output
let Token = state.Token;
let sections = [];
let nestedLevel = 0;
function openTag(token, parser, classOptName) {
let t = new Token(parser, opts.tagName, 1);
t.block = true;
const cls = token && opts[token.tag] && opts[token.tag][classOptName];
t.attrs = appendClass(token.attrs, cls);
return t;
}
function closeTag(parser) {
let t = new Token(parser, opts.tagName, -1);
t.block = true;
return t;
}
function closeSections(section) {
while (last(sections) && section.header <= last(sections).header) {
sections.pop();
tokens.push(closeTag('section_inner_close'));
tokens.push(closeTag('section_wrapper_close'));
}
}
function closeSectionsToCurrentNesting(nesting) {
while (last(sections) && nesting < last(sections).nesting) {
sections.pop();
tokens.push(closeTag('section_inner_close'));
tokens.push(closeTag('section_wrapper_close'));
}
}
function closeAllSections() {
while (sections.pop()) {
tokens.push(closeTag('section_inner_close'));
tokens.push(closeTag('section_wrapper_close'));
}
}
for (let i = 0, l = state.tokens.length; i < l; i++) {
let token = state.tokens[i];
// record level of nesting
if (token.type.search('heading') !== 0) {
nestedLevel += token.nesting;
}
if (last(sections) && nestedLevel < last(sections).nesting) {
closeSectionsToCurrentNesting(nestedLevel);
}
// add sections before headers
let expect = opts.hasOwnProperty(token.tag);
if (token.type === 'heading_open') {
let section = {
header: headingLevel(token.tag),
nesting: nestedLevel
};
if (last(sections) && section.header <= last(sections).header && expect) {
closeSections(section);
}
if (expect) {
tokens.push(openTag(token, 'section_wrapper_open', 'wrapperClass'));
if (token.attrIndex('id') !== -1) {
// remove ID from token
token.attrs.splice(token.attrIndex('id'), 1);
}
sections.push(section);
// The attribute has been placed in section_open,
// clear the attribute of the header tag
token.attrs = [];
}
tokens.push(token);
} else if (token.type === 'heading_close') { // add inner section after headers
tokens.push(token);
if (expect) {
tokens.push(openTag(token, 'section_inner_open', 'innerClass'));
}
} else {
tokens.push(token);
}
} // end for every token
closeAllSections();
state.tokens = tokens;
function openTag(token, parser, classOptName) {
let t = new Token(parser, opts.tagName, 1);
t.block = true;
const cls = token && opts[token.tag] && opts[token.tag][classOptName];
t.attrs = appendClass(token.attrs, cls);
return t;
}
function appendClass(attrs, cls) {
if (cls == null) {
return attrs;
}
if (attrs == null) {
attrs = [];
}
let appended = false;
attrs.forEach(function (x, i) {
if (x[0] === "class") {
x[1] = cls + " " + x[1];
appended = true;
}
});
if (!appended) {
attrs.push(["class", cls.trim()])
}
return attrs;
function closeTag(parser) {
let t = new Token(parser, opts.tagName, -1);
t.block = true;
return t;
}
function headingLevel(header) {
return parseInt(header.charAt(1));
function closeSections(section) {
while (last(sections) && section.header <= last(sections).header) {
sections.pop();
tokens.push(closeTag("section_inner_close"));
tokens.push(closeTag("section_wrapper_close"));
}
}
function last(arr) {
return arr.slice(-1)[0];
function closeSectionsToCurrentNesting(nesting) {
while (last(sections) && nesting < last(sections).nesting) {
sections.pop();
tokens.push(closeTag("section_inner_close"));
tokens.push(closeTag("section_wrapper_close"));
}
}
md.core.ruler.push('header_sections', addSections);
}
function closeAllSections() {
while (sections.pop()) {
tokens.push(closeTag("section_inner_close"));
tokens.push(closeTag("section_wrapper_close"));
}
}
for (let i = 0, l = state.tokens.length; i < l; i++) {
let token = state.tokens[i];
// record level of nesting
if (token.type.search("heading") !== 0) {
nestedLevel += token.nesting;
}
if (last(sections) && nestedLevel < last(sections).nesting) {
closeSectionsToCurrentNesting(nestedLevel);
}
// add sections before headers
let expect = opts.hasOwnProperty(token.tag);
if (token.type === "heading_open") {
let section = {
header: headingLevel(token.tag),
nesting: nestedLevel,
};
if (last(sections) && section.header <= last(sections).header && expect) {
closeSections(section);
}
if (expect) {
tokens.push(openTag(token, "section_wrapper_open", "wrapperClass"));
if (token.attrIndex("id") !== -1) {
// remove ID from token
token.attrs.splice(token.attrIndex("id"), 1);
}
sections.push(section);
// The attribute has been placed in section_open,
// clear the attribute of the header tag
token.attrs = [];
}
tokens.push(token);
} else if (token.type === "heading_close") {
// add inner section after headers
tokens.push(token);
if (expect) {
tokens.push(openTag(token, "section_inner_open", "innerClass"));
}
} else {
tokens.push(token);
}
} // end for every token
closeAllSections();
state.tokens = tokens;
}
function appendClass(attrs, cls) {
if (cls == null) {
return attrs;
}
if (attrs == null) {
attrs = [];
}
let appended = false;
attrs.forEach(function (x, i) {
if (x[0] === "class") {
x[1] = cls + " " + x[1];
appended = true;
}
});
if (!appended) {
attrs.push(["class", cls.trim()]);
}
return attrs;
}
function headingLevel(header) {
return parseInt(header.charAt(1));
}
function last(arr) {
return arr.slice(-1)[0];
}
md.core.ruler.push("header_sections", addSections);
}
+2 -2
View File
@@ -3,6 +3,6 @@
* This fixes an issue with hexo-renderer-stylus, which otherwise ignores these
* configuration overrides.
*/
hexo.on('generateBefore', function () {
hexo.theme.config = Object.assign({}, hexo.theme.config, hexo.config.theme_config);
hexo.on("generateBefore", function () {
hexo.theme.config = Object.assign({}, hexo.theme.config, hexo.config.theme_config);
});
+11 -11
View File
@@ -1,14 +1,14 @@
let pagination = require("hexo-pagination");
hexo.extend.generator.register("notes-pagination", function (locals) {
let config = this.config;
let posts = locals.posts.filter(post => post.layout === "note").sort("-date");
return pagination("notes", posts, {
perPage: config.per_page,
layout: ['notes'],
format: "%d/",
data: {
_isNotePagination: true
}
});
});
let config = this.config;
let posts = locals.posts.filter((post) => post.layout === "note").sort("-date");
return pagination("notes", posts, {
perPage: config.per_page,
layout: ["notes"],
format: "%d/",
data: {
_isNotePagination: true,
},
});
});
+54 -55
View File
@@ -1,69 +1,68 @@
const fs = require('fs');
const path = require('path');
const fs = require("fs");
const path = require("path");
hexo.extend.helper.register("page_title", function () {
let title = "";
if (this.is_home()) {
title = `${this.config.title} - ${this.config.subtitle}`;
} else if (this.page.layout === "note") {
title = `${this.page.title} - ${this.config.title}`;
} else if (this.is_page()) {
title = `${this.page.title} - ${this.config.title}`;
} else if (this.is_post()) {
title = this.page.title;
let hasCommand = this.page.categories.findOne({name: "Linux Command"});
if (hasCommand) {
title += " Command";
}
title = `${title} Cheat Sheet & Quick Reference`;
} else if (this.page._isNotePagination) {
title = `Page ${this.page.current} of Notes - ${this.config.title}`
let title = "";
if (this.is_home()) {
title = `${this.config.title} - ${this.config.subtitle}`;
} else if (this.page.layout === "note") {
title = `${this.page.title} - ${this.config.title}`;
} else if (this.is_page()) {
title = `${this.page.title} - ${this.config.title}`;
} else if (this.is_post()) {
title = this.page.title;
let hasCommand = this.page.categories.findOne({ name: "Linux Command" });
if (hasCommand) {
title += " Command";
}
return title;
title = `${title} Cheat Sheet & Quick Reference`;
} else if (this.page._isNotePagination) {
title = `Page ${this.page.current} of Notes - ${this.config.title}`;
}
return title;
});
hexo.extend.helper.register("page_description", function () {
let description;
if (this.is_home()) {
description = this.config.description;
} else if (this.page != null && this.page.intro != null) {
description = this.strip_html(this.markdown(this.page.intro)).substring(0, 110);
} else {
description = this.strip_html(this.page.content).substring(0, 130);
}
description = description.replace(/[\r\n\s\s+]+/g, " ");
return description;
let description;
if (this.is_home()) {
description = this.config.description;
} else if (this.page != null && this.page.intro != null) {
description = this.strip_html(this.markdown(this.page.intro)).substring(0, 110);
} else {
description = this.strip_html(this.page.content).substring(0, 130);
}
description = description.replace(/[\r\n\s\s+]+/g, " ");
return description;
});
hexo.extend.helper.register("page_keywords", function () {
let keywords = this.config.keywords;
if (this.page.tags && this.page.tags.each) {
this.page.tags.each(function (tag) {
keywords += ("," + tag.name);
});
}
return keywords;
let keywords = this.config.keywords;
if (this.page.tags && this.page.tags.each) {
this.page.tags.each(function (tag) {
keywords += "," + tag.name;
});
}
return keywords;
});
hexo.extend.helper.register("page_image", function () {
let homePng = "preview.png";
let postPng = "";
if (this.is_post()) {
postPng = `${this.page.slug}-preview.png`;
}
let homePng = "preview.png";
let postPng = "";
if (this.is_post()) {
postPng = `${this.page.slug}-preview.png`;
}
let version = (Math.random() + 1).toString(36).substring(7);
let imageURL;
let version = (Math.random() + 1).toString(36).substring(7);
let imageURL;
// Check file exists
let postPath = path.resolve("./", "source/assets/image/", postPng);
if (fs.existsSync(postPath)) {
// Generate image url
imageURL = `${this.config.url}/assets/image/${postPng}?v=${version}`;
} else {
// console.warn(`Warning: ${postPath} not Found!`);
imageURL = `${this.config.url}/assets/image/${homePng}?v=${version}`;
}
return imageURL;
});
// Check file exists
let postPath = path.resolve("./", "source/assets/image/", postPng);
if (fs.existsSync(postPath)) {
// Generate image url
imageURL = `${this.config.url}/assets/image/${postPng}?v=${version}`;
} else {
// console.warn(`Warning: ${postPath} not Found!`);
imageURL = `${this.config.url}/assets/image/${homePng}?v=${version}`;
}
return imageURL;
});
+30 -30
View File
@@ -1,32 +1,32 @@
const {encodeURL} = require('hexo-util');
const { encodeURL } = require("hexo-util");
hexo.extend.helper.register("share_link", function (type) {
let title = this.page_title();
let description = this.page_description();
let url = this.url_for(this.url);
let link = "";
switch (type) {
case "facebook":
link = `https://facebook.com/sharer/sharer.php?u=${url}`;
break;
case "twitter":
link = `https://twitter.com/intent/tweet/?text=${description}&url=${url}`;
break;
case "linkedin":
link = `https://www.linkedin.com/shareArticle?url=${url}&title=${title}&summary=${description}`;
break;
case "reddit":
link = `https://reddit.com/submit/?url=${url}&resubmit=true&title=${description}`;
break;
case "pinterest":
link = `https://pinterest.com/pin/create/button/?url=${url}&description=${description}`;
break;
case "mail":
link = `mailto:?subject=${title}&body=\n${description}\n\n${url}`;
break;
case "line":
link = `https://social-plugins.line.me/lineit/share?url=${url}`;
break;
}
return encodeURL(link);
});
let title = this.page_title();
let description = this.page_description();
let url = this.url_for(this.url);
let link = "";
switch (type) {
case "facebook":
link = `https://facebook.com/sharer/sharer.php?u=${url}`;
break;
case "twitter":
link = `https://twitter.com/intent/tweet/?text=${description}&url=${url}`;
break;
case "linkedin":
link = `https://www.linkedin.com/shareArticle?url=${url}&title=${title}&summary=${description}`;
break;
case "reddit":
link = `https://reddit.com/submit/?url=${url}&resubmit=true&title=${description}`;
break;
case "pinterest":
link = `https://pinterest.com/pin/create/button/?url=${url}&description=${description}`;
break;
case "mail":
link = `mailto:?subject=${title}&body=\n${description}\n\n${url}`;
break;
case "line":
link = `https://social-plugins.line.me/lineit/share?url=${url}`;
break;
}
return encodeURL(link);
});
+10 -10
View File
@@ -1,15 +1,15 @@
const path = require('path');
const fs = require('hexo-fs');
const path = require("path");
const fs = require("hexo-fs");
const outputFile = path.resolve("./", "source/ga_analytics_tops.json")
const outputFile = path.resolve("./", "source/ga_analytics_tops.json");
const cache = new Map();
hexo.extend.helper.register("topPosts", function (maximum = 4) {
let posts = cache.get(outputFile);
if (!posts) {
let content = fs.readFileSync(outputFile);
posts = JSON.parse(content);
cache.set(outputFile, posts);
}
return posts.slice(0, maximum);
let posts = cache.get(outputFile);
if (!posts) {
let content = fs.readFileSync(outputFile);
posts = JSON.parse(content);
cache.set(outputFile, posts);
}
return posts.slice(0, maximum);
});
+434 -435
View File
@@ -1,421 +1,421 @@
let Utils = (function () {
return {
LIBRARY: {
fuse: {
lib: ['/js/fuse_6.4.6.js'],
instance: 'Fuse',
attr: {async: true}
}
},
loadScripts: function (urls, callback, attr = {}, container = document.head) {
let scripts = [];
for (let i in urls) {
scripts[i] = document.createElement('script');
scripts[i].setAttribute("type", "text/javascript");
scripts[i].setAttribute("src", urls[i]);
Object.keys(attr).forEach(function (key) {
scripts[i].setAttribute(key, attr[key]);
})
}
let loadNextScript = function () {
let script = scripts.shift();
let loaded = false;
container.appendChild(script);
script.onload = script.onreadystatechange = function () {
let rs = this.readyState;
if (rs && rs !== 'complete' && rs !== 'loaded') return;
if (loaded) return;
loaded = true;
if (scripts.length) {
loadNextScript();
} else {
callback()
}
};
};
loadNextScript();
},
externalLibrary(library) {
return new Promise(resolve => {
if (window[library.instance] == null) {
this.loadScripts(library.lib, function () {
resolve(window[library.instance]);
}, library.attr, library.container);
} else {
resolve(window[library.instance]);
}
});
}
};
}());
window.addEventListener('load', () => {
const isDarkMode = document.documentElement.classList.contains("dark")
if (!isDarkMode) {
let icon = document.querySelector("#darkMode > i").classList;
icon.toggle('icon-light')
icon.toggle('icon-dark')
}
document.querySelector("#darkMode").addEventListener("click", function () {
let html = document.documentElement.classList;
html.toggle('dark')
let icon = document.querySelector("#darkMode > i").classList;
icon.toggle('icon-light')
icon.toggle('icon-dark')
let isDarkMode = html.contains("dark");
localStorage.theme = isDarkMode ? "dark" : "";
});
/******** List Collapsible ***********/
document.querySelectorAll("ul.collapsible > li > strong").forEach(function (strong) {
let li = strong.parentElement;
li.classList.add("active");
strong.classList.toggle("arrow-down");
strong.addEventListener("click", function () {
li.classList.toggle("active");
this.classList.toggle("arrow-down");
return {
LIBRARY: {
fuse: {
lib: ["/js/fuse_6.4.6.js"],
instance: "Fuse",
attr: { async: true },
},
},
loadScripts: function (urls, callback, attr = {}, container = document.head) {
let scripts = [];
for (let i in urls) {
scripts[i] = document.createElement("script");
scripts[i].setAttribute("type", "text/javascript");
scripts[i].setAttribute("src", urls[i]);
Object.keys(attr).forEach(function (key) {
scripts[i].setAttribute(key, attr[key]);
});
});
/******** Remove bottom border noise ********/
document.querySelectorAll(".h3-wrap ul").forEach(function (ul, i) {
let length = ul.querySelectorAll("li").length;
let matches = ul.className.match("cols-([0-9]+)");
let cols = matches === null ? 1 : parseInt(matches[1]);
let no_border_length = length === 1 || length % cols === 0 ? cols : length % cols;
for (let j = 1; j <= no_border_length; j++) {
let element = ul.querySelector(`li:nth-last-child(${j})`);
if (element != null) {
element.style.borderBottom = "none";
}
}
});
/******** h3-wrap blink ***********/
function blinkSection() {
let hash = window.location.hash;
let anchor = document.querySelector(`a[class="h-anchor"][href="${hash}"]`);
if (anchor != null) {
let anchorSection = anchor.parentElement.parentElement;
document.querySelectorAll(".boxed").forEach((e) => {
e.classList.remove("boxed")
});
let timer = setTimeout(function () {
anchorSection.classList.add("boxed");
clearTimeout(timer);
}, 100);
}
}
blinkSection();
window.addEventListener('popstate', blinkSection);
/******** Search ***********/
const searchEngine = function (options) {
let settings = options ? options : {};
let defaultOptions = {
trigger: "#mysearch-trigger",
container: "#mysearch",
dbPath: `${location.protocol}//${location.host}/search.json?v=1.0`
}
let loadNextScript = function () {
let script = scripts.shift();
let loaded = false;
container.appendChild(script);
script.onload = script.onreadystatechange = function () {
let rs = this.readyState;
if (rs && rs !== "complete" && rs !== "loaded") return;
if (loaded) return;
loaded = true;
if (scripts.length) {
loadNextScript();
} else {
callback();
}
};
this.container = (typeof settings.container != 'undefined') ? settings.container : defaultOptions.container;
this.trigger = (typeof settings.trigger != 'undefined') ? settings.trigger : defaultOptions.trigger;
this.dbPath = (typeof settings.dbPath != 'undefined') ? settings.dbPath : defaultOptions.dbPath;
};
loadNextScript();
},
externalLibrary(library) {
return new Promise((resolve) => {
if (window[library.instance] == null) {
this.loadScripts(
library.lib,
function () {
resolve(window[library.instance]);
},
library.attr,
library.container,
);
} else {
resolve(window[library.instance]);
}
});
},
};
})();
this.lastSearch = {};
window.addEventListener("load", () => {
const isDarkMode = document.documentElement.classList.contains("dark");
if (!isDarkMode) {
let icon = document.querySelector("#darkMode > i").classList;
icon.toggle("icon-light");
icon.toggle("icon-dark");
}
document.querySelector("#darkMode").addEventListener("click", function () {
let html = document.documentElement.classList;
html.toggle("dark");
let icon = document.querySelector("#darkMode > i").classList;
icon.toggle("icon-light");
icon.toggle("icon-dark");
let isDarkMode = html.contains("dark");
localStorage.theme = isDarkMode ? "dark" : "";
});
window.search = this;
/******** List Collapsible ***********/
document.querySelectorAll("ul.collapsible > li > strong").forEach(function (strong) {
let li = strong.parentElement;
li.classList.add("active");
strong.classList.toggle("arrow-down");
strong.addEventListener("click", function () {
li.classList.toggle("active");
this.classList.toggle("arrow-down");
});
});
/******** Remove bottom border noise ********/
document.querySelectorAll(".h3-wrap ul").forEach(function (ul, i) {
let length = ul.querySelectorAll("li").length;
let matches = ul.className.match("cols-([0-9]+)");
let cols = matches === null ? 1 : parseInt(matches[1]);
let no_border_length = length === 1 || length % cols === 0 ? cols : length % cols;
for (let j = 1; j <= no_border_length; j++) {
let element = ul.querySelector(`li:nth-last-child(${j})`);
if (element != null) {
element.style.borderBottom = "none";
}
}
});
/******** h3-wrap blink ***********/
function blinkSection() {
let hash = window.location.hash;
let anchor = document.querySelector(`a[class="h-anchor"][href="${hash}"]`);
if (anchor != null) {
let anchorSection = anchor.parentElement.parentElement;
document.querySelectorAll(".boxed").forEach((e) => {
e.classList.remove("boxed");
});
let timer = setTimeout(function () {
anchorSection.classList.add("boxed");
clearTimeout(timer);
}, 100);
}
}
blinkSection();
window.addEventListener("popstate", blinkSection);
/******** Search ***********/
const searchEngine = function (options) {
let settings = options ? options : {};
let defaultOptions = {
trigger: "#mysearch-trigger",
container: "#mysearch",
dbPath: `${location.protocol}//${location.host}/search.json?v=1.0`,
};
searchEngine.prototype = {
start: function () {
const _this = this;
this.container = typeof settings.container != "undefined" ? settings.container : defaultOptions.container;
this.trigger = typeof settings.trigger != "undefined" ? settings.trigger : defaultOptions.trigger;
this.dbPath = typeof settings.dbPath != "undefined" ? settings.dbPath : defaultOptions.dbPath;
_this.fetchData(); // Prepare search data
this.search = document.querySelector(this.container);
this.box = document.querySelector("#mysearch-box");
this.input = document.querySelector("#mysearch-input");
this.result = document.querySelector("#mysearch-list");
this.lastSearch.query = this.input.value;
this.lastSearch = {};
this.detectModal();
window.search = this;
};
searchEngine.prototype = {
start: function () {
const _this = this;
// Cancel button
const cancel = document.querySelector(".cancel");
cancel.addEventListener("click", function (e) {
_this.closeModal(true);
_this.fetchData(); // Prepare search data
this.search = document.querySelector(this.container);
this.box = document.querySelector("#mysearch-box");
this.input = document.querySelector("#mysearch-input");
this.result = document.querySelector("#mysearch-list");
this.lastSearch.query = this.input.value;
this.detectModal();
// Cancel button
const cancel = document.querySelector(".cancel");
cancel.addEventListener("click", function (e) {
_this.closeModal(true);
});
// Clear button
const clear = document.querySelector("#mysearch-clear");
clear.addEventListener("click", function (e) {
_this.doSearch("", true).then();
});
// Search trigger
const trigger = document.querySelector(_this.trigger);
trigger.addEventListener("click", function (e) {
_this.openModal(true);
});
document.body.addEventListener("click", function (e) {
if (_this.isOpened()) {
if (!_this.box.contains(e.target) && !trigger.contains(e.target)) {
_this.closeModal();
}
}
});
// Search input event
this.input.addEventListener("keyup", function (e) {
let value = _this.input.value;
if (value === _this.lastSearch.query) {
return;
}
_this.doSearch(value, true).then();
});
document.body.addEventListener("keydown", function (e) {
if (e.key === "ArrowDown") {
if (_this.isOpened()) {
_this.moveItem(false);
e.preventDefault();
e.stopPropagation();
}
} else if (e.key === "ArrowUp") {
if (_this.isOpened()) {
_this.moveItem(true);
e.preventDefault();
e.stopPropagation();
}
} else if (e.key === "Enter") {
if (_this.isOpened()) {
let active = _this.result.querySelector("li.active > a");
if (active != null) {
window.location.href = active.getAttribute("href");
}
}
e.preventDefault();
e.stopPropagation();
} else if (e.key === "Escape") {
_this.closeModal();
e.preventDefault();
e.stopPropagation();
} else if ((e.ctrlKey || e.metaKey) && e.key === "k") {
_this.toggleModal();
e.preventDefault();
e.stopPropagation();
}
});
},
moveItem: function (up) {
let current = this.result.querySelector("li.active");
let next = up ? current.previousElementSibling : current.nextElementSibling;
if (next !== null) {
current.classList.remove("active");
current.classList.add("inactive");
next.classList.remove("inactive");
next.classList.add("active");
this.renderPreview();
}
},
detectModal: function () {
const url_string = window.location.href;
const url = new URL(url_string);
const query = url.searchParams.get("q");
if (query != null) {
this.input.value = query;
this.openModal(false);
}
},
isOpened: function () {
return this.search.classList.contains("block");
},
toggleModal: function () {
if (this.isOpened()) {
this.closeModal();
} else {
this.openModal();
}
},
openModal: function (reset) {
this.search.classList.remove("hidden");
this.search.classList.add("block");
if (reset) {
this.input.value = "";
}
document.body.classList.add("overflow-hidden");
this.doSearch(this.input.value, false);
this.input.focus();
},
closeModal: function (reset) {
this.search.classList.remove("block");
this.search.classList.add("hidden");
if (reset) {
this.input.value = "";
}
document.body.classList.remove("overflow-hidden");
this.input.blur();
},
changeUrl: function (params) {
let baseURL = `${location.protocol}//${location.host}${location.pathname}`;
let newURL = baseURL;
if (params !== "" && params != null) {
newURL = `${baseURL}?${params}`;
}
history.pushState({}, null, newURL);
},
fetchData: async function () {
const _this = this;
if (_this.index !== undefined) {
return;
}
return await fetch(_this.dbPath)
.then((resp) => resp.text())
.then((resp) => {
_this.db = JSON.parse(resp);
_this.index = new Fuse(_this.db, {
// isCaseSensitive: false,
includeScore: false,
shouldSort: true,
includeMatches: true,
matchEmptyQuery: true,
// minMatchCharLength: 1,
// location: 0,
threshold: 0.1,
// distance: 100,
// useExtendedSearch: false,
// ignoreLocation: true,
// ignoreFieldNorm: false,
keys: [
{ name: "title", weight: 12 },
{ name: "tags", weight: 6 },
{ name: "categories", weight: 6 },
{ name: "sections.h3.title", weight: 5 },
{ name: "sections.h2.title", weight: 1 },
{ name: "intro", weight: 1 },
],
});
// default return all
_this.lastSearch.whole = _this.db.map((doc, idx) => ({
item: doc,
score: 1,
refIndex: idx,
}));
return resp;
});
},
doSearch: async function (value, history) {
const _this = this;
await _this.fetchData().then(() => {
if (this.lastSearch.query === value && this.lastSearch.resp !== undefined) {
this.renderResult(this.lastSearch.resp);
this.renderPreview();
} else {
let results = value !== "" ? _this.index.search(`${value}`) : _this.lastSearch.whole;
if (history) {
this.changeUrl(value === "" ? null : `q=${value}`);
}
this.lastSearch.query = value;
this.lastSearch.resp = results;
this.renderResult(results);
this.renderPreview();
}
});
},
addEventToResult: function () {
const _this = this;
this.result.querySelectorAll("li").forEach(function (li) {
li.addEventListener("mouseover", function (e) {
if (_this.isOpened()) {
_this.result.querySelectorAll("li").forEach(function (e) {
e.classList.remove("active");
e.classList.add("inactive");
});
// Clear button
const clear = document.querySelector("#mysearch-clear");
clear.addEventListener("click", function (e) {
_this.doSearch("", true).then();
});
// Search trigger
const trigger = document.querySelector(_this.trigger);
trigger.addEventListener("click", function (e) {
_this.openModal(true);
});
document.body.addEventListener('click', function (e) {
if (_this.isOpened()) {
if (!_this.box.contains(e.target) && !trigger.contains(e.target)) {
_this.closeModal();
}
}
});
// Search input event
this.input.addEventListener("keyup", function (e) {
let value = _this.input.value
if (value === _this.lastSearch.query) {
return;
}
_this.doSearch(value, true).then();
});
document.body.addEventListener('keydown', function (e) {
if (e.key === "ArrowDown") {
if (_this.isOpened()) {
_this.moveItem(false)
e.preventDefault();
e.stopPropagation();
}
} else if (e.key === 'ArrowUp') {
if (_this.isOpened()) {
_this.moveItem(true)
e.preventDefault();
e.stopPropagation();
}
} else if (e.key === 'Enter') {
if (_this.isOpened()) {
let active = _this.result.querySelector("li.active > a")
if (active != null) {
window.location.href = active.getAttribute("href");
}
}
e.preventDefault();
e.stopPropagation();
} else if (e.key === 'Escape') {
_this.closeModal();
e.preventDefault();
e.stopPropagation();
} else if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
_this.toggleModal();
e.preventDefault();
e.stopPropagation();
}
});
},
moveItem: function (up) {
let current = this.result.querySelector("li.active")
let next = up ? current.previousElementSibling : current.nextElementSibling;
if (next !== null) {
current.classList.remove("active");
current.classList.add("inactive");
next.classList.remove("inactive");
next.classList.add("active");
this.renderPreview();
this.classList.remove("inactive");
this.classList.add("active");
_this.renderPreview();
}
});
});
},
mark: function (text, matches) {
let result = [];
let pair = matches.shift();
// Build the formatted string
for (let i = 0; i < text.length; i++) {
let char = text.charAt(i);
if (pair && i === pair[0]) {
result.push("<mark>");
}
result.push(char);
if (pair && i === pair[1]) {
result.push("</mark>");
pair = matches.shift();
}
}
return result.join("");
},
highlightMatches: function (result) {
if (result.matches === undefined || result.item.length === 0) {
return;
}
const _this = this;
result.item = JSON.parse(JSON.stringify(_this.db[result.refIndex]));
result.matches.forEach((m) => {
switch (m.key) {
case "tags":
case "categories":
result.item[m.key][m.refIndex] = _this.mark(m.value, m.indices);
break;
case "sections.h2.title":
result.item["sections"][m.refIndex]["h2"]["title"] = _this.mark(m.value, m.indices);
break;
case "sections.h3.title":
let currLength = 0;
let lastLength = 0;
for (let i = 0; i < result.item["sections"].length; i++) {
let subArr = result.item["sections"][i]["h3"];
currLength += subArr.length;
if (m.refIndex >= lastLength && m.refIndex < currLength) {
result.item["sections"][i]["h3"][m.refIndex - lastLength]["title"] = _this.mark(m.value, m.indices);
break;
}
lastLength += subArr.length;
}
},
detectModal: function () {
const url_string = window.location.href;
const url = new URL(url_string);
const query = url.searchParams.get("q");
if (query != null) {
this.input.value = query;
this.openModal(false);
}
},
isOpened: function () {
return this.search.classList.contains("block");
},
toggleModal: function () {
if (this.isOpened()) {
this.closeModal();
} else {
this.openModal();
}
},
openModal: function (reset) {
this.search.classList.remove("hidden")
this.search.classList.add("block")
if (reset) {
this.input.value = "";
}
document.body.classList.add("overflow-hidden");
this.doSearch(this.input.value, false);
this.input.focus();
},
closeModal: function (reset) {
this.search.classList.remove("block")
this.search.classList.add("hidden")
if (reset) {
this.input.value = "";
}
document.body.classList.remove("overflow-hidden");
this.input.blur();
},
changeUrl: function (params) {
let baseURL = `${location.protocol}//${location.host}${location.pathname}`;
let newURL = baseURL;
if (params !== "" && params != null) {
newURL = `${baseURL}?${params}`
}
history.pushState({}, null, newURL);
},
fetchData: async function () {
const _this = this;
if (_this.index !== undefined) {
return;
}
return await fetch(_this.dbPath)
.then(resp => resp.text())
.then(resp => {
_this.db = JSON.parse(resp);
_this.index = new Fuse(_this.db, {
// isCaseSensitive: false,
includeScore: false,
shouldSort: true,
includeMatches: true,
matchEmptyQuery: true,
// minMatchCharLength: 1,
// location: 0,
threshold: 0.1,
// distance: 100,
// useExtendedSearch: false,
// ignoreLocation: true,
// ignoreFieldNorm: false,
keys: [
{name: 'title', weight: 12},
{name: 'tags', weight: 6},
{name: 'categories', weight: 6},
{name: 'sections.h3.title', weight: 5},
{name: 'sections.h2.title', weight: 1},
{name: 'intro', weight: 1},
]
});
// default return all
_this.lastSearch.whole = _this.db.map((doc, idx) => ({
item: doc,
score: 1,
refIndex: idx
}));
return resp;
});
},
doSearch: async function (value, history) {
const _this = this;
await _this.fetchData().then(() => {
if (this.lastSearch.query === value && this.lastSearch.resp !== undefined) {
this.renderResult(this.lastSearch.resp);
this.renderPreview();
} else {
let results = value !== "" ? _this.index.search(`${value}`) : _this.lastSearch.whole;
if (history) {
this.changeUrl(value === "" ? null : `q=${value}`);
}
this.lastSearch.query = value;
this.lastSearch.resp = results;
this.renderResult(results);
this.renderPreview();
}
});
},
addEventToResult: function () {
const _this = this;
this.result.querySelectorAll("li").forEach(function (li) {
li.addEventListener("mouseover", function (e) {
if (_this.isOpened()) {
_this.result.querySelectorAll("li").forEach(function (e) {
e.classList.remove("active")
e.classList.add("inactive")
});
this.classList.remove("inactive");
this.classList.add("active");
_this.renderPreview();
}
});
});
},
mark: function (text, matches) {
let result = []
let pair = matches.shift()
// Build the formatted string
for (let i = 0; i < text.length; i++) {
let char = text.charAt(i)
if (pair && i === pair[0]) {
result.push('<mark>')
}
result.push(char)
if (pair && i === pair[1]) {
result.push('</mark>')
pair = matches.shift()
}
}
return result.join('');
},
highlightMatches: function (result) {
if (result.matches === undefined || result.item.length === 0) {
return;
}
const _this = this;
result.item = JSON.parse(JSON.stringify(_this.db[result.refIndex]))
result.matches.forEach(m => {
switch (m.key) {
case "tags":
case "categories":
result.item[m.key][m.refIndex] = _this.mark(m.value, m.indices);
break;
case "sections.h2.title":
result.item["sections"][m.refIndex]["h2"]["title"] = _this.mark(m.value, m.indices);
break;
case "sections.h3.title":
let currLength = 0;
let lastLength = 0;
for (let i = 0; i < result.item["sections"].length; i++) {
let subArr = result.item["sections"][i]["h3"];
currLength += subArr.length;
if (m.refIndex >= lastLength && m.refIndex < currLength) {
result.item["sections"][i]["h3"][m.refIndex - lastLength]["title"] = _this.mark(m.value, m.indices)
break;
}
lastLength += subArr.length;
}
break;
default:
result.item[m.key] = _this.mark(m.value, m.indices);
break;
}
})
},
renderResult: function (results) {
const _this = this;
let liHtml = "";
let index = 0;
results.forEach(function (result, itemIndex) {
let activeStr = "inactive";
if (index === 0) {
activeStr = "active";
}
break;
default:
result.item[m.key] = _this.mark(m.value, m.indices);
break;
}
});
},
renderResult: function (results) {
const _this = this;
let liHtml = "";
let index = 0;
results.forEach(function (result, itemIndex) {
let activeStr = "inactive";
if (index === 0) {
activeStr = "active";
}
_this.highlightMatches(result);
_this.highlightMatches(result);
let hit = result.item;
let tags = hit.tags || [];
let categories = hit.categories || [];
let tagStr = tags.join("<span class='text-slate-300 px-1'>•</span>");
let tagsHTML = "";
if (tagStr !== "") {
tagsHTML = `<div class="w-px h-3 bg-slate-300 mr-2"></div><span class="mr-2">${tagStr}</span>`
}
liHtml += `<li class="group ${activeStr} m-3 fadeIn" data-index="${itemIndex}">
let hit = result.item;
let tags = hit.tags || [];
let categories = hit.categories || [];
let tagStr = tags.join("<span class='text-slate-300 px-1'>•</span>");
let tagsHTML = "";
if (tagStr !== "") {
tagsHTML = `<div class="w-px h-3 bg-slate-300 mr-2"></div><span class="mr-2">${tagStr}</span>`;
}
liHtml += `<li class="group ${activeStr} m-3 fadeIn" data-index="${itemIndex}">
<a href="${hit.path}" class="flex justify-between items-center rounded-lg py-1 px-4 transition-colors duration-100 ease-in-out overflow-hidden">
<div class="flex items-start">
<div class="flex justify-center items-center w-5 mr-5 mt-2 flex-none">
@@ -432,49 +432,48 @@ window.addEventListener('load', () => {
<i class="w-6 ml-8 p-2 icon icon-enter"></i>
</a>
</li>`;
index++;
});
index++;
});
this.result.innerHTML = liHtml;
this.addEventToResult();
},
renderPreview() {
const active = this.search.querySelector("li.active");
if (active == null) {
return;
}
const _this = this;
let itemIndex = active.getAttribute("data-index");
let hit = _this.lastSearch.resp[parseInt(itemIndex)].item;
this.result.innerHTML = liHtml;
this.addEventToResult();
},
renderPreview() {
const active = this.search.querySelector("li.active");
if (active == null) {
return;
}
const _this = this;
let itemIndex = active.getAttribute("data-index");
let hit = _this.lastSearch.resp[parseInt(itemIndex)].item;
let olInnerHtml = "";
let olInnerHtml = "";
hit.sections.forEach(function (section, index, array) {
let h3HTML = "";
section.h3.forEach(function (h3) {
let anchor = hit.path + h3.anchor;
h3HTML += `<a href="${anchor}" class="inline-block mr-1 px-2 p-0.5 transition duration-200 ease-in-out rounded-full hover:bg-emerald-500 text-slate-500 dark:text-slate-300 hover:text-slate-50">${h3.title.toLowerCase()}</a>`
});
let anchor = hit.path + section.h2.anchor;
olInnerHtml += `<li class="text-slate-700 dark:text-slate-300 hover:underline hover:text-slate-900 mt-3 mb-2">
hit.sections.forEach(function (section, index, array) {
let h3HTML = "";
section.h3.forEach(function (h3) {
let anchor = hit.path + h3.anchor;
h3HTML += `<a href="${anchor}" class="inline-block mr-1 px-2 p-0.5 transition duration-200 ease-in-out rounded-full hover:bg-emerald-500 text-slate-500 dark:text-slate-300 hover:text-slate-50">${h3.title.toLowerCase()}</a>`;
});
let anchor = hit.path + section.h2.anchor;
olInnerHtml += `<li class="text-slate-700 dark:text-slate-300 hover:underline hover:text-slate-900 mt-3 mb-2">
<a href="${anchor}"> ${section.h2.title}</a>
</li>
<span>${h3HTML}</span>`;
})
});
document.querySelector(".preview-panel").innerHTML = `<section class="w-full py-3 px-5">
document.querySelector(".preview-panel").innerHTML = `<section class="w-full py-3 px-5">
<div class="flex justify-center pt-1 pb-4">
<div class="flex justify-center items-center w-8 h-8 rounded ${hit.background === undefined ? 'bg-emerald-500' : hit.background} shadow-lg">
<div class="flex justify-center items-center w-8 h-8 rounded ${hit.background === undefined ? "bg-emerald-500" : hit.background} shadow-lg">
<i class="text-2xl text-slate-100">${hit.icon}</i>
</div>
</div>
<div class="flex justify-center items-center font-medium flex-wrap dark:text-slate-200">${hit.title}</div>
<ol class="list-inside mt-4 pt-2 text-sm list-decimal">${olInnerHtml}</ol>
</section>`;
}
};
},
};
// Start search
Utils.externalLibrary(Utils.LIBRARY.fuse).then(() => new searchEngine().start());
// Start search
Utils.externalLibrary(Utils.LIBRARY.fuse).then(() => new searchEngine().start());
});