From da9f7b8218bb007ea19ef4413a3b4d7e3284f83b Mon Sep 17 00:00:00 2001
From: Cotes Chung <11371340+cotes2020@users.noreply.github.com>
Date: Sat, 23 Jan 2021 15:07:18 +0800
Subject: [PATCH] Process JS files with gulp
---
.gitignore | 4 +
_config.yml | 4 +
_includes/disqus.html | 9 +-
_includes/head.html | 16 +++
_includes/js-selector.html | 21 +++-
_includes/mermaid.html | 3 +-
_includes/panel.html | 2 +
assets/js/_commons.js | 23 ----
assets/js/_commons/copy-link.js | 4 +-
assets/js/_commons/search-display.js | 44 +++----
assets/js/_commons/sidebar.js | 6 +-
.../js/{_utils => _commons}/tooltip-loader.js | 0
assets/js/_commons/topbar-switch.js | 46 +++----
assets/js/_commons/topbar-title.js | 28 +++--
assets/js/_home-post.js | 22 ----
assets/js/_pv-config.js | 16 ---
assets/js/_utils/category-collapse.js | 27 +++--
assets/js/_utils/img-hyperlink.js | 5 +-
assets/js/_utils/lang-badge.js | 8 +-
assets/js/_utils/pageviews.js | 76 +++++++-----
assets/js/_utils/smooth-scroll.js | 113 +++++++++---------
assets/js/_utils/timeago.js | 16 +--
assets/js/categories.min.js | 13 --
assets/js/data/cache-list.js | 19 +--
assets/js/dist/categories.min.js | 1 +
assets/js/dist/home.min.js | 1 +
assets/js/dist/page.min.js | 1 +
assets/js/dist/post.min.js | 1 +
assets/js/dist/pvreport.min.js | 1 +
assets/js/home.min.js | 11 --
assets/js/lib/_bootstrap-toc.min.js | 5 -
assets/js/lib/_countUp.min.js | 2 -
assets/js/page.min.js | 13 --
assets/js/post.min.js | 20 ----
gulpfile.js/index.js | 10 ++
gulpfile.js/tasks/js.js | 86 +++++++++++++
package.json | 29 +++++
37 files changed, 380 insertions(+), 326 deletions(-)
delete mode 100644 assets/js/_commons.js
rename assets/js/{_utils => _commons}/tooltip-loader.js (100%)
delete mode 100644 assets/js/_home-post.js
delete mode 100644 assets/js/_pv-config.js
delete mode 100644 assets/js/categories.min.js
create mode 100644 assets/js/dist/categories.min.js
create mode 100644 assets/js/dist/home.min.js
create mode 100644 assets/js/dist/page.min.js
create mode 100644 assets/js/dist/post.min.js
create mode 100644 assets/js/dist/pvreport.min.js
delete mode 100644 assets/js/home.min.js
delete mode 100644 assets/js/lib/_bootstrap-toc.min.js
delete mode 100644 assets/js/lib/_countUp.min.js
delete mode 100644 assets/js/page.min.js
delete mode 100644 assets/js/post.min.js
create mode 100644 gulpfile.js/index.js
create mode 100644 gulpfile.js/tasks/js.js
create mode 100644 package.json
diff --git a/.gitignore b/.gitignore
index ed798ee..2cc94c7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,7 @@
# jekyll cache
_site
vendor
+
+# npm dependencies
+node_modules
+package-lock.json
diff --git a/_config.yml b/_config.yml
index a789a72..c0c6961 100644
--- a/_config.yml
+++ b/_config.yml
@@ -194,6 +194,10 @@ exclude:
- docs
- README.md
- LICENSE
+ - gulpfile.js
+ - node_modules
+ - package.json
+ - package-lock.json
jekyll-archives:
enabled: [categories, tags]
diff --git a/_includes/disqus.html b/_includes/disqus.html
index a750c27..7115bf1 100644
--- a/_includes/disqus.html
+++ b/_includes/disqus.html
@@ -1,6 +1,6 @@
+
+ {% endif %}
{% endif %}
-{% assign js_src = js | prepend: '/assets/js/' | append: '.min.js' | relative_url %}
+{% if page.layout == 'home'
+ or page.layout == 'post'
+ or page.layout == 'categories' %}
+ {% assign type = page.layout %}
+{% else %}
+ {% assign type = "page" %}
+{% endif %}
-
+{% assign js = type | prepend: '/assets/js/dist/' | append: '.min.js' %}
+
{% if page.math %}
diff --git a/_includes/mermaid.html b/_includes/mermaid.html
index 2cb5cc6..063d950 100644
--- a/_includes/mermaid.html
+++ b/_includes/mermaid.html
@@ -1,7 +1,8 @@
-
+
+
{{- site.data.label.panel.toc -}}
diff --git a/assets/js/_commons.js b/assets/js/_commons.js
deleted file mode 100644
index d482ee5..0000000
--- a/assets/js/_commons.js
+++ /dev/null
@@ -1,23 +0,0 @@
-/*!
- Aggregation of common JS.
- Chirpy@2.3
- https://github.com/cotes2020/jekyll-theme-chirpy
- © 2020 Cotes Chung
- MIT License
-*/
-
-{% include_relative _commons/back-to-top.js %}
-
-{% include_relative _commons/search-display.js %}
-
-{% include_relative _commons/sidebar.js %}
-
-{% include_relative _commons/topbar-switch.js %}
-
-{% include_relative _commons/topbar-title.js %}
-
-{% include_relative _commons/copy-link.js %}
-
-{% include_relative _commons/checkbox.js %}
-
-{% include_relative _utils/tooltip-loader.js %}
diff --git a/assets/js/_commons/copy-link.js b/assets/js/_commons/copy-link.js
index 5a9c100..fc65d2b 100644
--- a/assets/js/_commons/copy-link.js
+++ b/assets/js/_commons/copy-link.js
@@ -10,8 +10,8 @@ function copyLink(url) {
if (!url || 0 === url.length) {
url = window.location.href;
}
-
- var $temp = $("");
+
+ const $temp = $("");
$("body").append($temp);
$temp.val(url).select();
document.execCommand("copy");
diff --git a/assets/js/_commons/search-display.js b/assets/js/_commons/search-display.js
index a5955dc..4fd29ac 100644
--- a/assets/js/_commons/search-display.js
+++ b/assets/js/_commons/search-display.js
@@ -8,24 +8,24 @@
$(function() {
- var btnSbTrigger = $("#sidebar-trigger");
- var btnSearchTrigger = $("#search-trigger");
- var btnCancel = $("#search-cancel");
- var btnClear = $("#search-cleaner");
+ const btnSbTrigger = $("#sidebar-trigger");
+ const btnSearchTrigger = $("#search-trigger");
+ const btnCancel = $("#search-cancel");
+ const btnClear = $("#search-cleaner");
- var main = $("#main");
- var topbarTitle = $("#topbar-title");
- var searchWrapper = $("#search-wrapper");
- var resultWrapper = $("#search-result-wrapper");
- var results = $("#search-results");
- var input = $("#search-input");
- var hints = $("#search-hints");
+ const main = $("#main");
+ const topbarTitle = $("#topbar-title");
+ const searchWrapper = $("#search-wrapper");
+ const resultWrapper = $("#search-result-wrapper");
+ const results = $("#search-results");
+ const input = $("#search-input");
+ const hints = $("#search-hints");
/*--- Actions in small screens (Sidebar unloaded) ---*/
- var scrollBlocker = (function() {
- var offset = 0;
+ const scrollBlocker = (function () {
+ let offset = 0;
return {
block() {
offset = $(window).scrollTop();
@@ -39,7 +39,7 @@ $(function() {
};
}());
- var mobileSearchBar = (function() {
+ const mobileSearchBar = (function () {
return {
on() {
btnSbTrigger.addClass("unloaded");
@@ -58,21 +58,21 @@ $(function() {
};
}());
- var resultSwitch = (function() {
- var visable = false;
+ const resultSwitch = (function () {
+ let visible = false;
return {
on() {
- if (!visable) {
+ if (!visible) {
resultWrapper.removeClass("unloaded");
main.addClass("hidden");
- visable = true;
+ visible = true;
scrollBlocker.block();
}
},
off() {
- if (visable) {
+ if (visible) {
results.empty();
if (hints.hasClass("unloaded")) {
hints.removeClass("unloaded");
@@ -82,13 +82,13 @@ $(function() {
main.removeClass("hidden");
input.val("");
- visable = false;
+ visible = false;
scrollBlocker.release();
}
},
- isVisable() {
- return visable;
+ isVisible() {
+ return visible;
}
};
diff --git a/assets/js/_commons/sidebar.js b/assets/js/_commons/sidebar.js
index 44bf3f4..2aca1ed 100644
--- a/assets/js/_commons/sidebar.js
+++ b/assets/js/_commons/sidebar.js
@@ -8,10 +8,10 @@
$(function() {
- var sidebarUtil = (function() {
+ const sidebarUtil = (function () {
const ATTR_DISPLAY = "sidebar-display";
- var isExpanded = false;
- var body = $("body");
+ let isExpanded = false;
+ const body = $("body");
return {
toggle() {
diff --git a/assets/js/_utils/tooltip-loader.js b/assets/js/_commons/tooltip-loader.js
similarity index 100%
rename from assets/js/_utils/tooltip-loader.js
rename to assets/js/_commons/tooltip-loader.js
diff --git a/assets/js/_commons/topbar-switch.js b/assets/js/_commons/topbar-switch.js
index 0f915bb..2a4d20f 100644
--- a/assets/js/_commons/topbar-switch.js
+++ b/assets/js/_commons/topbar-switch.js
@@ -8,10 +8,16 @@
$(function() {
- var didScroll;
- var lastScrollTop = 0;
- var delta = 5;
- var topbarHeight = $("#topbar-wrapper").outerHeight();
+ const topbarWrapper = $("#topbar-wrapper");
+ const toc = $("#toc-wrapper");
+ const access = $(".access");
+ const searchInput = $("#search-input");
+
+ let didScroll;
+ let lastScrollTop = 0;
+
+ const delta = 5;
+ const topbarHeight = topbarWrapper.outerHeight();
function hasScrolled() {
var st = $(this).scrollTop();
@@ -23,30 +29,28 @@ $(function() {
if (st > lastScrollTop && st > topbarHeight) {
/* Scroll Down */
- $("#topbar-wrapper").removeClass("topbar-down").addClass("topbar-up");
+ topbarWrapper.removeClass("topbar-down").addClass("topbar-up");
- if ($("#toc-wrapper").length > 0) {
- $("#toc-wrapper").removeClass("topbar-down");
+ if (toc.length > 0) {
+ toc.removeClass("topbar-down");
}
- if ($(".access").length > 0) {
- $(".access").removeClass("topbar-down");
+ if (access.length > 0) {
+ access.removeClass("topbar-down");
}
- if ($("#search-input").is(":focus")) {
- $("#search-input").blur(); /* remove focus */
+ if (searchInput.is(":focus")) {
+ searchInput.blur(); /* remove focus */
}
- } else {
+ } else if (st + $(window).height() < $(document).height()) {
/* Scroll Up */
- if (st + $(window).height() < $(document).height()) {
- $("#topbar-wrapper").removeClass("topbar-up").addClass("topbar-down");
- if ($("#toc-wrapper").length > 0) {
- $("#toc-wrapper").addClass("topbar-down");
- }
- if ($(".access").length > 0) {
- $(".access").addClass("topbar-down");
- }
+ topbarWrapper.removeClass("topbar-up").addClass("topbar-down");
+ if (toc.length > 0) {
+ toc.addClass("topbar-down");
+ }
+ if (access.length > 0) {
+ access.addClass("topbar-down");
}
}
@@ -66,4 +70,4 @@ $(function() {
}
}, 250);
-});
\ No newline at end of file
+});
diff --git a/assets/js/_commons/topbar-title.js b/assets/js/_commons/topbar-title.js
index dc39ae4..aca3b05 100644
--- a/assets/js/_commons/topbar-title.js
+++ b/assets/js/_commons/topbar-title.js
@@ -1,5 +1,5 @@
/*
- * Topbar title auto change while scrolling in mobile screens.
+ * Top bar title auto change while scrolling in mobile screens.
* v2.0
* https://github.com/cotes2020/jekyll-theme-chirpy
* © 2018-2019 Cotes Chung
@@ -8,9 +8,13 @@
$(function() {
- var DEFAULT = $("#topbar-title").text().trim();
- var title = ($("div.post>h1").length > 0) ?
- $("div.post>h1").text().trim() : $("h1").text().trim();
+ const topbarTitle = $("#topbar-title");
+ const postTitle = $("div.post>h1");
+
+ const DEFAULT = topbarTitle.text().trim();
+
+ let title = (postTitle.length > 0) ?
+ postTitle.text().trim() : $("h1").text().trim();
if ($("#page-category").length || $("#page-tag").length) {
/* The title in Category or Tag page will be " " */
@@ -22,26 +26,26 @@ $(function() {
/* Replace topbar title while scroll screens. */
$(window).scroll(function () {
if ($("#post-list").length /* in Home page */
- || $("div.post>h1").is(":hidden") /* is tab pages */
- || $("#topbar-title").is(":hidden") /* not mobile screens */
+ || postTitle.is(":hidden") /* is tab pages */
+ || topbarTitle.is(":hidden") /* not mobile screens */
|| $("#sidebar.sidebar-expand").length) { /* when the sidebar trigger is clicked */
return false;
}
if ($(this).scrollTop() >= 95) {
- if ($("#topbar-title").text() !== title) {
- $("#topbar-title").text(title);
+ if (topbarTitle.text() !== title) {
+ topbarTitle.text(title);
}
} else {
- if ($("#topbar-title").text() !== DEFAULT) {
- $("#topbar-title").text(DEFAULT);
+ if (topbarTitle.text() !== DEFAULT) {
+ topbarTitle.text(DEFAULT);
}
}
});
/* Click title remove hover effect. */
- $("#topbar-title").click(function() {
+ topbarTitle.click(function() {
$("body,html").animate({scrollTop: 0}, 800);
});
-});
\ No newline at end of file
+});
diff --git a/assets/js/_home-post.js b/assets/js/_home-post.js
deleted file mode 100644
index c802777..0000000
--- a/assets/js/_home-post.js
+++ /dev/null
@@ -1,22 +0,0 @@
-/*!
- JS group for layout Home or Post
- Chirpy v2.3
- https://github.com/cotes2020/jekyll-theme-chirpy
- © 2020 Cotes Chung
- MIT License
-*/
-
-{% include_relative _commons.js %}
-
-{% include_relative _utils/timeago.js %}
-
-
-{% if site.google_analytics.pv.enabled %}
-
- {% include_relative _pv-config.js %}
-
- {% include_relative _utils/pageviews.js %}
-
- {% include_relative lib/_countUp.min.js %}
-
-{% endif %}
diff --git a/assets/js/_pv-config.js b/assets/js/_pv-config.js
deleted file mode 100644
index f560273..0000000
--- a/assets/js/_pv-config.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/*!
- PV configuration and Javascript conversion.
-*/
-
-const proxyEndpoint = "{{ site.google_analytics.pv.proxy_endpoint }}";
-
-
-{% if site.google_analytics.pv.cache and site.google_analytics.pv.enabled %}
- {% assign enabled = true %}
-{% else %}
- {% assign enabled = false %}
-{% endif %}
-
-const pvCacheEnabled = {{ enabled }};
-
-const pvCacheData = "{{ '/assets/js/data/pageviews.json' | relative_url }}";
diff --git a/assets/js/_utils/category-collapse.js b/assets/js/_utils/category-collapse.js
index 71080b6..d8c8a3d 100644
--- a/assets/js/_utils/category-collapse.js
+++ b/assets/js/_utils/category-collapse.js
@@ -7,27 +7,28 @@
*/
$(function() {
- var childPrefix = "l_";
- var parentPrefix = "h_";
+ const childPrefix = "l_";
+ const parentPrefix = "h_";
+ const collapse = $(".collapse");
/* close up top-category */
- $(".collapse").on("hide.bs.collapse", function() { /* Bootstrap collapse events. */
- var parentId = parentPrefix + $(this).attr("id").substring(childPrefix.length);
+ collapse.on("hide.bs.collapse", function () { /* Bootstrap collapse events. */
+ const parentId = parentPrefix + $(this).attr("id").substring(childPrefix.length);
if (parentId) {
- $("#" + parentId + " .far.fa-folder-open").attr("class", "far fa-folder fa-fw");
- $("#" + parentId + " i.fas").addClass("rotate");
- $("#" + parentId).removeClass("hide-border-bottom");
+ $(`#${parentId} .far.fa-folder-open`).attr("class", "far fa-folder fa-fw");
+ $(`#${parentId} i.fas`).addClass("rotate");
+ $(`#${parentId}`).removeClass("hide-border-bottom");
}
});
/* expand the top category */
- $(".collapse").on("show.bs.collapse", function() {
- var parentId = parentPrefix + $(this).attr("id").substring(childPrefix.length);
+ collapse.on("show.bs.collapse", function() {
+ const parentId = parentPrefix + $(this).attr("id").substring(childPrefix.length);
if (parentId) {
- $("#" + parentId + " .far.fa-folder").attr("class", "far fa-folder-open fa-fw");
- $("#" + parentId + " i.fas").removeClass("rotate");
- $("#" + parentId).addClass("hide-border-bottom");
+ $(`#${parentId} .far.fa-folder`).attr("class", "far fa-folder-open fa-fw");
+ $(`#${parentId} i.fas`).removeClass("rotate");
+ $(`#${parentId}`).addClass("hide-border-bottom");
}
});
-});
\ No newline at end of file
+});
diff --git a/assets/js/_utils/img-hyperlink.js b/assets/js/_utils/img-hyperlink.js
index c910af0..df38d05 100644
--- a/assets/js/_utils/img-hyperlink.js
+++ b/assets/js/_utils/img-hyperlink.js
@@ -8,9 +8,6 @@
*/
$(function() {
-
- var MARK="img-hyperlink";
-
+ const MARK = "img-hyperlink";
$("a:has(img)").addClass(MARK);
-
});
diff --git a/assets/js/_utils/lang-badge.js b/assets/js/_utils/lang-badge.js
index 845721a..bad815d 100644
--- a/assets/js/_utils/lang-badge.js
+++ b/assets/js/_utils/lang-badge.js
@@ -7,11 +7,11 @@ $(function() {
const regex = new RegExp(`^${prefix}([a-z])+$`);
$(`div[class^=${prefix}`).each(function() {
- let clzsses = $(this).attr("class").split(" ");
+ let classes = $(this).attr("class").split(" ");
- clzsses.forEach((clzss) => {
- if (regex.test(clzss)) {
- let lang = clzss.substring(prefix.length);
+ classes.forEach((_class) => {
+ if (regex.test(_class)) {
+ let lang = _class.substring(prefix.length);
$(this).attr("lang", `${lang}`);
}
});
diff --git a/assets/js/_utils/pageviews.js b/assets/js/_utils/pageviews.js
index 5cb0201..4a64c78 100644
--- a/assets/js/_utils/pageviews.js
+++ b/assets/js/_utils/pageviews.js
@@ -1,7 +1,7 @@
/**
- * Count pageviews form GA or local cache file.
+ * Count page views form GA or local cache file.
*
- * Dependences:
+ * Dependencies:
* - jQuery
* - countUp.js
*
@@ -11,8 +11,8 @@
* MIT License
*/
-var getInitStatus = (function () {
- var hasInit = false;
+const getInitStatus = (function () {
+ let hasInit = false;
return () => {
let ret = hasInit;
if (!hasInit) {
@@ -22,13 +22,26 @@ var getInitStatus = (function () {
};
}());
+const PvOpts = (function () {
+ return {
+ isEnabled() {
+ return "true" === $("meta[name=pv-cache-enabled]").attr("content");
+ },
+ getProxyEndpoint() {
+ return $("meta[name=pv-proxy-endpoint]").attr("content");
+ },
+ getLocalData() {
+ return $("meta[name=pv-cache-data]").attr("content");
+ }
+ }
+}());
-var PvCache = (function () {
+const PvCache = (function () {
const KEY_PV = "pv";
const KEY_CREATION = "pv_created_date";
const KEY_PV_SRC = "pv_source";
- var Source = {
+ const Source = {
ORIGIN: "origin",
PROXY: "proxy"
};
@@ -43,17 +56,18 @@ var PvCache = (function () {
return {
getData() {
- return JSON.parse(localStorage.getItem(KEY_PV) );
+ // get data from browser cache
+ return JSON.parse(localStorage.getItem(KEY_PV));
},
saveOriginCache(pv) {
set(KEY_PV, pv);
- set(KEY_PV_SRC, Source.ORIGIN );
- set(KEY_CREATION, new Date().toJSON() );
+ set(KEY_PV_SRC, Source.ORIGIN);
+ set(KEY_CREATION, new Date().toJSON());
},
saveProxyCache(pv) {
set(KEY_PV, pv);
- set(KEY_PV_SRC, Source.PROXY );
- set(KEY_CREATION, new Date().toJSON() );
+ set(KEY_PV_SRC, Source.PROXY);
+ set(KEY_CREATION, new Date().toJSON());
},
isFromOrigin() {
return get(KEY_PV_SRC) === Source.ORIGIN;
@@ -62,23 +76,23 @@ var PvCache = (function () {
return get(KEY_PV_SRC) === Source.PROXY;
},
isExpired() {
- if (PvCache.isFromOrigin() ) {
+ if (PvCache.isFromOrigin()) {
let date = new Date(get(KEY_CREATION));
date.setDate(date.getDate() + 1); /* update origin records every day */
return Date.now() >= date.getTime();
- } else if (PvCache.isFromProxy() ) {
- let date = new Date(get(KEY_CREATION) );
+ } else if (PvCache.isFromProxy()) {
+ let date = new Date(get(KEY_CREATION));
date.setHours(date.getHours() + 1); /* update proxy records per hour */
return Date.now() >= date.getTime();
}
return false;
},
- getAllPagevies() {
+ getAllPageviews() {
return PvCache.getData().totalsForAllResults["ga:pageviews"];
},
newerThan(pv) {
- return PvCache.getAllPagevies() > pv.totalsForAllResults["ga:pageviews"];
+ return PvCache.getAllPageviews() > pv.totalsForAllResults["ga:pageviews"];
},
inspectKeys() {
if (localStorage.getItem(KEY_PV) === null
@@ -91,9 +105,10 @@ var PvCache = (function () {
}()); /* PvCache */
+
function countUp(min, max, destId) {
if (min < max) {
- var numAnim = new CountUp(destId, min, max);
+ let numAnim = new CountUp(destId, min, max);
if (!numAnim.error) {
numAnim.start();
} else {
@@ -104,11 +119,11 @@ function countUp(min, max, destId) {
function countPV(path, rows) {
- var count = 0;
+ let count = 0;
if (typeof rows !== "undefined" ) {
- for (var i = 0; i < rows.length; ++i) {
- var gaPath = rows[parseInt(i, 10)][0];
+ for (let i = 0; i < rows.length; ++i) {
+ const gaPath = rows[parseInt(i, 10)][0];
if (gaPath === path) { /* path format see: site.permalink */
count += parseInt(rows[parseInt(i, 10)][1], 10);
break;
@@ -121,13 +136,13 @@ function countPV(path, rows) {
function tacklePV(rows, path, elem, hasInit) {
- var count = countPV(path, rows);
+ let count = countPV(path, rows);
count = (count === 0 ? 1 : count);
if (!hasInit) {
elem.text(new Intl.NumberFormat().format(count));
} else {
- var initCount = parseInt(elem.text().replace(/,/g, ""), 10);
+ const initCount = parseInt(elem.text().replace(/,/g, ""), 10);
if (count > initCount) {
countUp(initCount, count, elem.attr("id"));
}
@@ -140,17 +155,17 @@ function displayPageviews(data) {
return;
}
- var hasInit = getInitStatus();
- var rows = data.rows; /* could be undefined */
+ let hasInit = getInitStatus();
+ const rows = data.rows; /* could be undefined */
if ($("#post-list").length > 0) { /* the Home page */
$(".post-preview").each(function() {
- var path = $(this).find("a").attr("href");
+ const path = $(this).find("a").attr("href");
tacklePV(rows, path, $(this).find(".pageviews"), hasInit);
});
} else if ($(".post").length > 0) { /* the post */
- var path = window.location.pathname;
+ const path = window.location.pathname;
tacklePV(rows, path, $("#pv"), hasInit);
}
}
@@ -159,7 +174,7 @@ function displayPageviews(data) {
function fetchProxyPageviews() {
$.ajax({
type: "GET",
- url: proxyEndpoint, /* see: /assets/js/_pv-config.js */
+ url: PvOpts.getProxyEndpoint(),
dataType: "jsonp",
jsonpCallback: "displayPageviews",
success: (data, textStatus, jqXHR) => {
@@ -173,9 +188,8 @@ function fetchProxyPageviews() {
function fetchPageviews(fetchOrigin = true, filterOrigin = false) {
- /* pvCacheEnabled, pvCacheData › see: /assets/js/_pv-config.js */
- if (pvCacheEnabled && fetchOrigin) {
- fetch(pvCacheData)
+ if (PvOpts.isEnabled() && fetchOrigin) {
+ fetch(PvOpts.getLocalData())
.then((response) => response.json())
.then((data) => {
if (filterOrigin) {
@@ -196,9 +210,7 @@ function fetchPageviews(fetchOrigin = true, filterOrigin = false) {
$(function() {
-
if ($(".pageviews").length > 0) {
-
PvCache.inspectKeys();
let cache = PvCache.getData();
diff --git a/assets/js/_utils/smooth-scroll.js b/assets/js/_utils/smooth-scroll.js
index 7516212..57adac2 100644
--- a/assets/js/_utils/smooth-scroll.js
+++ b/assets/js/_utils/smooth-scroll.js
@@ -1,6 +1,6 @@
/*
Safari doesn't support CSS `scroll-behavior: smooth`,
- so here is a compatible sollution for all browser to smooth scrolling
+ so here is a compatible solution for all browser to smooth scrolling
See:
@@ -13,66 +13,67 @@ $(function() {
.not("[href='#0']")
.click(function(event) {
- if (location.pathname.replace(/^\//, "") === this.pathname.replace(/^\//, "")
- && location.hostname === this.hostname) {
+ if (this.pathname.replace(/^\//, "") === location.pathname.replace(/^\//, "")) {
+ if (location.hostname === this.hostname) {
- const REM = 16; /* 16px */
+ const REM = 16; /* 16px */
- const hash = decodeURI(this.hash);
- let isFnRef = RegExp(/^#fnref:/).test(hash);
- let isFn = RegExp(/^#fn:/).test(hash);
- let selector = hash.includes(":") ? hash.replace(/\:/, "\\:") : hash;
- const target = $(selector);
+ const hash = decodeURI(this.hash);
+ let isFnRef = RegExp(/^#fnref:/).test(hash);
+ let isFn = RegExp(/^#fn:/).test(hash);
+ let selector = hash.includes(":") ? hash.replace(/\:/, "\\:") : hash;
+ let target = $(selector);
- if (target.length) {
- event.preventDefault();
+ if (target.length) {
+ event.preventDefault();
- if (history.pushState) { /* add hash to URL */
- history.pushState(null, null, hash);
+ if (history.pushState) { /* add hash to URL */
+ history.pushState(null, null, hash);
+ }
+
+ let curOffset = $(this).offset().top;
+ let destOffset = target.offset().top;
+ const scrollUp = (destOffset < curOffset);
+ const topbarHeight = $("#topbar-wrapper").outerHeight();
+
+ if (scrollUp && isFnRef) {
+ /* Avoid the top-bar covering `fnref` when scrolling up
+ because `fnref` has no `%anchor`(see: module.scss) style. */
+ destOffset -= (topbarHeight + REM / 2);
+ }
+
+ $("html,body").animate({
+ scrollTop: destOffset
+ }, 800, () => {
+
+ const $target = $(target);
+ $target.focus();
+
+ const SCROLL_MARK = "scroll-focus";
+
+ /* clean up old scroll mark */
+ if ($(`[${SCROLL_MARK}=true]`).length) {
+ $(`[${SCROLL_MARK}=true]`).attr(SCROLL_MARK, false);
+ }
+
+ /* Clean :target links */
+ if ($(":target").length) { /* element that visited by the URL with hash */
+ $(":target").attr(SCROLL_MARK, false);
+ }
+
+ /* set scroll mark to footnotes */
+ if (isFn || isFnRef) {
+ $target.attr(SCROLL_MARK, true);
+ }
+
+ if ($target.is(":focus")) { /* Checking if the target was focused */
+ return false;
+ } else {
+ $target.attr("tabindex", "-1"); /* Adding tabindex for elements not focusable */
+ $target.focus(); /* Set focus again */
+ }
+ });
}
-
- let curOffset = $(this).offset().top;
- let destOffset = target.offset().top;
- const scrollUp = (destOffset < curOffset);
- const topbarHeight = $("#topbar-wrapper").outerHeight();
-
- if (scrollUp && isFnRef) {
- /* Avoid the top-bar covering `fnref` when scrolling up
- because `fnref` has no `%anchor`(see: module.scss) style. */
- destOffset -= (topbarHeight + REM / 2);
- }
-
- $("html,body").animate({
- scrollTop: destOffset
- }, 800, () => {
-
- var $target = $(target);
- $target.focus();
-
- const SCROLL_MARK = "scroll-focus";
-
- /* clean up old scroll mark */
- if ($(`[${ SCROLL_MARK }=true]`).length) {
- $(`[${ SCROLL_MARK }=true]`).attr(SCROLL_MARK, false);
- }
-
- /* Clean :target links */
- if ($(":target").length) { /* element that visited by the URL with hash */
- $(":target").attr(SCROLL_MARK, false);
- }
-
- /* set scroll mark to footnotes */
- if (isFn || isFnRef) {
- $target.attr(SCROLL_MARK, true);
- }
-
- if ($target.is(":focus")) { /* Checking if the target was focused */
- return false;
- } else {
- $target.attr("tabindex", "-1"); /* Adding tabindex for elements not focusable */
- $target.focus(); /* Set focus again */
- }
- });
}
}
diff --git a/assets/js/_utils/timeago.js b/assets/js/_utils/timeago.js
index f98c706..0e2f49e 100644
--- a/assets/js/_utils/timeago.js
+++ b/assets/js/_utils/timeago.js
@@ -1,5 +1,5 @@
/*
- * Caculate the Timeago
+ * Calculate the Timeago
* v2.0
* https://github.com/cotes2020/jekyll-theme-chirpy
* © 2019 Cotes Chung
@@ -8,9 +8,11 @@
$(function() {
- var toRefresh = $(".timeago").length;
+ const timeagoElem = $(".timeago");
- var intervalId = void 0;
+ let toRefresh = timeagoElem.length;
+
+ let intervalId = void 0;
function timeago(iso, isLastmod) {
let now = new Date();
@@ -57,10 +59,10 @@ $(function() {
function updateTimeago() {
$(".timeago").each(function() {
if ($(this).children("i").length > 0) {
- var basic = $(this).text();
- var isLastmod = $(this).hasClass("lastmod");
- var node = $(this).children("i");
- var date = node.text(); /* ISO Date: "YYYY-MM-DDTHH:MM:SSZ" */
+ $(this).text();
+ let isLastmod = $(this).hasClass("lastmod");
+ let node = $(this).children("i");
+ let date = node.text(); /* ISO Date: "YYYY-MM-DDTHH:MM:SSZ" */
$(this).text(timeago(date, isLastmod));
$(this).append(node);
}
diff --git a/assets/js/categories.min.js b/assets/js/categories.min.js
deleted file mode 100644
index c8230eb..0000000
--- a/assets/js/categories.min.js
+++ /dev/null
@@ -1,13 +0,0 @@
----
-layout: compress
-
-# JS for layout tab Categories.
-# Chirpy v2.3
-# https://github.com/cotes2020/jekyll-theme-chirpy
-# © 2020 Cotes Chung
-# MIT License
----
-
-{% include_relative _commons.js %}
-
-{% include_relative _utils/category-collapse.js %}
diff --git a/assets/js/data/cache-list.js b/assets/js/data/cache-list.js
index a5001b1..27997ec 100644
--- a/assets/js/data/cache-list.js
+++ b/assets/js/data/cache-list.js
@@ -11,22 +11,13 @@ layout: compress
const include = [
/*--- CSS ---*/
-
- '{{ "/assets/css/home.css" | relative_url }}',
- '{{ "/assets/css/categories.css" | relative_url }}',
- '{{ "/assets/css/tags.css" | relative_url }}',
- '{{ "/assets/css/archives.css" | relative_url }}',
- '{{ "/assets/css/page.css" | relative_url }}',
- '{{ "/assets/css/post.css" | relative_url }}',
- '{{ "/assets/css/category-tag.css" | relative_url }}',
- '{{ "/assets/css/lib/bootstrap-toc.min.css" | relative_url }}',
+ '{{ "/assets/css/style.css" | relative_url }}',
/*--- Javascripts ---*/
-
- '{{ "/assets/js/home.min.js" | relative_url }}',
- '{{ "/assets/js/page.min.js" | relative_url }}',
- '{{ "/assets/js/post.min.js" | relative_url }}',
- '{{ "/assets/js/categories.min.js" | relative_url }}',
+ '{{ "/assets/js/dist/home.min.js" | relative_url }}',
+ '{{ "/assets/js/dist/page.min.js" | relative_url }}',
+ '{{ "/assets/js/dist/post.min.js" | relative_url }}',
+ '{{ "/assets/js/dist/categories.min.js" | relative_url }}',
/*--- HTML ---*/
diff --git a/assets/js/dist/categories.min.js b/assets/js/dist/categories.min.js
new file mode 100644
index 0000000..f84862b
--- /dev/null
+++ b/assets/js/dist/categories.min.js
@@ -0,0 +1 @@
+function copyLink(e){e&&0!==e.length||(e=window.location.href);const o=$("");$("body").append(o),o.val(e).select(),document.execCommand("copy"),o.remove(),alert("Link copied successfully!")}$(function(){$(window).scroll(()=>{$(this).scrollTop()>50&&"none"===$("#sidebar-trigger").css("display")?$("#back-to-top").fadeIn():$("#back-to-top").fadeOut()}),$("#back-to-top").click(()=>($("body,html").animate({scrollTop:0},800),!1))}),$(function(){$("input[type=checkbox]").addClass("unloaded"),$("input[type=checkbox][checked]").before(''),$("input[type=checkbox]:not([checked])").before('')}),$(function(){const e=$("#sidebar-trigger"),o=$("#search-trigger"),s=$("#search-cancel"),t=$("#search-cleaner"),a=$("#main"),l=$("#topbar-title"),n=$("#search-wrapper"),d=$("#search-result-wrapper"),r=$("#search-results"),c=$("#search-input"),i=$("#search-hints"),f=function(){let e=0;return{block(){e=$(window).scrollTop()},release(){$("html,body").scrollTop(e)},getOffset:()=>e}}(),u={on(){e.addClass("unloaded"),l.addClass("unloaded"),o.addClass("unloaded"),n.addClass("d-flex"),s.addClass("loaded")},off(){s.removeClass("loaded"),n.removeClass("d-flex"),e.removeClass("unloaded"),l.removeClass("unloaded"),o.removeClass("unloaded")}},p=function(){let e=!1;return{on(){e||(d.removeClass("unloaded"),a.addClass("hidden"),e=!0,f.block())},off(){e&&(r.empty(),i.hasClass("unloaded")&&i.removeClass("unloaded"),d.addClass("unloaded"),t.removeClass("visible"),a.removeClass("hidden"),c.val(""),e=!1,f.release())},isVisible:()=>e}}();function h(){return s.hasClass("loaded")}o.click(function(){u.on(),p.on(),c.focus()}),s.click(function(){u.off(),p.off()}),c.focus(function(){n.addClass("input-focus")}),c.focusout(function(){n.removeClass("input-focus")}),c.on("keyup",function(e){8===e.keyCode&&""===c.val()?h()?i.removeClass("unloaded"):p.off():""!==c.val()&&(p.on(),t.hasClass("visible")||t.addClass("visible"),h()&&i.addClass("unloaded"))}),t.on("click",function(){c.val(""),h()?(i.removeClass("unloaded"),r.empty()):p.off(),c.focus(),t.removeClass("visible")})}),$(function(){const e=function(){let e=!1;const o=$("body");return{toggle(){!1===e?o.attr("sidebar-display",""):o.removeAttr("sidebar-display"),e=!e}}}();$("#sidebar-trigger").click(e.toggle),$("#mask").click(e.toggle)}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(function(){const e=$("#topbar-wrapper"),o=$("#toc-wrapper"),s=$(".access"),t=$("#search-input");let a,l=0;const n=5,d=e.outerHeight();$(window).scroll(function(e){$("#topbar-title").is(":hidden")&&(a=!0)}),setInterval(function(){a&&(!function(){var a=$(this).scrollTop();Math.abs(l-a)<=n||(a>l&&a>d?(e.removeClass("topbar-down").addClass("topbar-up"),o.length>0&&o.removeClass("topbar-down"),s.length>0&&s.removeClass("topbar-down"),t.is(":focus")&&t.blur()):a+$(window).height()<$(document).height()&&(e.removeClass("topbar-up").addClass("topbar-down"),o.length>0&&o.addClass("topbar-down"),s.length>0&&s.addClass("topbar-down")),l=a)}(),a=!1)},250)}),$(function(){const e=$("#topbar-title"),o=$("div.post>h1"),s=e.text().trim();let t=o.length>0?o.text().trim():$("h1").text().trim();($("#page-category").length||$("#page-tag").length)&&/\s/.test(t)&&(t=t.replace(/[0-9]/g,"").trim()),$(window).scroll(function(){if($("#post-list").length||o.is(":hidden")||e.is(":hidden")||$("#sidebar.sidebar-expand").length)return!1;$(this).scrollTop()>=95?e.text()!==t&&e.text(t):e.text()!==s&&e.text(s)}),e.click(function(){$("body,html").animate({scrollTop:0},800)})}),$(function(){const e=$(".collapse");e.on("hide.bs.collapse",function(){const e="h_"+$(this).attr("id").substring("l_".length);e&&($(`#${e} .far.fa-folder-open`).attr("class","far fa-folder fa-fw"),$(`#${e} i.fas`).addClass("rotate"),$(`#${e}`).removeClass("hide-border-bottom"))}),e.on("show.bs.collapse",function(){const e="h_"+$(this).attr("id").substring("l_".length);e&&($(`#${e} .far.fa-folder`).attr("class","far fa-folder-open fa-fw"),$(`#${e} i.fas`).removeClass("rotate"),$(`#${e}`).addClass("hide-border-bottom"))})});
\ No newline at end of file
diff --git a/assets/js/dist/home.min.js b/assets/js/dist/home.min.js
new file mode 100644
index 0000000..dad56ca
--- /dev/null
+++ b/assets/js/dist/home.min.js
@@ -0,0 +1 @@
+function copyLink(e){e&&0!==e.length||(e=window.location.href);const t=$("");$("body").append(t),t.val(e).select(),document.execCommand("copy"),t.remove(),alert("Link copied successfully!")}$(function(){$(window).scroll(()=>{$(this).scrollTop()>50&&"none"===$("#sidebar-trigger").css("display")?$("#back-to-top").fadeIn():$("#back-to-top").fadeOut()}),$("#back-to-top").click(()=>($("body,html").animate({scrollTop:0},800),!1))}),$(function(){$("input[type=checkbox]").addClass("unloaded"),$("input[type=checkbox][checked]").before(''),$("input[type=checkbox]:not([checked])").before('')}),$(function(){const e=$("#sidebar-trigger"),t=$("#search-trigger"),o=$("#search-cancel"),a=$("#search-cleaner"),s=$("#main"),n=$("#topbar-title"),l=$("#search-wrapper"),i=$("#search-result-wrapper"),r=$("#search-results"),c=$("#search-input"),d=$("#search-hints"),u=function(){let e=0;return{block(){e=$(window).scrollTop()},release(){$("html,body").scrollTop(e)},getOffset:()=>e}}(),h={on(){e.addClass("unloaded"),n.addClass("unloaded"),t.addClass("unloaded"),l.addClass("d-flex"),o.addClass("loaded")},off(){o.removeClass("loaded"),l.removeClass("d-flex"),e.removeClass("unloaded"),n.removeClass("unloaded"),t.removeClass("unloaded")}},f=function(){let e=!1;return{on(){e||(i.removeClass("unloaded"),s.addClass("hidden"),e=!0,u.block())},off(){e&&(r.empty(),d.hasClass("unloaded")&&d.removeClass("unloaded"),i.addClass("unloaded"),a.removeClass("visible"),s.removeClass("hidden"),c.val(""),e=!1,u.release())},isVisible:()=>e}}();function p(){return o.hasClass("loaded")}t.click(function(){h.on(),f.on(),c.focus()}),o.click(function(){h.off(),f.off()}),c.focus(function(){l.addClass("input-focus")}),c.focusout(function(){l.removeClass("input-focus")}),c.on("keyup",function(e){8===e.keyCode&&""===c.val()?p()?d.removeClass("unloaded"):f.off():""!==c.val()&&(f.on(),a.hasClass("visible")||a.addClass("visible"),p()&&d.addClass("unloaded"))}),a.on("click",function(){c.val(""),p()?(d.removeClass("unloaded"),r.empty()):f.off(),c.focus(),a.removeClass("visible")})}),$(function(){const e=function(){let e=!1;const t=$("body");return{toggle(){!1===e?t.attr("sidebar-display",""):t.removeAttr("sidebar-display"),e=!e}}}();$("#sidebar-trigger").click(e.toggle),$("#mask").click(e.toggle)}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(function(){const e=$("#topbar-wrapper"),t=$("#toc-wrapper"),o=$(".access"),a=$("#search-input");let s,n=0;const l=5,i=e.outerHeight();$(window).scroll(function(e){$("#topbar-title").is(":hidden")&&(s=!0)}),setInterval(function(){s&&(!function(){var s=$(this).scrollTop();Math.abs(n-s)<=l||(s>n&&s>i?(e.removeClass("topbar-down").addClass("topbar-up"),t.length>0&&t.removeClass("topbar-down"),o.length>0&&o.removeClass("topbar-down"),a.is(":focus")&&a.blur()):s+$(window).height()<$(document).height()&&(e.removeClass("topbar-up").addClass("topbar-down"),t.length>0&&t.addClass("topbar-down"),o.length>0&&o.addClass("topbar-down")),n=s)}(),s=!1)},250)}),$(function(){const e=$("#topbar-title"),t=$("div.post>h1"),o=e.text().trim();let a=t.length>0?t.text().trim():$("h1").text().trim();($("#page-category").length||$("#page-tag").length)&&/\s/.test(a)&&(a=a.replace(/[0-9]/g,"").trim()),$(window).scroll(function(){if($("#post-list").length||t.is(":hidden")||e.is(":hidden")||$("#sidebar.sidebar-expand").length)return!1;$(this).scrollTop()>=95?e.text()!==a&&e.text(a):e.text()!==o&&e.text(o)}),e.click(function(){$("body,html").animate({scrollTop:0},800)})}),$(function(){let e=$(".timeago").length,t=void 0;function o(){return $(".timeago").each(function(){if($(this).children("i").length>0){$(this).text();let t=$(this).hasClass("lastmod"),o=$(this).children("i"),a=o.text();$(this).text(function(t,o){let a=new Date,s=new Date(t);if(s.getFullYear()!==a.getFullYear())return e-=1,s.toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric"});if(s.getMonth()!==a.getMonth())return e-=1,s.toLocaleString("en-US",{month:"short",day:"numeric"});let n=Math.floor((a-s)/1e3),l=Math.floor(n/86400);if(l>=1)return e-=1,l+" day"+(l>1?"s":"")+" ago";let i=Math.floor(n/3600);if(i>=1)return i+" hour"+(i>1?"s":"")+" ago";let r=Math.floor(n/60);return r>=1?r+" minute"+(r>1?"s":"")+" ago":(o?"just":"Just")+" now"}(a,t)),$(this).append(o)}}),0===e&&void 0!==t&&clearInterval(t),e}0!==e&&o()>0&&(t=setInterval(o,6e4))});
\ No newline at end of file
diff --git a/assets/js/dist/page.min.js b/assets/js/dist/page.min.js
new file mode 100644
index 0000000..5e8724d
--- /dev/null
+++ b/assets/js/dist/page.min.js
@@ -0,0 +1 @@
+function copyLink(e){e&&0!==e.length||(e=window.location.href);const t=$("");$("body").append(t),t.val(e).select(),document.execCommand("copy"),t.remove(),alert("Link copied successfully!")}$(function(){$(window).scroll(()=>{$(this).scrollTop()>50&&"none"===$("#sidebar-trigger").css("display")?$("#back-to-top").fadeIn():$("#back-to-top").fadeOut()}),$("#back-to-top").click(()=>($("body,html").animate({scrollTop:0},800),!1))}),$(function(){$("input[type=checkbox]").addClass("unloaded"),$("input[type=checkbox][checked]").before(''),$("input[type=checkbox]:not([checked])").before('')}),$(function(){const e=$("#sidebar-trigger"),t=$("#search-trigger"),o=$("#search-cancel"),s=$("#search-cleaner"),a=$("#main"),l=$("#topbar-title"),n=$("#search-wrapper"),c=$("#search-result-wrapper"),r=$("#search-results"),i=$("#search-input"),d=$("#search-hints"),u=function(){let e=0;return{block(){e=$(window).scrollTop()},release(){$("html,body").scrollTop(e)},getOffset:()=>e}}(),f={on(){e.addClass("unloaded"),l.addClass("unloaded"),t.addClass("unloaded"),n.addClass("d-flex"),o.addClass("loaded")},off(){o.removeClass("loaded"),n.removeClass("d-flex"),e.removeClass("unloaded"),l.removeClass("unloaded"),t.removeClass("unloaded")}},p=function(){let e=!1;return{on(){e||(c.removeClass("unloaded"),a.addClass("hidden"),e=!0,u.block())},off(){e&&(r.empty(),d.hasClass("unloaded")&&d.removeClass("unloaded"),c.addClass("unloaded"),s.removeClass("visible"),a.removeClass("hidden"),i.val(""),e=!1,u.release())},isVisible:()=>e}}();function h(){return o.hasClass("loaded")}t.click(function(){f.on(),p.on(),i.focus()}),o.click(function(){f.off(),p.off()}),i.focus(function(){n.addClass("input-focus")}),i.focusout(function(){n.removeClass("input-focus")}),i.on("keyup",function(e){8===e.keyCode&&""===i.val()?h()?d.removeClass("unloaded"):p.off():""!==i.val()&&(p.on(),s.hasClass("visible")||s.addClass("visible"),h()&&d.addClass("unloaded"))}),s.on("click",function(){i.val(""),h()?(d.removeClass("unloaded"),r.empty()):p.off(),i.focus(),s.removeClass("visible")})}),$(function(){const e=function(){let e=!1;const t=$("body");return{toggle(){!1===e?t.attr("sidebar-display",""):t.removeAttr("sidebar-display"),e=!e}}}();$("#sidebar-trigger").click(e.toggle),$("#mask").click(e.toggle)}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(function(){const e=$("#topbar-wrapper"),t=$("#toc-wrapper"),o=$(".access"),s=$("#search-input");let a,l=0;const n=5,c=e.outerHeight();$(window).scroll(function(e){$("#topbar-title").is(":hidden")&&(a=!0)}),setInterval(function(){a&&(!function(){var a=$(this).scrollTop();Math.abs(l-a)<=n||(a>l&&a>c?(e.removeClass("topbar-down").addClass("topbar-up"),t.length>0&&t.removeClass("topbar-down"),o.length>0&&o.removeClass("topbar-down"),s.is(":focus")&&s.blur()):a+$(window).height()<$(document).height()&&(e.removeClass("topbar-up").addClass("topbar-down"),t.length>0&&t.addClass("topbar-down"),o.length>0&&o.addClass("topbar-down")),l=a)}(),a=!1)},250)}),$(function(){const e=$("#topbar-title"),t=$("div.post>h1"),o=e.text().trim();let s=t.length>0?t.text().trim():$("h1").text().trim();($("#page-category").length||$("#page-tag").length)&&/\s/.test(s)&&(s=s.replace(/[0-9]/g,"").trim()),$(window).scroll(function(){if($("#post-list").length||t.is(":hidden")||e.is(":hidden")||$("#sidebar.sidebar-expand").length)return!1;$(this).scrollTop()>=95?e.text()!==s&&e.text(s):e.text()!==o&&e.text(o)}),e.click(function(){$("body,html").animate({scrollTop:0},800)})}),$(function(){$("a[href*='#']").not("[href='#']").not("[href='#0']").click(function(e){if(this.pathname.replace(/^\//,"")===location.pathname.replace(/^\//,"")&&location.hostname===this.hostname){const t=16,o=decodeURI(this.hash);let s=RegExp(/^#fnref:/).test(o),a=RegExp(/^#fn:/).test(o),l=o.includes(":")?o.replace(/\:/,"\\:"):o,n=$(l);if(n.length){e.preventDefault(),history.pushState&&history.pushState(null,null,o);let l=$(this).offset().top,c=n.offset().top;const r=c{const e=$(n);e.focus();if($("[scroll-focus=true]").length&&$("[scroll-focus=true]").attr("scroll-focus",!1),$(":target").length&&$(":target").attr("scroll-focus",!1),(a||s)&&e.attr("scroll-focus",!0),e.is(":focus"))return!1;e.attr("tabindex","-1"),e.focus()})}}})});
\ No newline at end of file
diff --git a/assets/js/dist/post.min.js b/assets/js/dist/post.min.js
new file mode 100644
index 0000000..48a1a37
--- /dev/null
+++ b/assets/js/dist/post.min.js
@@ -0,0 +1 @@
+function copyLink(e){e&&0!==e.length||(e=window.location.href);const t=$("");$("body").append(t),t.val(e).select(),document.execCommand("copy"),t.remove(),alert("Link copied successfully!")}$(function(){$(window).scroll(()=>{$(this).scrollTop()>50&&"none"===$("#sidebar-trigger").css("display")?$("#back-to-top").fadeIn():$("#back-to-top").fadeOut()}),$("#back-to-top").click(()=>($("body,html").animate({scrollTop:0},800),!1))}),$(function(){$("input[type=checkbox]").addClass("unloaded"),$("input[type=checkbox][checked]").before(''),$("input[type=checkbox]:not([checked])").before('')}),$(function(){const e=$("#sidebar-trigger"),t=$("#search-trigger"),o=$("#search-cancel"),s=$("#search-cleaner"),a=$("#main"),n=$("#topbar-title"),l=$("#search-wrapper"),r=$("#search-result-wrapper"),i=$("#search-results"),c=$("#search-input"),d=$("#search-hints"),u=function(){let e=0;return{block(){e=$(window).scrollTop()},release(){$("html,body").scrollTop(e)},getOffset:()=>e}}(),h={on(){e.addClass("unloaded"),n.addClass("unloaded"),t.addClass("unloaded"),l.addClass("d-flex"),o.addClass("loaded")},off(){o.removeClass("loaded"),l.removeClass("d-flex"),e.removeClass("unloaded"),n.removeClass("unloaded"),t.removeClass("unloaded")}},f=function(){let e=!1;return{on(){e||(r.removeClass("unloaded"),a.addClass("hidden"),e=!0,u.block())},off(){e&&(i.empty(),d.hasClass("unloaded")&&d.removeClass("unloaded"),r.addClass("unloaded"),s.removeClass("visible"),a.removeClass("hidden"),c.val(""),e=!1,u.release())},isVisible:()=>e}}();function p(){return o.hasClass("loaded")}t.click(function(){h.on(),f.on(),c.focus()}),o.click(function(){h.off(),f.off()}),c.focus(function(){l.addClass("input-focus")}),c.focusout(function(){l.removeClass("input-focus")}),c.on("keyup",function(e){8===e.keyCode&&""===c.val()?p()?d.removeClass("unloaded"):f.off():""!==c.val()&&(f.on(),s.hasClass("visible")||s.addClass("visible"),p()&&d.addClass("unloaded"))}),s.on("click",function(){c.val(""),p()?(d.removeClass("unloaded"),i.empty()):f.off(),c.focus(),s.removeClass("visible")})}),$(function(){const e=function(){let e=!1;const t=$("body");return{toggle(){!1===e?t.attr("sidebar-display",""):t.removeAttr("sidebar-display"),e=!e}}}();$("#sidebar-trigger").click(e.toggle),$("#mask").click(e.toggle)}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(function(){const e=$("#topbar-wrapper"),t=$("#toc-wrapper"),o=$(".access"),s=$("#search-input");let a,n=0;const l=5,r=e.outerHeight();$(window).scroll(function(e){$("#topbar-title").is(":hidden")&&(a=!0)}),setInterval(function(){a&&(!function(){var a=$(this).scrollTop();Math.abs(n-a)<=l||(a>n&&a>r?(e.removeClass("topbar-down").addClass("topbar-up"),t.length>0&&t.removeClass("topbar-down"),o.length>0&&o.removeClass("topbar-down"),s.is(":focus")&&s.blur()):a+$(window).height()<$(document).height()&&(e.removeClass("topbar-up").addClass("topbar-down"),t.length>0&&t.addClass("topbar-down"),o.length>0&&o.addClass("topbar-down")),n=a)}(),a=!1)},250)}),$(function(){const e=$("#topbar-title"),t=$("div.post>h1"),o=e.text().trim();let s=t.length>0?t.text().trim():$("h1").text().trim();($("#page-category").length||$("#page-tag").length)&&/\s/.test(s)&&(s=s.replace(/[0-9]/g,"").trim()),$(window).scroll(function(){if($("#post-list").length||t.is(":hidden")||e.is(":hidden")||$("#sidebar.sidebar-expand").length)return!1;$(this).scrollTop()>=95?e.text()!==s&&e.text(s):e.text()!==o&&e.text(o)}),e.click(function(){$("body,html").animate({scrollTop:0},800)})}),$(function(){let e=$(".timeago").length,t=void 0;function o(){return $(".timeago").each(function(){if($(this).children("i").length>0){$(this).text();let t=$(this).hasClass("lastmod"),o=$(this).children("i"),s=o.text();$(this).text(function(t,o){let s=new Date,a=new Date(t);if(a.getFullYear()!==s.getFullYear())return e-=1,a.toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric"});if(a.getMonth()!==s.getMonth())return e-=1,a.toLocaleString("en-US",{month:"short",day:"numeric"});let n=Math.floor((s-a)/1e3),l=Math.floor(n/86400);if(l>=1)return e-=1,l+" day"+(l>1?"s":"")+" ago";let r=Math.floor(n/3600);if(r>=1)return r+" hour"+(r>1?"s":"")+" ago";let i=Math.floor(n/60);return i>=1?i+" minute"+(i>1?"s":"")+" ago":(o?"just":"Just")+" now"}(s,t)),$(this).append(o)}}),0===e&&void 0!==t&&clearInterval(t),e}0!==e&&o()>0&&(t=setInterval(o,6e4))}),$(function(){$("a:has(img)").addClass("img-hyperlink")}),$(function(){const e=new RegExp("^language-([a-z])+$");$("div[class^=language-").each(function(){$(this).attr("class").split(" ").forEach(t=>{if(e.test(t)){let e=t.substring("language-".length);$(this).attr("lang",`${e}`)}})})}),$(function(){$("a[href*='#']").not("[href='#']").not("[href='#0']").click(function(e){if(this.pathname.replace(/^\//,"")===location.pathname.replace(/^\//,"")&&location.hostname===this.hostname){const t=16,o=decodeURI(this.hash);let s=RegExp(/^#fnref:/).test(o),a=RegExp(/^#fn:/).test(o),n=o.includes(":")?o.replace(/\:/,"\\:"):o,l=$(n);if(l.length){e.preventDefault(),history.pushState&&history.pushState(null,null,o);let n=$(this).offset().top,r=l.offset().top;const i=r{const e=$(l);e.focus();if($("[scroll-focus=true]").length&&$("[scroll-focus=true]").attr("scroll-focus",!1),$(":target").length&&$(":target").attr("scroll-focus",!1),(a||s)&&e.attr("scroll-focus",!0),e.is(":focus"))return!1;e.attr("tabindex","-1"),e.focus()})}}})});
\ No newline at end of file
diff --git a/assets/js/dist/pvreport.min.js b/assets/js/dist/pvreport.min.js
new file mode 100644
index 0000000..97d7861
--- /dev/null
+++ b/assets/js/dist/pvreport.min.js
@@ -0,0 +1 @@
+const getInitStatus=function(){let e=!1;return()=>{let t=e;return e||(e=!0),t}}(),PvOpts={isEnabled:()=>"true"===$("meta[name=pv-cache-enabled]").attr("content"),getProxyEndpoint:()=>$("meta[name=pv-proxy-endpoint]").attr("content"),getLocalData:()=>$("meta[name=pv-cache-data]").attr("content")},PvCache=function(){const e="origin",t="proxy";function a(e){return localStorage.getItem(e)}function n(e,t){localStorage.setItem(e,t)}return{getData:()=>JSON.parse(localStorage.getItem("pv")),saveOriginCache(t){n("pv",t),n("pv_source",e),n("pv_created_date",(new Date).toJSON())},saveProxyCache(e){n("pv",e),n("pv_source",t),n("pv_created_date",(new Date).toJSON())},isFromOrigin:()=>a("pv_source")===e,isFromProxy:()=>a("pv_source")===t,isExpired(){if(PvCache.isFromOrigin()){let e=new Date(a("pv_created_date"));return e.setDate(e.getDate()+1),Date.now()>=e.getTime()}if(PvCache.isFromProxy()){let e=new Date(a("pv_created_date"));return e.setHours(e.getHours()+1),Date.now()>=e.getTime()}return!1},getAllPageviews:()=>PvCache.getData().totalsForAllResults["ga:pageviews"],newerThan:e=>PvCache.getAllPageviews()>e.totalsForAllResults["ga:pageviews"],inspectKeys(){null!==localStorage.getItem("pv")&&null!==localStorage.getItem("pv_source")&&null!==localStorage.getItem("pv_created_date")||localStorage.clear()}}}();function countUp(e,t,a){if(ee&&countUp(e,r,a.attr("id"))}else a.text((new Intl.NumberFormat).format(r))}function displayPageviews(e){if(void 0===e)return;let t=getInitStatus();const a=e.rows;if($("#post-list").length>0)$(".post-preview").each(function(){const e=$(this).find("a").attr("href");tacklePV(a,e,$(this).find(".pageviews"),t)});else if($(".post").length>0){const e=window.location.pathname;tacklePV(a,e,$("#pv"),t)}}function fetchProxyPageviews(){$.ajax({type:"GET",url:PvOpts.getProxyEndpoint(),dataType:"jsonp",jsonpCallback:"displayPageviews",success:(e,t,a)=>{PvCache.saveProxyCache(JSON.stringify(e))},error:(e,t,a)=>{console.log("Failed to load pageviews from proxy server: "+a)}})}function fetchPageviews(e=!0,t=!1){PvOpts.isEnabled()&&e?fetch(PvOpts.getLocalData()).then(e=>e.json()).then(e=>{t&&PvCache.newerThan(e)||(displayPageviews(e),PvCache.saveOriginCache(JSON.stringify(e)))}).then(()=>fetchProxyPageviews()):fetchProxyPageviews()}$(function(){if($(".pageviews").length>0){PvCache.inspectKeys();let e=PvCache.getData();e?(displayPageviews(e),PvCache.isExpired()?fetchPageviews(!0,PvCache.isFromProxy()):PvCache.isFromOrigin()&&fetchPageviews(!1)):fetchPageviews()}});
\ No newline at end of file
diff --git a/assets/js/home.min.js b/assets/js/home.min.js
deleted file mode 100644
index c8b59e5..0000000
--- a/assets/js/home.min.js
+++ /dev/null
@@ -1,11 +0,0 @@
----
-layout: compress
-
-# JS for layout home.
-# Chirpy v2.3
-# https://github.com/cotes2020/jekyll-theme-chirpy
-# © 2020 Cotes Chung
-# MIT License
----
-
-{% include_relative _home-post.js %}
diff --git a/assets/js/lib/_bootstrap-toc.min.js b/assets/js/lib/_bootstrap-toc.min.js
deleted file mode 100644
index c628326..0000000
--- a/assets/js/lib/_bootstrap-toc.min.js
+++ /dev/null
@@ -1,5 +0,0 @@
-/*!
- * Bootstrap Table of Contents v1.0.1 (http://afeld.github.io/bootstrap-toc/)
- * Copyright 2015 Aidan Feldman
- * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */
-!function(a){"use strict";window.Toc={helpers:{findOrFilter:function(e,t){var n=e.find(t);return e.filter(t).add(n).filter(":not([data-toc-skip])")},generateUniqueIdBase:function(e){return a(e).text().trim().replace(/\'/gi,"").replace(/[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\\n\t\b\v]/g,"-").replace(/-{2,}/g,"-").substring(0,64).replace(/^-+|-+$/gm,"").toLowerCase()||e.tagName.toLowerCase()},generateUniqueId:function(e){for(var t=this.generateUniqueIdBase(e),n=0;;n++){var r=t;if(0')},createChildNavList:function(e){var t=this.createNavList();return e.append(t),t},generateNavEl:function(e,t){var n=a('');n.attr("href","#"+e),n.text(t);var r=a("");return r.append(n),r},generateNavItem:function(e){var t=this.generateAnchor(e),n=a(e),r=n.data("toc-text")||n.text();return this.generateNavEl(t,r)},getTopLevel:function(e){for(var t=1;t<=6;t++){if(11?m.options.decimal+p[1]:"";if(m.options.useGrouping){q="";for(u=0,o=s.length;um.endVal);m.frameVal=m.startVal;m.initialized=true;return true}else{m.error="[CountUp] startVal ("+b+") or endVal ("+i+") is not a number";return false}};m.printValue=function(p){var o=m.options.formattingFn(p);if(m.d.tagName==="INPUT"){this.d.value=o}else{if(m.d.tagName==="text"||m.d.tagName==="tspan"){this.d.textContent=o}else{this.d.innerHTML=o}}};m.count=function(p){if(!m.startTime){m.startTime=p}m.timestamp=p;var o=p-m.startTime;m.remaining=m.duration-o;if(m.options.useEasing){if(m.countDown){m.frameVal=m.startVal-m.options.easingFn(o,0,m.startVal-m.endVal,m.duration)}else{m.frameVal=m.options.easingFn(o,m.startVal,m.endVal-m.startVal,m.duration)}}else{if(m.countDown){m.frameVal=m.startVal-((m.startVal-m.endVal)*(o/m.duration))}else{m.frameVal=m.startVal+(m.endVal-m.startVal)*(o/m.duration)}}if(m.countDown){m.frameVal=(m.frameValm.endVal)?m.endVal:m.frameVal}m.frameVal=Math.round(m.frameVal*m.dec)/m.dec;m.printValue(m.frameVal);if(om.endVal);m.rAF=requestAnimationFrame(m.count)};if(m.initialize()){m.printValue(m.startVal)}};
\ No newline at end of file
diff --git a/assets/js/page.min.js b/assets/js/page.min.js
deleted file mode 100644
index d9a7a53..0000000
--- a/assets/js/page.min.js
+++ /dev/null
@@ -1,13 +0,0 @@
----
-layout: compress
-
-# JS for layout page by default.
-# Chirpy v2.3
-# https://github.com/cotes2020/jekyll-theme-chirpy
-# © 2020 Cotes Chung
-# MIT License
----
-
-{% include_relative _commons.js %}
-
-{% include_relative _utils/smooth-scroll.js %}
diff --git a/assets/js/post.min.js b/assets/js/post.min.js
deleted file mode 100644
index 1536651..0000000
--- a/assets/js/post.min.js
+++ /dev/null
@@ -1,20 +0,0 @@
----
-layout: compress
-
-# JS for layout post.
-# Chirpy v2.3
-# https://github.com/cotes2020/jekyll-theme-chirpy
-# © 2020 Cotes Chung
-# MIT License
----
-
-{% include_relative _home-post.js %}
-
-{% include_relative lib/_bootstrap-toc.min.js %}
-
-{% include_relative _utils/img-hyperlink.js %}
-
-{% include_relative _utils/lang-badge.js %}
-
-{% comment %} `smooth-scroll.js` must be called after ToC is ready {% endcomment %}
-{% include_relative _utils/smooth-scroll.js %}
diff --git a/gulpfile.js/index.js b/gulpfile.js/index.js
new file mode 100644
index 0000000..14692fb
--- /dev/null
+++ b/gulpfile.js/index.js
@@ -0,0 +1,10 @@
+#!/usr/bin/env node
+
+"use strict";
+
+const js = require('./tasks/js');
+
+exports.default = js.build;
+
+/* keep-alive develop mode, without uglify */
+exports.dev = js.liveRebuild;
diff --git a/gulpfile.js/tasks/js.js b/gulpfile.js/tasks/js.js
new file mode 100644
index 0000000..16260a4
--- /dev/null
+++ b/gulpfile.js/tasks/js.js
@@ -0,0 +1,86 @@
+#!/usr/bin/env node
+
+"use strict";
+
+const { src, dest, watch, series, parallel} = require('gulp');
+
+const concat = require('gulp-concat');
+const rename = require("gulp-rename");
+const uglify = require('gulp-uglify');
+
+const JS_ROOT = './assets/js';
+const jsDest = `${ JS_ROOT }/dist/`;
+
+function concatJs(files, output) {
+ return src(files)
+ .pipe(concat(output))
+ .pipe(rename({ extname: '.min.js' }))
+ .pipe(dest(jsDest));
+}
+
+function minifyJs() {
+ return src(`${ jsDest }/*.js`)
+ .pipe(uglify())
+ .pipe(dest(jsDest));
+}
+
+const homeJs = () => {
+ return concatJs([
+ `${JS_ROOT}/_commons/*.js`,
+ `${JS_ROOT}/_utils/timeago.js`
+ ],
+ 'home'
+ );
+};
+
+const postJs = () => {
+ return concatJs([
+ `${JS_ROOT}/_commons/*.js`,
+ `${JS_ROOT}/_utils/timeago.js`,
+ `${JS_ROOT}/_utils/img-hyperlink.js`,
+ `${JS_ROOT}/_utils/lang-badge.js`,
+ // 'smooth-scroll.js' must be called after ToC is ready
+ `${JS_ROOT}/_utils/smooth-scroll.js`
+ ], 'post'
+ );
+};
+
+const categoriesJs = () => {
+ return concatJs([
+ `${JS_ROOT}/_commons/*.js`,
+ `${JS_ROOT}/_utils/category-collapse.js`
+ ], 'categories'
+ );
+};
+
+const pageJs = () => {
+ return concatJs([
+ `${JS_ROOT}/_commons/*.js`,
+ `${JS_ROOT}/_utils/smooth-scroll.js`
+ ], 'page'
+ );
+};
+
+// GA pageviews report
+const pvreportJs = () => {
+ return concatJs([
+ `${JS_ROOT}/_utils/pageviews.js`
+ ], 'pvreport'
+ );
+};
+
+const buildJs = parallel(homeJs, postJs, categoriesJs, pageJs, pvreportJs);
+
+exports.build = series(buildJs, minifyJs);
+
+exports.liveRebuild = () => {
+ buildJs();
+
+ watch([
+ `${ JS_ROOT }/_commons/*.js`,
+ `${ JS_ROOT }/_utils/*.js`
+ ],
+ buildJs
+ )
+}
+
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..d84babc
--- /dev/null
+++ b/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "jekyll-theme-chirpy",
+ "version": "3.0.0",
+ "description": "A minimal, sidebar, responsive web design Jekyll theme that focuses on text presentation.",
+ "main": "index.js",
+ "directories": {
+ "doc": "docs"
+ },
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/cotes2020/jekyll-theme-chirpy.git"
+ },
+ "author": "Cotes Chung",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/cotes2020/jekyll-theme-chirpy/issues"
+ },
+ "homepage": "https://github.com/cotes2020/jekyll-theme-chirpy#readme",
+ "dependencies": {
+ "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony",
+ "gulp": "^4.0.2",
+ "gulp-concat": "^2.6.1",
+ "gulp-rename": "^2.0.0",
+ "gulp-uglify": "^3.0.2"
+ }
+}