From 1a2767ca248fe07b468ce9f6c1d96345f8c7f51f Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sat, 30 May 2020 00:48:10 +0800 Subject: [PATCH] Combine local JS. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ’yui-compressor’ is no longer used. --- _config.yml | 5 -- _includes/disqus.html | 2 +- _includes/head.html | 56 +++++-------- _includes/js-selector.html | 45 +++++++++++ _includes/search-loader.html | 5 +- assets/js/_commons.js | 21 +++++ assets/js/{_src => }/_commons/back-to-top.js | 0 assets/js/{_src => }/_commons/copy-link.js | 0 .../js/{_src => }/_commons/search-display.js | 0 assets/js/{_src => }/_commons/sidebar.js | 0 .../js/{_src => }/_commons/topbar-switch.js | 11 +-- assets/js/{_src => }/_commons/topbar-title.js | 17 ++-- assets/js/_home-post.js | 22 +++++ .../js/{_src => _utils}/category-collapse.js | 6 +- assets/js/{_src => _utils}/pageviews.js | 16 ++-- assets/js/{_src => _utils}/timeago.js | 0 assets/js/{_src => _utils}/toc.js | 0 assets/js/{_src => _utils}/tooltip-loader.js | 2 +- assets/js/categories.min.js | 13 +++ assets/{ => js}/data/cache-list.js | 22 +++-- .../{data/pv-data.json => js/data/pv-data.js} | 7 +- assets/{ => js}/data/search.json | 1 + assets/js/dist/_commons/back-to-top.min.js | 1 - assets/js/dist/_commons/copy-link.min.js | 1 - assets/js/dist/_commons/search-display.min.js | 1 - assets/js/dist/_commons/sidebar.min.js | 1 - assets/js/dist/_commons/topbar-switch.min.js | 1 - assets/js/dist/_commons/topbar-title.min.js | 1 - assets/js/dist/category-collapse.min.js | 1 - assets/js/dist/commons.js | 12 --- assets/js/dist/pageviews.min.js | 1 - assets/js/dist/timeago.min.js | 1 - assets/js/dist/toc.min.js | 1 - assets/js/dist/tooltip-loader.min.js | 1 - assets/js/home.min.js | 11 +++ .../lib/_bootstrap-toc.min.js} | 0 .../countUp.min.js => js/lib/_countUp.min.js} | 0 .../{ => js}/lib/jquery.disqusloader.min.js | 0 assets/js/page.min.js | 11 +++ assets/js/post-toc.min.js | 16 ++++ assets/js/post.min.js | 11 +++ sw.js | 3 +- tabs/categories.md | 2 - tools/js-compress.sh | 80 ------------------- 44 files changed, 213 insertions(+), 195 deletions(-) create mode 100644 _includes/js-selector.html create mode 100644 assets/js/_commons.js rename assets/js/{_src => }/_commons/back-to-top.js (100%) rename assets/js/{_src => }/_commons/copy-link.js (100%) rename assets/js/{_src => }/_commons/search-display.js (100%) rename assets/js/{_src => }/_commons/sidebar.js (100%) rename assets/js/{_src => }/_commons/topbar-switch.js (85%) rename assets/js/{_src => }/_commons/topbar-title.js (71%) create mode 100644 assets/js/_home-post.js rename assets/js/{_src => _utils}/category-collapse.js (85%) rename assets/js/{_src => _utils}/pageviews.js (92%) rename assets/js/{_src => _utils}/timeago.js (100%) rename assets/js/{_src => _utils}/toc.js (100%) rename assets/js/{_src => _utils}/tooltip-loader.js (97%) create mode 100644 assets/js/categories.min.js rename assets/{ => js}/data/cache-list.js (80%) rename assets/{data/pv-data.json => js/data/pv-data.js} (71%) rename assets/{ => js}/data/search.json (96%) delete mode 100644 assets/js/dist/_commons/back-to-top.min.js delete mode 100644 assets/js/dist/_commons/copy-link.min.js delete mode 100644 assets/js/dist/_commons/search-display.min.js delete mode 100644 assets/js/dist/_commons/sidebar.min.js delete mode 100644 assets/js/dist/_commons/topbar-switch.min.js delete mode 100644 assets/js/dist/_commons/topbar-title.min.js delete mode 100644 assets/js/dist/category-collapse.min.js delete mode 100644 assets/js/dist/commons.js delete mode 100644 assets/js/dist/pageviews.min.js delete mode 100644 assets/js/dist/timeago.min.js delete mode 100644 assets/js/dist/toc.min.js delete mode 100644 assets/js/dist/tooltip-loader.min.js create mode 100644 assets/js/home.min.js rename assets/{lib/bootstrap-toc-1.0.1/bootstrap-toc.min.js => js/lib/_bootstrap-toc.min.js} (100%) rename assets/{lib/countUp.min.js => js/lib/_countUp.min.js} (100%) rename assets/{ => js}/lib/jquery.disqusloader.min.js (100%) create mode 100644 assets/js/page.min.js create mode 100644 assets/js/post-toc.min.js create mode 100644 assets/js/post.min.js delete mode 100755 tools/js-compress.sh diff --git a/_config.yml b/_config.yml index 39b1517..4aa95e5 100644 --- a/_config.yml +++ b/_config.yml @@ -158,11 +158,6 @@ defaults: - label: Home url: / - - - scope: - path: assets/data - values: - layout: compress sass: diff --git a/_includes/disqus.html b/_includes/disqus.html index 3164122..692ca23 100644 --- a/_includes/disqus.html +++ b/_includes/disqus.html @@ -11,7 +11,7 @@
Comments powered by Disqus.
- + - - {% endif %} - {% endif %} - + - + - + - {% if page.layout == 'home' or page.layout == 'post' %} - - {% if site.google_analytics.pv.enabled %} - - - - {% endif %} - {% endif %} + - {% if site.toc and page.toc and page.layout == 'post' %} - - - - {% endif %} - - - - - {% if jekyll.environment == 'production' %} - - {% endif %} + {% include js-selector.html %} \ No newline at end of file diff --git a/_includes/js-selector.html b/_includes/js-selector.html new file mode 100644 index 0000000..390ae51 --- /dev/null +++ b/_includes/js-selector.html @@ -0,0 +1,45 @@ + + +{% if page.layout == 'home' %} + + + +{% elsif page.layout == 'post' %} + + {% if site.toc and page.toc %} + + {% else %} + + {% endif %} + + {% if page.math %} + + + + {% endif %} + +{% elsif page.layout == 'page' %} + + {% if page.title == 'Categories' %} + + {% else %} + + {% endif %} + +{% else %} + + + +{% endif %} + + + +{% if jekyll.environment == 'production' %} + +{% endif %} diff --git a/_includes/search-loader.html b/_includes/search-loader.html index f78891c..af7ebb1 100644 --- a/_includes/search-loader.html +++ b/_includes/search-loader.html @@ -5,7 +5,6 @@ © 2017-2019 Cotes Chung MIT License --> - {% capture result_elem %}Oops! No result founds.
{% endcapture %} + + diff --git a/tools/js-compress.sh b/tools/js-compress.sh deleted file mode 100755 index f416c76..0000000 --- a/tools/js-compress.sh +++ /dev/null @@ -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