From 89fc2917985d3da944af8116e101748267d66104 Mon Sep 17 00:00:00 2001
From: amzrk2
Date: Sun, 14 Jun 2020 23:17:37 +0800
Subject: Remove medium-zoom
---
assets/js/fuji.js | 31 -------------------------------
1 file changed, 31 deletions(-)
(limited to 'assets/js')
diff --git a/assets/js/fuji.js b/assets/js/fuji.js
index 4bc9d56..b72c30e 100644
--- a/assets/js/fuji.js
+++ b/assets/js/fuji.js
@@ -10,23 +10,6 @@ function getNowTheme() {
}
}
-// update medium-zoom theme
-function updateMeidumTheme(mediumInst) {
- let targetTheme = getNowTheme();
- if (mediumInst) {
- mediumInst.detach();
- if (targetTheme === 'dark') {
- mediumInst = mediumZoom('.img-zoomable', {
- background: '#2f3136',
- });
- } else {
- mediumInst = mediumZoom('.img-zoomable', {
- background: '#fffffd',
- });
- }
- }
-}
-
// update utterances theme
function updateUtterancesTheme(utterancesFrame) {
let targetTheme = getNowTheme();
@@ -61,18 +44,6 @@ document.querySelector('.btn .btn-scroll-top').addEventListener('click', () => {
document.documentElement.scrollTop = 0;
});
-// init medium-zoom
-var mediumInst; // medium-zoom instance
-if (getNowTheme() === 'dark') {
- mediumInst = mediumZoom('.img-zoomable', {
- background: '#2f3136',
- });
-} else {
- mediumInst = mediumZoom('.img-zoomable', {
- background: '#fffffd',
- });
-}
-
// theme switch button
document.querySelector('.btn .btn-toggle-mode').addEventListener('click', () => {
let nowTheme = getNowTheme();
@@ -95,8 +66,6 @@ document.querySelector('.btn .btn-toggle-mode').addEventListener('click', () =>
localStorage.setItem('fuji_data-theme', systemTheme === 'light' ? 'auto' : 'light');
}
- // update medium background
- updateMeidumTheme(mediumInst);
// switch comment area theme
// if this page has comment area
let commentArea = document.querySelector('.post-comment');
--
cgit v1.2.3
From a3376d1ad133455b73ca893e222c1aec89ae6d44 Mon Sep 17 00:00:00 2001
From: amzrk2
Date: Mon, 15 Jun 2020 23:50:54 +0800
Subject: Update searching based on Fuse.js
---
assets/js/fuji.js | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
(limited to 'assets/js')
diff --git a/assets/js/fuji.js b/assets/js/fuji.js
index b72c30e..d1be458 100644
--- a/assets/js/fuji.js
+++ b/assets/js/fuji.js
@@ -83,3 +83,40 @@ document.querySelector('.btn .btn-toggle-mode').addEventListener('click', () =>
}
}
});
+
+// search by fuse.js
+function searchAll(key, index) {
+ let fuse = new Fuse(index, {
+ keys: ['title', 'tags'],
+ });
+ let result = fuse.search(key);
+ console.log(result);
+ if (result.length > 0) {
+ document.getElementById('search-result').innerHTML = template('search-result-template', result);
+ }
+}
+
+let urlParams = new URLSearchParams(window.location.search); // get params from URL
+if (urlParams.has('search')) {
+ let key = urlParams.get('search'); // get search keyword
+ document.querySelector('.search-input input').setAttribute('value', key);
+ // get search index from json
+ let xhr = new XMLHttpRequest();
+ xhr.open('GET', '/index.json', true);
+ xhr.responseType = 'json';
+ xhr.onerror = function (e) {
+ console.error(`${xhr.status} ${xhr.statusText}`);
+ };
+ xhr.onload = function () {
+ if (xhr.readyState === 4) {
+ if (xhr.status === 200) {
+ // use index json to search
+ console.log(xhr.response);
+ searchAll(key, xhr.response);
+ } else {
+ console.error(`${xhr.status} ${xhr.statusText}`);
+ }
+ }
+ };
+ xhr.send(null);
+}
--
cgit v1.2.3
From e7587236dbe98775315619d4f3b8d3f335001583 Mon Sep 17 00:00:00 2001
From: amzrk2
Date: Tue, 16 Jun 2020 00:47:55 +0800
Subject: Update tags in search template
---
assets/js/fuji.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'assets/js')
diff --git a/assets/js/fuji.js b/assets/js/fuji.js
index d1be458..55e93b5 100644
--- a/assets/js/fuji.js
+++ b/assets/js/fuji.js
@@ -93,12 +93,14 @@ function searchAll(key, index) {
console.log(result);
if (result.length > 0) {
document.getElementById('search-result').innerHTML = template('search-result-template', result);
+ } else {
+ document.getElementById('search-result').innerHTML = 'NOT FOUND';
}
}
let urlParams = new URLSearchParams(window.location.search); // get params from URL
-if (urlParams.has('search')) {
- let key = urlParams.get('search'); // get search keyword
+if (urlParams.has('s')) {
+ let key = urlParams.get('s'); // get search keyword
document.querySelector('.search-input input').setAttribute('value', key);
// get search index from json
let xhr = new XMLHttpRequest();
--
cgit v1.2.3
From c42924047c6f654c4723746790e041f8907ed378 Mon Sep 17 00:00:00 2001
From: amzrk2
Date: Tue, 16 Jun 2020 14:00:53 +0800
Subject: Searching now works
---
assets/js/fuji.js | 45 ++++++++++++++++++++++++++++++++++++---------
1 file changed, 36 insertions(+), 9 deletions(-)
(limited to 'assets/js')
diff --git a/assets/js/fuji.js b/assets/js/fuji.js
index 55e93b5..bf9eabc 100644
--- a/assets/js/fuji.js
+++ b/assets/js/fuji.js
@@ -85,38 +85,65 @@ document.querySelector('.btn .btn-toggle-mode').addEventListener('click', () =>
});
// search by fuse.js
-function searchAll(key, index) {
+function searchAll(key, index, counter) {
let fuse = new Fuse(index, {
- keys: ['title', 'tags'],
+ shouldSort: true,
+ distance: 10000,
+ keys: [
+ {
+ name: 'title',
+ weight: 2.0,
+ },
+ {
+ name: 'tags',
+ weight: 1.5,
+ },
+ {
+ name: 'content',
+ weight: 1.0,
+ },
+ ],
});
let result = fuse.search(key);
console.log(result);
if (result.length > 0) {
document.getElementById('search-result').innerHTML = template('search-result-template', result);
+ return [new Date().getTime() - counter, result.length];
} else {
- document.getElementById('search-result').innerHTML = 'NOT FOUND';
+ return 'notFound';
}
}
let urlParams = new URLSearchParams(window.location.search); // get params from URL
if (urlParams.has('s')) {
- let key = urlParams.get('s'); // get search keyword
+ let counter = new Date().getTime();
+ let infoElements = document.querySelectorAll('.search-result-info');
+ let key = urlParams.get('s'); // get search keyword, divided by space
document.querySelector('.search-input input').setAttribute('value', key);
// get search index from json
let xhr = new XMLHttpRequest();
xhr.open('GET', '/index.json', true);
xhr.responseType = 'json';
- xhr.onerror = function (e) {
- console.error(`${xhr.status} ${xhr.statusText}`);
+ xhr.onerror = (e) => {
+ infoElements[2].removeAttribute('style');
};
- xhr.onload = function () {
+ xhr.onload = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
// use index json to search
console.log(xhr.response);
- searchAll(key, xhr.response);
+ counter = searchAll(key, xhr.response, counter);
+ console.log(counter);
+ if (counter === 'notFound') {
+ infoElements[1].removeAttribute('style');
+ } else {
+ infoElements[0].innerHTML = infoElements[0].innerHTML.replace('[TIME]', counter[0]);
+ infoElements[0].innerHTML = infoElements[0].innerHTML.replace('[NUM]', counter[1]);
+ infoElements[0].removeAttribute('style');
+ }
} else {
- console.error(`${xhr.status} ${xhr.statusText}`);
+ console.error(`Failed to get index.json, ${xhr.status} ${xhr.statusText}`);
+ infoElements[2].removeAttribute('style');
}
}
};
--
cgit v1.2.3
From f88c7b78f224bf746b831001ec8cef01693a4b3c Mon Sep 17 00:00:00 2001
From: amzrk2
Date: Tue, 16 Jun 2020 16:09:04 +0800
Subject: Search page i18n
---
assets/js/fuji.js | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
(limited to 'assets/js')
diff --git a/assets/js/fuji.js b/assets/js/fuji.js
index bf9eabc..14d63bc 100644
--- a/assets/js/fuji.js
+++ b/assets/js/fuji.js
@@ -105,7 +105,7 @@ function searchAll(key, index, counter) {
],
});
let result = fuse.search(key);
- console.log(result);
+ // console.log(result);
if (result.length > 0) {
document.getElementById('search-result').innerHTML = template('search-result-template', result);
return [new Date().getTime() - counter, result.length];
@@ -124,16 +124,19 @@ if (urlParams.has('s')) {
let xhr = new XMLHttpRequest();
xhr.open('GET', '/index.json', true);
xhr.responseType = 'json';
- xhr.onerror = (e) => {
+ xhr.onerror = () => {
infoElements[2].removeAttribute('style');
};
- xhr.onload = () => {
+ xhr.ontimeout = () => {
+ infoElements[2].removeAttribute('style');
+ };
+ xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
// use index json to search
- console.log(xhr.response);
+ // console.log(xhr.response);
counter = searchAll(key, xhr.response, counter);
- console.log(counter);
+ // console.log(counter);
if (counter === 'notFound') {
infoElements[1].removeAttribute('style');
} else {
@@ -142,7 +145,6 @@ if (urlParams.has('s')) {
infoElements[0].removeAttribute('style');
}
} else {
- console.error(`Failed to get index.json, ${xhr.status} ${xhr.statusText}`);
infoElements[2].removeAttribute('style');
}
}
--
cgit v1.2.3