Combine local JS.

’yui-compressor’ is no longer used.
This commit is contained in:
Cotes Chung 2020-05-30 00:48:10 +08:00
parent cfb67a1cb9
commit 1a2767ca24
44 changed files with 213 additions and 195 deletions

View file

@ -158,11 +158,6 @@ defaults:
-
label: Home
url: /
-
scope:
path: assets/data
values:
layout: compress
sass:

View file

@ -11,7 +11,7 @@
<p class="font-italic text-muted small">Comments powered by <a href="https://disqus.com/">Disqus</a>.</p>
</div>
<script src="{{ site.baseurl }}/assets/lib/jquery.disqusloader.min.js"></script>
<script src="{{ site.baseurl }}/assets/js/lib/jquery.disqusloader.min.js"></script>
<script>
var options = {
scriptUrl: '//{{ site.disqus.shortname }}.disqus.com/embed.js',

View file

@ -11,22 +11,21 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>
{%- if page.layout == "home" -%}
{{- site.title -}}
{%- else -%}
{{ page.title }} | {{ site.title }}
{%- endif -%}
{%- unless page.layout == "home" -%}
{{ page.title | append: " | "}}
{%- endunless -%}
{{ site.title }}
</title>
{% seo title=false %}
{% include favicons.html %}
<!-- google fonts -->
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous">
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<!-- ga -->
<!-- GA -->
{% if jekyll.environment == 'production' %}
<link rel="preconnect" href="https://www.google-analytics.com" crossorigin="use-credentials">
<link rel="dns-prefetch" href="https://www.google-analytics.com">
@ -40,10 +39,12 @@
{% endif %}
{% endif %}
<!-- jsdelivr CDN -->
<!-- jsDelivr CDN -->
<link rel="preconnect" href="cdn.jsdelivr.net">
<link rel="dns-prefetch" href="cdn.jsdelivr.net">
<!-- Bootstrap -->
<link rel="preload" as="style"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css"
integrity="sha256-LA89z+k9fjgMKQ/kq4OO2Mrf8VltYml/VES+Rg0fh20=" crossorigin>
@ -52,6 +53,8 @@
href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css"
integrity="sha256-LA89z+k9fjgMKQ/kq4OO2Mrf8VltYml/VES+Rg0fh20=" crossorigin="anonymous">
<!-- Font Awesome -->
<link rel="preload" as="style"
href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.11.2/css/all.min.css"
integrity="sha256-+N4/V/SbAFiW1MPBCXnfnP9QSN3+Keu+NlB+0ev/YKQ="
@ -100,41 +103,18 @@
<link rel="stylesheet" href="{{ site.baseurl }}/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.css" />
{% endif %}
{% if page.math %}
<!-- MathJax -->
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" async></script>
{% endif %}
{% endif %}
<link rel="preload" as="script"
href="https://cdn.jsdelivr.net/combine/npm/jquery@3.4.1,npm/popper.js@1.15.0,npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" crossorigin>
<!-- JavaScripts -->
<script src="https://cdn.jsdelivr.net/combine/npm/jquery@3.4.1,npm/popper.js@1.15.0,npm/bootstrap@4.0.0/dist/js/bootstrap.min.js"></script>
<link rel="preload" as="script" href="https://cdn.jsdelivr.net/npm/jquery@3.4.1"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous">
<script src="{{ site.baseurl }}/assets/js/dist/commons.js" async></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
{% if page.layout == 'home' or page.layout == 'post' %}
<script src="{{ site.baseurl }}/assets/js/dist/timeago.min.js" async></script>
{% if site.google_analytics.pv.enabled %}
<script src="{{ site.baseurl }}/assets/data/pv-data.json"></script>
<script src="{{ site.baseurl }}/assets/lib/countUp.min.js" async></script>
<script src="{{ site.baseurl }}/assets/js/dist/pageviews.min.js" async></script>
{% endif %}
{% endif %}
<script src="https://cdn.jsdelivr.net/combine/npm/popper.js@1.15.0,npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" async></script>
{% if site.toc and page.toc and page.layout == 'post' %}
<link rel="preload" as="script" href="{{ site.baseurl }}/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.js">
<script src="{{ site.baseurl }}/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.js" async></script>
<script src="{{ site.baseurl }}/assets/js/dist/toc.min.js" async></script>
{% endif %}
<script src="{{ site.baseurl }}/assets/js/dist/tooltip-loader.min.js" async></script>
<!-- PWA -->
{% if jekyll.environment == 'production' %}
<script src="{{ '/app.js' | relative_url }}" defer></script>
{% endif %}
{% include js-selector.html %}
</head>

View file

@ -0,0 +1,45 @@
<!--
JS selector for site.
Chirpy v2.3
https://github.com/cotes2020/jekyll-theme-chirpy
© 2020 Cotes Chung
MIT Licensed
-->
{% if page.layout == 'home' %}
<script src="{{ '/assets/js/home.min.js' | relative_url }}" async></script>
{% elsif page.layout == 'post' %}
{% if site.toc and page.toc %}
<script src="{{ '/assets/js/post-toc.min.js' | relative_url }}" async></script>
{% else %}
<script src="{{ '/assets/js/post.min.js' | relative_url }}" async></script>
{% endif %}
{% if page.math %}
<!-- MathJax -->
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" async></script>
{% endif %}
{% elsif page.layout == 'page' %}
{% if page.title == 'Categories' %}
<script src="{{ '/assets/js/categories.min.js' | relative_url }}" async></script>
{% else %}
<script src="{{ '/assets/js/page.min.js' | relative_url }}" async></script>
{% endif %}
{% else %}
<script src="{{ '/assets/js/page.min.js' | relative_url }}" async></script>
{% endif %}
<!-- PWA -->
{% if jekyll.environment == 'production' %}
<script src="{{ '/app.js' | relative_url }}" defer></script>
{% endif %}

View file

@ -5,7 +5,6 @@
© 2017-2019 Cotes Chung
MIT License
-->
<script src="https://cdn.jsdelivr.net/npm/simple-jekyll-search@1.7.3/dest/simple-jekyll-search.min.js" integrity="sha256-qcLR00zq6pJk4je3MLgAri8Nn+ZumUlXgTKR2H/xCY0=" crossorigin="anonymous"></script>
{% capture result_elem %}
<div class="pl-1 pr-1 pl-sm-2 pr-sm-2 pl-lg-4 pr-lg-4 pl-xl-0 pr-xl-0">
@ -20,11 +19,13 @@
{% capture not_found %}<p class="mt-5">Oops! No result founds.</p>{% endcapture %}
<script src="https://cdn.jsdelivr.net/npm/simple-jekyll-search@1.7.3/dest/simple-jekyll-search.min.js"></script>
<script>
SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('search-results'),
json: '{{ site.baseurl }}/assets/data/search.json',
json: '{{ site.baseurl }}/assets/js/data/search.json',
searchResultTemplate: '{{ result_elem | strip_newlines }}',
noResultsText: '{{ not_found }}'
});

21
assets/js/_commons.js Normal file
View file

@ -0,0 +1,21 @@
/*!
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 _utils/tooltip-loader.js %}

View file

@ -5,6 +5,7 @@
* © 2018-2019 Cotes Chung
* MIT License
*/
$(function() {
var didScroll;
@ -13,7 +14,7 @@ $(function() {
var topbarHeight = $('#topbar-wrapper').outerHeight();
$(window).scroll(function(event) {
if ($("#topbar-title").is(":hidden")) { // Not in small screens
if ($("#topbar-title").is(":hidden")) { /* Not in small screens */
didScroll = true;
}
});
@ -28,12 +29,12 @@ $(function() {
function hasScrolled() {
var st = $(this).scrollTop();
// Make sure they scroll more than delta
/* Make sure they scroll more than delta */
if (Math.abs(lastScrollTop - st) <= delta)
return;
if (st > lastScrollTop && st > topbarHeight) {
// Scroll Down
/* Scroll Down */
$('#topbar-wrapper').removeClass('topbar-down').addClass('topbar-up');
if ( $('#toc-wrapper').length > 0) {
@ -45,11 +46,11 @@ $(function() {
}
if ($('#search-input').is(':focus')) {
$('#search-input').blur(); // remove focus
$('#search-input').blur(); /* remove focus */
}
} else {
// Scroll Up
/* Scroll Up */
if (st + $(window).height() < $(document).height()) {
$('#topbar-wrapper').removeClass('topbar-up').addClass('topbar-down');
if ( $('#toc-wrapper').length > 0) {

View file

@ -5,7 +5,8 @@
* © 2018-2019 Cotes Chung
* MIT License
*/
$(function(){
$(function() {
var DEFAULT = $("#topbar-title").text().trim();
var title = ($("div.post>h1").length > 0) ?
@ -18,12 +19,12 @@ $(function(){
}
}
// Replace topbar title while scroll screens.
/* 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
|| $("#sidebar.sidebar-expand").length) { // when the sidebar trigger is clicked
if ($("#post-list").length /* in Home page */
|| $("div.post>h1").is(":hidden") /* is tab pages */
|| $("#topbar-title").is(":hidden") /* not mobile screens */
|| $("#sidebar.sidebar-expand").length) { /* when the sidebar trigger is clicked */
return false;
}
@ -36,9 +37,9 @@ $(function(){
$("#topbar-title").text(DEFAULT);
}
}
})
});
// Click title remove hover effect.
/* Click title remove hover effect. */
$('#topbar-title').click(function() {
$('body,html').animate({scrollTop: 0}, 800);
});

22
assets/js/_home-post.js Normal file
View file

@ -0,0 +1,22 @@
/*!
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 data/pv-data.js %}
{% include_relative _utils/pageviews.js %}
{% include_relative lib/_countUp.min.js %}
{% endif %}

View file

@ -10,8 +10,8 @@ $(function() {
var child_prefix = "l_";
var parent_prefix = "h_";
// close up top-category
$(".collapse").on("hide.bs.collapse", function() { // Bootstrap collapse events.
/* close up top-category */
$(".collapse").on("hide.bs.collapse", function() { /* Bootstrap collapse events. */
var parent_id = parent_prefix + $(this).attr('id').substring(child_prefix.length);
if (parent_id) {
$("#" + parent_id + " .far.fa-folder-open").attr("class", "far fa-folder fa-fw");
@ -20,7 +20,7 @@ $(function() {
}
});
// expand the top category
/* expand the top category */
$(".collapse").on("show.bs.collapse", function() {
var parent_id = parent_prefix + $(this).attr('id').substring(child_prefix.length);
if (parent_id) {

View file

@ -35,7 +35,7 @@ function countPV(path, rows) {
if (gaPath == path ||
gaPath == _v2_url ||
gaPath.concat('/') == _v2_url ||
gaPath.slice(gaPath.lastIndexOf('/') + 1) === fileName) { // old permalink record
gaPath.slice(gaPath.lastIndexOf('/') + 1) === fileName) { /* old permalink record */
count += parseInt(rows[i][1]);
}
}
@ -67,13 +67,13 @@ function displayPageviews(data) {
var hasInit = getInitStatus();
var rows = data.rows;
if ($("#post-list").length > 0) { // the Home page
if ($("#post-list").length > 0) { /* the Home page */
$(".post-preview").each(function() {
var path = $(this).children("h1").children("a").attr("href");
tacklePV(rows, path, $(this).find('.pageviews'), hasInit);
});
} else if ($(".post").length > 0) { // the post
} else if ($(".post").length > 0) { /* the post */
var path = window.location.pathname;
tacklePV(rows, path, $('#pv'), hasInit);
}
@ -133,12 +133,12 @@ var PvCache = (function() {
isExpired: function() {
if (PvCache.isOriginCache() ) {
let date = new Date(get(KEY_CREATION));
date.setDate(date.getDate() + 1); // fetch origin-data every day
date.setDate(date.getDate() + 1); /* fetch origin-data every day */
return Date.now() >= date.getTime();
} else if (PvCache.isProxyCache() ) {
let date = new Date(get(KEY_CREATION) );
date.setHours(date.getHours() + 1); // proxy-data is updated every hour
date.setHours(date.getHours() + 1); /* proxy-data is updated every hour */
return Date.now() >= date.getTime();
}
return false;
@ -151,7 +151,7 @@ var PvCache = (function() {
}
};
})(); // PvCache
})(); /* PvCache */
function fetchOriginPageviews(pvData) {
@ -164,7 +164,7 @@ function fetchOriginPageviews(pvData) {
function fetchProxyPageviews() {
let proxy = JSON.parse(proxyData); // see file '/assets/data/pv-data.json'
let proxy = JSON.parse(proxyData); /* see file '/assets/data/pv-data.json' */
$.ajax({
type: 'GET',
url: proxy.url,
@ -205,7 +205,7 @@ $(function() {
fetchProxyPageviews();
}
} else { // still valid
} else { /* still valid */
displayPageviews(cache);
if (PvCache.isOriginCache() ) {

View file

@ -7,4 +7,4 @@
*/
$(function () {
$('[data-toggle="tooltip"]').tooltip();
})
});

13
assets/js/categories.min.js vendored Normal file
View file

@ -0,0 +1,13 @@
---
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 %}

View file

@ -1,4 +1,6 @@
---
layout: compress
# The list to be cached by PWA
# Chirpy v2.2
# https://github.com/cotes2020/jekyll-theme-chirpy
@ -17,15 +19,14 @@ const include = [
'{{ "/assets/css/page.css" | relative_url }}',
'{{ "/assets/css/post.css" | relative_url }}',
'{{ "/assets/css/category-tag.css" | relative_url }}',
'{{ "/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.css" | relative_url }}',
'{{ "/assets/css/lib/bootstrap-toc.min.css" | relative_url }}',
/*--- Javascripts ---*/
'{{ "/assets/js/dist/commons.js" | relative_url }}',
'{{ "/assets/js/dist/timeago.min.js" | relative_url }}',
'{{ "/assets/js/dist/category-collapse.min.js" | relative_url }}',
'{{ "/assets/js/dist/toc.min.js" | relative_url }}',
'{{ "/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.js" | relative_url }}',
'{{ "/assets/js/home.min.js" | relative_url }}',
'{{ "/assets/js/page.min.js" | relative_url }}',
'{{ "/assets/js/post.min.js" | relative_url }}',
'{{ "/assets/js/post-toc.min.js" | relative_url }}',
/*--- HTML ---*/
@ -98,12 +99,7 @@ const include = [
/*--- Others ---*/
{% if site.google_analytics.pv.enabled %}
'{{ "/assets/lib/countUp.min.js" | relative_url }}',
'{{ "/assets/js/dist/pageviews.min.js" | relative_url }}',
{% endif %}
'{{ "/assets/data/search.json" | relative_url }}',
'{{ "/assets/js/data/search.json" | relative_url }}',
'{{ "/404.html" | relative_url }}',
'{{ "/app.js" | relative_url }}',
@ -111,6 +107,6 @@ const include = [
];
const exclude = [
'/assets/data/pv-data.json',
'/assets/js/data/pv-data.js',
'/img.shields.io/'
];

View file

@ -1,11 +1,8 @@
---
---
const proxyData = '{"url": "{{ site.google_analytics.pv.proxy_endpoint }}"}';
{%- capture pv_data -%}
{%- if site.google_analytics.pv.cache and site.google_analytics.pv.enabled -%}
{% include_relative _pageviews.json %}
{% include_relative data/_pageviews.json %}
{%- endif -%}
{%- endcapture -%}

View file

@ -1,4 +1,5 @@
---
layout: compress
---
[

View file

@ -1 +0,0 @@
$(window).scroll(function(){if($(this).scrollTop()>50&&$("#sidebar-trigger").css("display")=="none"){$("#back-to-top").fadeIn()}else{$("#back-to-top").fadeOut()}});$(function(){$("#back-to-top").click(function(){$("body,html").animate({scrollTop:0},800);return false})});

View file

@ -1 +0,0 @@
function copyLink(a){if(!a||0===a.length){a=window.location.href}var b=$("<input>");$("body").append(b);b.val(a).select();document.execCommand("copy");b.remove();alert("Link copied successfully!")};

View file

@ -1 +0,0 @@
$(function(){var j=$("#sidebar-trigger");var o=$("#search-trigger");var h=$("#search-cancel");var b=$("#search-cleaner");var e=$("#main");var c=$("#topbar-title");var k=$("#search-wrapper");var i=$("#search-result-wrapper");var g=$("#search-results");var l=$("#search-input");var a=$("#search-hints");var d=(function(){var p=0;return{block:function(){p=$(window).scrollTop()},release:function(){$("html,body").scrollTop(p)},getOffset:function(){return p}}})();var m=(function(){return{on:function(){j.addClass("unloaded");c.addClass("unloaded");o.addClass("unloaded");k.addClass("d-flex");h.addClass("loaded")},off:function(){h.removeClass("loaded");k.removeClass("d-flex");j.removeClass("unloaded");c.removeClass("unloaded");o.removeClass("unloaded")}}})();var n=(function(){var p=false;return{on:function(){if(!p){i.removeClass("unloaded");e.addClass("hidden");p=true;d.block()}},off:function(){if(p){g.empty();if(a.hasClass("unloaded")){a.removeClass("unloaded")}i.addClass("unloaded");b.removeClass("visable");e.removeClass("hidden");l.val("");p=false;d.release()}},isVisable:function(){return p}}})();function f(){return h.hasClass("loaded")}o.click(function(){m.on();n.on();l.focus()});h.click(function(){m.off();n.off()});l.focus(function(){k.addClass("input-focus")});l.focusout(function(){k.removeClass("input-focus")});l.on("keyup",function(p){if(p.keyCode==8&&l.val()==""){if(!f()){n.off()}else{a.removeClass("unloaded")}}else{if(l.val()!=""){n.on();if(!b.hasClass("visible")){b.addClass("visable")}if(f()){a.addClass("unloaded")}}}});b.on("click",function(){l.val("");if(f()){a.removeClass("unloaded");g.empty()}else{n.off()}l.focus();b.removeClass("visable")})});

View file

@ -1 +0,0 @@
$(function(){var a=(function(){const c="sidebar-display";var d=false;var b=$("body");return{toggle:function(){if(d==false){b.attr(c,"")}else{b.removeAttr(c)}d=!d}}})();$("#sidebar-trigger").click(a.toggle);$("#mask").click(a.toggle)});

View file

@ -1 +0,0 @@
$(function(){var d;var c=0;var e=5;var b=$("#topbar-wrapper").outerHeight();$(window).scroll(function(f){if($("#topbar-title").is(":hidden")){d=true}});setInterval(function(){if(d){a();d=false}},250);function a(){var f=$(this).scrollTop();if(Math.abs(c-f)<=e){return}if(f>c&&f>b){$("#topbar-wrapper").removeClass("topbar-down").addClass("topbar-up");if($("#toc-wrapper").length>0){$("#toc-wrapper").removeClass("topbar-down")}if($(".access").length>0){$(".access").removeClass("topbar-down")}if($("#search-input").is(":focus")){$("#search-input").blur()}}else{if(f+$(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")}}}c=f}});

View file

@ -1 +0,0 @@
$(function(){var a=$("#topbar-title").text().trim();var b=($("div.post>h1").length>0)?$("div.post>h1").text().trim():$("h1").text().trim();if($("#page-category").length||$("#page-tag").length){if(/\s/.test(b)){b=b.replace(/[0-9]/g,"").trim()}}$(window).scroll(function(){if($("#post-list").length||$("div.post>h1").is(":hidden")||$("#topbar-title").is(":hidden")||$("#sidebar.sidebar-expand").length){return false}if($(this).scrollTop()>=95){if($("#topbar-title").text()!=b){$("#topbar-title").text(b)}}else{if($("#topbar-title").text()!=a){$("#topbar-title").text(a)}}});$("#topbar-title").click(function(){$("body,html").animate({scrollTop:0},800)})});

View file

@ -1 +0,0 @@
$(function(){var b="l_";var a="h_";$(".collapse").on("hide.bs.collapse",function(){var c=a+$(this).attr("id").substring(b.length);if(c){$("#"+c+" .far.fa-folder-open").attr("class","far fa-folder fa-fw");$("#"+c+" i.fas").addClass("rotate");$("#"+c).removeClass("hide-border-bottom")}});$(".collapse").on("show.bs.collapse",function(){var c=a+$(this).attr("id").substring(b.length);if(c){$("#"+c+" .far.fa-folder").attr("class","far fa-folder-open fa-fw");$("#"+c+" i.fas").removeClass("rotate");$("#"+c).addClass("hide-border-bottom")}})});

View file

@ -1,12 +0,0 @@
---
# Aggregation of common JS.
# © 2018-2019 Cotes Chung
# MIT License
---
{% include_relative _commons/back-to-top.min.js %}
{% include_relative _commons/search-display.min.js %}
{% include_relative _commons/sidebar.min.js %}
{% include_relative _commons/topbar-switch.min.js %}
{% include_relative _commons/topbar-title.min.js %}
{% include_relative _commons/copy-link.min.js %}

View file

@ -1 +0,0 @@
function countUp(b,a,d){if(b<a){var c=new CountUp(d,b,a);if(!c.error){c.start()}else{console.error(c.error)}}}function countPV(f,e){var g=f.replace(/\/posts\//g,"").replace(/\//g,".html");var d=0;var c=f.replace(/posts\//g,"");for(var b=0;b<e.length;++b){var a=e[b][0];if(a==f||a==c||a.concat("/")==c||a.slice(a.lastIndexOf("/")+1)===g){d+=parseInt(e[b][1])}}return d}function tacklePV(e,f,d,b){var c=countPV(f,e);c=(c==0?1:c);if(!b){d.text(new Intl.NumberFormat().format(c))}else{var a=parseInt(d.text().replace(/,/g,""));if(c>a){countUp(a,c,d.attr("id"))}}}function displayPageviews(c){if(c===undefined){return}var a=getInitStatus();var b=c.rows;if($("#post-list").length>0){$(".post-preview").each(function(){var e=$(this).children("h1").children("a").attr("href");tacklePV(b,e,$(this).find(".pageviews"),a)})}else{if($(".post").length>0){var d=window.location.pathname;tacklePV(b,d,$("#pv"),a)}}}var getInitStatus=(function(){var a=false;return function(){let ret=a;if(!a){a=true}return ret}})();var PvCache=(function(){const e="pv";const b="pv-created-date";const d="pv-type";var c={ORIGIN:"origin",PROXY:"proxy"};function a(g){return localStorage.getItem(g)}function f(g,h){localStorage.setItem(g,h)}return{getData:function(){return JSON.parse(localStorage.getItem(e))},saveOriginCache:function(g){f(e,g);f(d,c.ORIGIN);f(b,new Date().toJSON())},saveProxyCache:function(g){f(e,g);f(d,c.PROXY);f(b,new Date().toJSON())},isOriginCache:function(){return a(d)==c.ORIGIN},isProxyCache:function(){return a(d)==c.PROXY},isExpired:function(){if(PvCache.isOriginCache()){let date=new Date(a(b));date.setDate(date.getDate()+1);return Date.now()>=date.getTime()}else{if(PvCache.isProxyCache()){let date=new Date(a(b));date.setHours(date.getHours()+1);return Date.now()>=date.getTime()}}return false},getAllPagevies:function(){return PvCache.getData().totalsForAllResults["ga:pageviews"]},newerThan:function(g){return PvCache.getAllPagevies()>g.totalsForAllResults["ga:pageviews"]}}})();function fetchOriginPageviews(a){if(a===undefined){return}displayPageviews(a);PvCache.saveOriginCache(JSON.stringify(a))}function fetchProxyPageviews(){let proxy=JSON.parse(proxyData);$.ajax({type:"GET",url:proxy.url,dataType:"jsonp",jsonpCallback:"displayPageviews",success:function(b,c,a){PvCache.saveProxyCache(JSON.stringify(b))},error:function(a,c,b){console.log("Failed to load pageviews from proxy server: "+b)}})}$(function(){if($(".pageviews").length>0){let cache=PvCache.getData();if(cache){if(PvCache.isExpired()){if(PvCache.isProxyCache()){let originPvData=pageviews?JSON.parse(pageviews):undefined;if(originPvData){if(PvCache.newerThan(originPvData)){displayPageviews(cache)}else{fetchOriginPageviews(originPvData)}}fetchProxyPageviews()}else{if(PvCache.isOriginCache()){fetchOriginPageviews(originPvData);fetchProxyPageviews()}}}else{displayPageviews(cache);if(PvCache.isOriginCache()){fetchProxyPageviews()}}}else{let originPvData=pageviews?JSON.parse(pageviews):undefined;fetchOriginPageviews(originPvData);fetchProxyPageviews()}}});

View file

@ -1 +0,0 @@
$(function(){function d(h,g){var f=new Date();var o=new Date(h);var n=Math.floor((f-o)/1000);var l=Math.floor(n/31536000);if(l>=1){return l+" year"+(l>1?"s":"")+" ago"}var k=Math.floor(n/2592000);if(k>=1){return k+" month"+(k>1?"s":"")+" ago"}var e=Math.floor(n/604800);if(e>=1){return e+" week"+(e>1?"s":"")+" ago"}var m=Math.floor(n/86400);if(m>=1){return m+" day"+(m>1?"s":"")+" ago"}var j=Math.floor(n/3600);if(j>=1){return j+" hour"+(j>1?"s":"")+" ago"}var i=Math.floor(n/60);if(i>=1){return i+" minute"+(i>1?"s":"")+" ago"}return(g?"just":"Just")+" now"}function c(){$(".timeago").each(function(){if($(this).children("i").length>0){var g=$(this).hasClass("lastmod");var f=$(this).children("i");var e=f.text();$(this).text(d(e,g));$(this).append(f)}});if(a==0&&b!=undefined){clearInterval(b)}return a}var a=$(".timeago").length;if(a==0){return}if(c()>0){a=$(".timeago").length;var b=setInterval(c,60000)}});

View file

@ -1 +0,0 @@
$(function(){if($("#post-wrapper .post-content h1").length==0&&$("#post-wrapper .post-content h2").length==0){$("#toc-wrapper").addClass("unloaded")}});

View file

@ -1 +0,0 @@
$(function(){$('[data-toggle="tooltip"]').tooltip()});

11
assets/js/home.min.js vendored Normal file
View file

@ -0,0 +1,11 @@
---
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 %}

11
assets/js/page.min.js vendored Normal file
View file

@ -0,0 +1,11 @@
---
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 %}

16
assets/js/post-toc.min.js vendored Normal file
View file

@ -0,0 +1,16 @@
---
layout: compress
# JS for layout post (with ToC).
# 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/toc.js %}

11
assets/js/post.min.js vendored Normal file
View file

@ -0,0 +1,11 @@
---
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 %}

3
sw.js
View file

@ -1,12 +1,13 @@
---
layout: compress
# Chirpy v2.2
# https://github.com/cotes2020/jekyll-theme-chirpy
# © 2020 Cotes Chung
# MIT Licensed
---
self.importScripts('{{ "/assets/data/cache-list.js" | relative_url }}');
self.importScripts('{{ "/assets/js/data/cache-list.js" | relative_url }}');
var cacheName = 'chirpy-{{ "now" | date: "%Y%m%d.%H%M" }}';

View file

@ -87,5 +87,3 @@ title: Categories
{% endif %}
{% endfor %}
<script src="{{ site.baseurl }}/assets/js/dist/category-collapse.min.js" async></script>

View file

@ -1,80 +0,0 @@
#!/bin/bash
#
# A development tool that use yuicompressor to compress JS files.
#
#
# Requirement:
# - wget
# - JRE
# - yuicompressor https://github.com/yui/yuicompressor
#
#
# Usage: bash /path/to/js-compress.sh
#
# Process:
# input: /path/to/js/source.js --> output: /path/to/js/dist/source.min.js
#
# v2.0
# https://github.com/cotes2020/jekyll-theme-chirpy
# © 2020 Cotes Chung
# MIT Licensed
set -eu
PROJ_HOME=$(dirname $(dirname $(realpath "$0")))
YUICOMPRESSOR_SRC=https://github.com/yui/yuicompressor/releases/download/v2.4.8/yuicompressor-2.4.8.jar
YUICOMPRESSOR=${PROJ_HOME}/tools/package/yuicompressor-2.4.8.jar
JS_ROOT=${PROJ_HOME}/assets/js/
JS_SRC=${JS_ROOT}_src # JS source files
JS_DEST=${JS_ROOT}dist # Compressed output directory
PREFIX_LEN=${#JS_ROOT} # To beautify the log
function init() {
if [[ ! -f $YUICOMPRESSOR ]]; then
if [[ ! -d "${PROJ_HOME}/tools/package/" ]]; then
mkdir -p "${PROJ_HOME}/tools/package/"
fi
wget "$YUICOMPRESSOR_SRC" -P "${PROJ_HOME}/tools/package/" -q
fi
}
function compress() {
# $1 is the source dir
# $2 is the destination dir
# $3 is the sub dir of source dir, nullable
if [[ -z ${3:+unset} ]]
then
sub_dir=""
else
sub_dir="$3/"
fi
for item in $(ls $1)
do
src="$1/$item"
if [[ -d "$src" ]]; then
compress $src $2 $item # recursion
else
if [[ -z $(git status $src -s) ]]; then
continue
fi
if [[ ! -d "$2/${sub_dir}" ]]; then
mkdir -p $2/${sub_dir}
fi
output=$2/${sub_dir}${item%.*}.min.js
echo "java -jar $(basename $YUICOMPRESSOR) ${src:$PREFIX_LEN} -o ${output:$PREFIX_LEN}"
java -jar $YUICOMPRESSOR $src -o $output
fi
done
sub_dir="" # clean up for next recursion.
}
init
compress $JS_SRC $JS_DEST