From 05eb46ac3faefc5c56a9c0406148a11a03c59608 Mon Sep 17 00:00:00 2001 From: George <31376482+george-gca@users.noreply.github.com> Date: Mon, 23 Dec 2024 14:00:58 -0300 Subject: [PATCH] Replaced jekyll-minifier that uses uglifier by terser (#2571) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hopefully fixes #2548. --------- Signed-off-by: George Araujo Signed-off-by: George Araújo --- .prettierignore | 2 +- Gemfile | 1 + Gemfile.lock | 44 +-- _config.yml | 16 +- _includes/distill_scripts.liquid | 280 +++++++++++++++++++ _includes/head.liquid | 20 +- _includes/scripts.liquid | 312 +++++++++++++++++++++ _includes/scripts/analytics.liquid | 48 ---- _includes/scripts/back_to_top.liquid | 6 - _includes/scripts/badges.liquid | 6 - _includes/scripts/bootstrap.liquid | 8 - _includes/scripts/chartjs.liquid | 24 -- _includes/scripts/diff2html.liquid | 30 -- _includes/scripts/echarts.liquid | 45 --- _includes/scripts/imageLayouts.liquid | 60 ---- _includes/scripts/jekyll_tabs.liquid | 3 - _includes/scripts/jquery.liquid | 6 - _includes/scripts/leaflet.liquid | 31 --- _includes/scripts/masonry.liquid | 16 -- _includes/scripts/mathjax.liquid | 25 -- _includes/scripts/mermaid.liquid | 55 ---- _includes/scripts/misc.liquid | 43 --- _includes/scripts/newsletter.liquid | 176 ------------ _includes/scripts/progressBar.liquid | 78 ------ _includes/scripts/pseudocode.liquid | 52 ---- _includes/scripts/search.liquid | 350 ------------------------ _includes/scripts/tikzjax.liquid | 8 - _includes/scripts/typograms.liquid | 23 -- _includes/scripts/vega.liquid | 47 ---- _includes/scripts/wechatModal.liquid | 18 -- _includes/social.liquid | 2 +- _layouts/default.liquid | 23 +- _layouts/distill.liquid | 32 +-- _plugins/terser.rb | 102 +++++++ _scripts/search.liquid.js | 327 ++++++++++++++++++++++ assets/js/chartjs-setup.js | 14 + assets/js/cronitor-analytics-setup.js | 6 + assets/js/diff2html-setup.js | 20 ++ assets/js/echarts-setup.js | 29 ++ assets/js/google-analytics-setup.js | 6 + assets/js/leaflet-setup.js | 22 ++ assets/js/mathjax-setup.js | 5 + assets/js/mermaid-setup.js | 37 +++ assets/js/open-panel-analytics-setup.js | 11 + assets/js/photoswipe-setup.js | 8 + assets/js/progress-bar.js | 73 +++++ assets/js/pseudocode-setup.js | 33 +++ assets/js/search-setup.js | 17 ++ assets/js/tooltips-setup.js | 3 + assets/js/typograms.js | 21 +- assets/js/vega-setup.js | 24 ++ assets/js/venobox-setup.js | 5 + assets/js/wechat.js | 14 + 53 files changed, 1421 insertions(+), 1246 deletions(-) create mode 100644 _includes/distill_scripts.liquid create mode 100644 _includes/scripts.liquid delete mode 100644 _includes/scripts/analytics.liquid delete mode 100644 _includes/scripts/back_to_top.liquid delete mode 100644 _includes/scripts/badges.liquid delete mode 100644 _includes/scripts/bootstrap.liquid delete mode 100644 _includes/scripts/chartjs.liquid delete mode 100644 _includes/scripts/diff2html.liquid delete mode 100644 _includes/scripts/echarts.liquid delete mode 100644 _includes/scripts/imageLayouts.liquid delete mode 100644 _includes/scripts/jekyll_tabs.liquid delete mode 100644 _includes/scripts/jquery.liquid delete mode 100644 _includes/scripts/leaflet.liquid delete mode 100644 _includes/scripts/masonry.liquid delete mode 100644 _includes/scripts/mathjax.liquid delete mode 100644 _includes/scripts/mermaid.liquid delete mode 100644 _includes/scripts/misc.liquid delete mode 100644 _includes/scripts/newsletter.liquid delete mode 100644 _includes/scripts/progressBar.liquid delete mode 100644 _includes/scripts/pseudocode.liquid delete mode 100644 _includes/scripts/search.liquid delete mode 100644 _includes/scripts/tikzjax.liquid delete mode 100644 _includes/scripts/typograms.liquid delete mode 100644 _includes/scripts/vega.liquid delete mode 100644 _includes/scripts/wechatModal.liquid create mode 100644 _plugins/terser.rb create mode 100644 _scripts/search.liquid.js create mode 100644 assets/js/chartjs-setup.js create mode 100644 assets/js/cronitor-analytics-setup.js create mode 100644 assets/js/diff2html-setup.js create mode 100644 assets/js/echarts-setup.js create mode 100644 assets/js/google-analytics-setup.js create mode 100644 assets/js/leaflet-setup.js create mode 100644 assets/js/mathjax-setup.js create mode 100644 assets/js/mermaid-setup.js create mode 100644 assets/js/open-panel-analytics-setup.js create mode 100644 assets/js/photoswipe-setup.js create mode 100644 assets/js/progress-bar.js create mode 100644 assets/js/pseudocode-setup.js create mode 100644 assets/js/search-setup.js create mode 100644 assets/js/tooltips-setup.js create mode 100644 assets/js/vega-setup.js create mode 100644 assets/js/venobox-setup.js create mode 100644 assets/js/wechat.js diff --git a/.prettierignore b/.prettierignore index ef61d8d..2929bf4 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,7 +2,6 @@ **/*.min.css **/*.min.js assets/css/main.scss -assets/js/search-data.js assets/js/distillpub/template.v2.js assets/js/search/*.js assets/plotly/demo.html @@ -10,3 +9,4 @@ lighthouse_results/** _posts/2015-10-20-math.md _sass/font-awesome/*.scss _sass/tabler-icons/*.scss +_scripts/search.liquid.js diff --git a/Gemfile b/Gemfile index 9637fc0..09bfbf4 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ group :jekyll_plugins do gem 'jekyll-toc' gem 'jekyll-twitter-plugin' gem 'jemoji' + gem 'terser' gem 'unicode_utils' gem 'webrick' end diff --git a/Gemfile.lock b/Gemfile.lock index b2814ad..8f4eae1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - activesupport (8.0.0.1) + activesupport (8.0.1) base64 benchmark (>= 0.3) bigdecimal @@ -39,7 +39,7 @@ GEM rexml csl-styles (1.0.1.11) csl (~> 1.0) - css_parser (1.19.1) + css_parser (1.21.0) addressable cssminify2 (2.0.1) csv (3.3.0) @@ -166,7 +166,7 @@ GEM listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - logger (1.6.2) + logger (1.6.3) loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -178,17 +178,17 @@ GEM bigdecimal (~> 3.1) namae (1.2.0) racc (~> 1.7) - nokogiri (1.17.1-aarch64-linux) + nokogiri (1.17.2-aarch64-linux) racc (~> 1.4) - nokogiri (1.17.1-arm-linux) + nokogiri (1.17.2-arm-linux) racc (~> 1.4) - nokogiri (1.17.1-arm64-darwin) + nokogiri (1.17.2-arm64-darwin) racc (~> 1.4) - nokogiri (1.17.1-x86-linux) + nokogiri (1.17.2-x86-linux) racc (~> 1.4) - nokogiri (1.17.1-x86_64-darwin) + nokogiri (1.17.2-x86_64-darwin) racc (~> 1.4) - nokogiri (1.17.1-x86_64-linux) + nokogiri (1.17.2-x86_64-linux) racc (~> 1.4) pathutil (0.16.2) forwardable-extended (~> 2.6) @@ -201,30 +201,32 @@ GEM rexml (3.3.9) rouge (4.5.1) safe_yaml (1.0.5) - sass-embedded (1.82.0-aarch64-linux-gnu) + sass-embedded (1.83.0-aarch64-linux-gnu) google-protobuf (~> 4.28) - sass-embedded (1.82.0-aarch64-linux-musl) + sass-embedded (1.83.0-aarch64-linux-musl) google-protobuf (~> 4.28) - sass-embedded (1.82.0-arm-linux-gnueabihf) + sass-embedded (1.83.0-arm-linux-gnueabihf) google-protobuf (~> 4.28) - sass-embedded (1.82.0-arm-linux-musleabihf) + sass-embedded (1.83.0-arm-linux-musleabihf) google-protobuf (~> 4.28) - sass-embedded (1.82.0-arm64-darwin) + sass-embedded (1.83.0-arm64-darwin) google-protobuf (~> 4.28) - sass-embedded (1.82.0-x86-linux-gnu) + sass-embedded (1.83.0-x86-linux-gnu) google-protobuf (~> 4.28) - sass-embedded (1.82.0-x86-linux-musl) + sass-embedded (1.83.0-x86-linux-musl) google-protobuf (~> 4.28) - sass-embedded (1.82.0-x86_64-darwin) + sass-embedded (1.83.0-x86_64-darwin) google-protobuf (~> 4.28) - sass-embedded (1.82.0-x86_64-linux-gnu) + sass-embedded (1.83.0-x86_64-linux-gnu) google-protobuf (~> 4.28) - sass-embedded (1.82.0-x86_64-linux-musl) + sass-embedded (1.83.0-x86_64-linux-musl) google-protobuf (~> 4.28) sax-machine (1.3.2) securerandom (0.4.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) + terser (1.2.4) + execjs (>= 0.3.0, < 3) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uglifier (4.2.1) @@ -248,6 +250,7 @@ PLATFORMS x86-linux-gnu x86-linux-musl x86_64-darwin + x86_64-linux x86_64-linux-gnu x86_64-linux-musl @@ -273,8 +276,9 @@ DEPENDENCIES jekyll-toc jekyll-twitter-plugin jemoji + terser unicode_utils webrick BUNDLED WITH - 2.5.18 + 2.5.7 diff --git a/_config.yml b/_config.yml index ec7596d..32eaa03 100644 --- a/_config.yml +++ b/_config.yml @@ -181,7 +181,7 @@ kramdown: start_line: 1 # Includes & excludes -include: ["_pages"] +include: ["_pages", "_scripts"] exclude: - bin/ - CONTRIBUTING.md @@ -224,6 +224,7 @@ plugins: - jekyll-toc - jekyll-twitter-plugin - jemoji + - terser # Sitemap settings defaults: @@ -240,9 +241,16 @@ sass: # ----------------------------------------------------------------------------- jekyll-minifier: - exclude: ["robots.txt", "assets/js/search/*.js", "assets/libs/**/*"] - uglifier_args: - harmony: true + compress_javascript: false # set to false since we are using terser as the js minifier + # exclude: ["robots.txt", "assets/js/search/*.js"] + +# ----------------------------------------------------------------------------- +# Terser +# ----------------------------------------------------------------------------- + +terser: + compress: + drop_console: true # ----------------------------------------------------------------------------- # Jekyll Archives diff --git a/_includes/distill_scripts.liquid b/_includes/distill_scripts.liquid new file mode 100644 index 0000000..df4104c --- /dev/null +++ b/_includes/distill_scripts.liquid @@ -0,0 +1,280 @@ + + + + + + + +{% if page.mermaid and page.mermaid.enabled %} + + + {% if page.mermaid.zoomable %} + + {% endif %} + +{% endif %} + +{% if page.code_diff %} + + + + +{% endif %} + +{% if page.map %} + + + +{% endif %} + +{% if page.chart and page.chart.chartjs %} + + + +{% endif %} + +{% if page.chart and page.chart.echarts %} + + + {% if site.enable_darkmode %} + + {% endif %} + +{% endif %} + +{% if page.chart and page.chart.vega_lite %} + + + + + +{% endif %} + +{% if page.tikzjax %} + + +{% endif %} + +{% if page.typograms %} + + +{% endif %} + +{% if site.enable_tooltips %} + + +{% endif %} + +{% if site.enable_medium_zoom %} + + + +{% endif %} + +{% if page.toc and page.toc.sidebar %} + + +{% endif %} + +{% if page.pretty_table %} + + + +{% endif %} + + + + + + + + + + + +{% if site.enable_math %} + + + + + +{% endif %} + +{% if site.enable_google_analytics %} + + + + +{% endif %} + +{% if site.enable_cronitor_analytics %} + + + +{% endif %} +{% if site.enable_pirsch_analytics %} + +{% endif %} +{% if site.enable_openpanel_analytics %} + + +{% endif %} + +{% if site.enable_progressbar %} + + +{% endif %} + +{% if page.images %} + + {% if page.images.compare %} + + {% endif %} + {% if page.images.lightbox2 %} + + {% endif %} + {% if page.images.photoswipe %} + + {% endif %} + {% if page.images.slider %} + + {% endif %} + {% if page.images.spotlight %} + + {% endif %} + {% if page.images.venobox %} + + + {% endif %} +{% endif %} + +{% if page.tabs %} + + +{% endif %} + +{% if site.back_to_top %} + + + +{% endif %} + +{% if site.search_enabled %} + + + + + + +{% endif %} diff --git a/_includes/head.liquid b/_includes/head.liquid index b4d96ef..b869095 100644 --- a/_includes/head.liquid +++ b/_includes/head.liquid @@ -10,8 +10,8 @@ crossorigin="anonymous" > - {% if page.pretty_table %} + - {% if page.pseudocode %} + {% endif %} - {% if page.map %} + {% endif %} - {% if page.code_diff %} + {% if page.images.compare %} + {% endif %} - {% if page.images.lightbox2 %} + {% endif %} - {% if page.images.photoswipe %} + {% endif %} - {% if page.images.slider %} + {% endif %} - {% if page.images.spotlight %} + {% endif %} - {% if page.images.venobox %} + + + + + + + +{% if site.enable_masonry %} + + + + +{% endif %} + +{% if page.mermaid and page.mermaid.enabled %} + + + {% if page.mermaid.zoomable %} + + {% endif %} + +{% endif %} + +{% if page.code_diff %} + + + + +{% endif %} + +{% if page.map %} + + + +{% endif %} + +{% if page.chart and page.chart.chartjs %} + + + +{% endif %} + +{% if page.chart and page.chart.echarts %} + + + {% if site.enable_darkmode %} + + {% endif %} + +{% endif %} + +{% if page.chart and page.chart.vega_lite %} + + + + + +{% endif %} + +{% if page.tikzjax %} + + +{% endif %} + +{% if page.typograms %} + + +{% endif %} + +{% if site.enable_tooltips %} + + +{% endif %} + +{% if site.enable_medium_zoom %} + + + +{% endif %} + +{% if page.toc and page.toc.sidebar %} + + +{% endif %} + +{% if page.pretty_table %} + + + +{% endif %} + + + + + + + + + + +{% if site.enable_publication_badges.altmetric %} + +{% endif %} +{% if site.enable_publication_badges.dimensions %} + +{% endif %} + +{% if site.enable_math %} + + + {% unless page.pseudocode %} + + + {% else %} + + + {% endunless %} +{% endif %} + +{% if site.enable_google_analytics %} + + + + +{% endif %} + +{% if site.enable_cronitor_analytics %} + + + +{% endif %} +{% if site.enable_pirsch_analytics %} + +{% endif %} +{% if site.enable_openpanel_analytics %} + + +{% endif %} + +{% if site.enable_progressbar %} + + +{% endif %} + +{% if page.images %} + + {% if page.images.compare %} + + {% endif %} + {% if page.images.lightbox2 %} + + {% endif %} + {% if page.images.photoswipe %} + + {% endif %} + {% if page.images.slider %} + + {% endif %} + {% if page.images.spotlight %} + + {% endif %} + {% if page.images.venobox %} + + + {% endif %} +{% endif %} + +{% if page.tabs %} + + +{% endif %} + +{% if site.back_to_top %} + + + +{% endif %} + +{% if site.search_enabled %} + + + + + + +{% endif %} diff --git a/_includes/scripts/analytics.liquid b/_includes/scripts/analytics.liquid deleted file mode 100644 index 2b9b122..0000000 --- a/_includes/scripts/analytics.liquid +++ /dev/null @@ -1,48 +0,0 @@ -{% if site.enable_google_analytics %} - - - -{% endif %} -{% if site.enable_cronitor_analytics %} - - - -{% endif %} -{% if site.enable_pirsch_analytics %} - -{% endif %} -{% if site.enable_openpanel_analytics %} - - -{% endif %} diff --git a/_includes/scripts/back_to_top.liquid b/_includes/scripts/back_to_top.liquid deleted file mode 100644 index 0b74448..0000000 --- a/_includes/scripts/back_to_top.liquid +++ /dev/null @@ -1,6 +0,0 @@ -{% if site.back_to_top %} - - -{% endif %} diff --git a/_includes/scripts/badges.liquid b/_includes/scripts/badges.liquid deleted file mode 100644 index 7270690..0000000 --- a/_includes/scripts/badges.liquid +++ /dev/null @@ -1,6 +0,0 @@ -{% if site.enable_publication_badges.altmetric %} - -{% endif %} -{% if site.enable_publication_badges.dimensions %} - -{% endif %} diff --git a/_includes/scripts/bootstrap.liquid b/_includes/scripts/bootstrap.liquid deleted file mode 100644 index 2573e77..0000000 --- a/_includes/scripts/bootstrap.liquid +++ /dev/null @@ -1,8 +0,0 @@ - - - - diff --git a/_includes/scripts/chartjs.liquid b/_includes/scripts/chartjs.liquid deleted file mode 100644 index bb21be2..0000000 --- a/_includes/scripts/chartjs.liquid +++ /dev/null @@ -1,24 +0,0 @@ -{% if page.chart and page.chart.chartjs %} - - -{% endif %} diff --git a/_includes/scripts/diff2html.liquid b/_includes/scripts/diff2html.liquid deleted file mode 100644 index 0c9f0e0..0000000 --- a/_includes/scripts/diff2html.liquid +++ /dev/null @@ -1,30 +0,0 @@ -{% if page.code_diff %} - - - -{% endif %} diff --git a/_includes/scripts/echarts.liquid b/_includes/scripts/echarts.liquid deleted file mode 100644 index fce103d..0000000 --- a/_includes/scripts/echarts.liquid +++ /dev/null @@ -1,45 +0,0 @@ -{% if page.chart and page.chart.echarts %} - - {% if site.enable_darkmode %} - - {% endif %} - -{% endif %} diff --git a/_includes/scripts/imageLayouts.liquid b/_includes/scripts/imageLayouts.liquid deleted file mode 100644 index fb5475e..0000000 --- a/_includes/scripts/imageLayouts.liquid +++ /dev/null @@ -1,60 +0,0 @@ -{% if page.images %} - {% if page.images.compare %} - - {% endif %} - {% if page.images.lightbox2 %} - - {% endif %} - {% if page.images.photoswipe %} - - {% endif %} - {% if page.images.slider %} - - {% endif %} - {% if page.images.spotlight %} - - {% endif %} - {% if page.images.venobox %} - - - {% endif %} -{% endif %} diff --git a/_includes/scripts/jekyll_tabs.liquid b/_includes/scripts/jekyll_tabs.liquid deleted file mode 100644 index 57d08ac..0000000 --- a/_includes/scripts/jekyll_tabs.liquid +++ /dev/null @@ -1,3 +0,0 @@ -{% if page.tabs %} - -{% endif %} diff --git a/_includes/scripts/jquery.liquid b/_includes/scripts/jquery.liquid deleted file mode 100644 index 6663530..0000000 --- a/_includes/scripts/jquery.liquid +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/_includes/scripts/leaflet.liquid b/_includes/scripts/leaflet.liquid deleted file mode 100644 index 393fdf4..0000000 --- a/_includes/scripts/leaflet.liquid +++ /dev/null @@ -1,31 +0,0 @@ -{% if page.map %} - - -{% endif %} diff --git a/_includes/scripts/masonry.liquid b/_includes/scripts/masonry.liquid deleted file mode 100644 index ec07f18..0000000 --- a/_includes/scripts/masonry.liquid +++ /dev/null @@ -1,16 +0,0 @@ -{% if site.enable_masonry %} - - - - -{% endif %} diff --git a/_includes/scripts/mathjax.liquid b/_includes/scripts/mathjax.liquid deleted file mode 100644 index df9d5fa..0000000 --- a/_includes/scripts/mathjax.liquid +++ /dev/null @@ -1,25 +0,0 @@ -{% if site.enable_math %} - {% unless page.pseudocode %} - - - - - {% endunless %} -{% endif %} diff --git a/_includes/scripts/mermaid.liquid b/_includes/scripts/mermaid.liquid deleted file mode 100644 index 8edab72..0000000 --- a/_includes/scripts/mermaid.liquid +++ /dev/null @@ -1,55 +0,0 @@ -{% if page.mermaid and page.mermaid.enabled %} - - {% if page.mermaid.zoomable %} - - {% endif %} - -{% endif %} diff --git a/_includes/scripts/misc.liquid b/_includes/scripts/misc.liquid deleted file mode 100644 index 56d68f5..0000000 --- a/_includes/scripts/misc.liquid +++ /dev/null @@ -1,43 +0,0 @@ -{% if site.enable_tooltips %} - - -{% endif %} -{% if site.enable_medium_zoom %} - - - -{% endif %} -{% if page.toc and page.toc.sidebar %} - - -{% endif %} - - -{% if page.pretty_table %} - - -{% endif %} - - - - - - - - - -{% assign site.test-library.url = site.test-library.url | append: 'teste' %} diff --git a/_includes/scripts/newsletter.liquid b/_includes/scripts/newsletter.liquid deleted file mode 100644 index 0204ffa..0000000 --- a/_includes/scripts/newsletter.liquid +++ /dev/null @@ -1,176 +0,0 @@ - - - - - diff --git a/_includes/scripts/progressBar.liquid b/_includes/scripts/progressBar.liquid deleted file mode 100644 index 08d1915..0000000 --- a/_includes/scripts/progressBar.liquid +++ /dev/null @@ -1,78 +0,0 @@ -{% if site.enable_progressbar %} - - -{% endif %} diff --git a/_includes/scripts/pseudocode.liquid b/_includes/scripts/pseudocode.liquid deleted file mode 100644 index be942ed..0000000 --- a/_includes/scripts/pseudocode.liquid +++ /dev/null @@ -1,52 +0,0 @@ -{% if site.enable_math and page.pseudocode %} - - - - - -{% endif %} diff --git a/_includes/scripts/search.liquid b/_includes/scripts/search.liquid deleted file mode 100644 index 4b7308b..0000000 --- a/_includes/scripts/search.liquid +++ /dev/null @@ -1,350 +0,0 @@ -{% if site.search_enabled %} - - - - - -{% endif %} diff --git a/_includes/scripts/tikzjax.liquid b/_includes/scripts/tikzjax.liquid deleted file mode 100644 index 2bd6e91..0000000 --- a/_includes/scripts/tikzjax.liquid +++ /dev/null @@ -1,8 +0,0 @@ -{% if page.tikzjax %} - -{% endif %} diff --git a/_includes/scripts/typograms.liquid b/_includes/scripts/typograms.liquid deleted file mode 100644 index 0983b2c..0000000 --- a/_includes/scripts/typograms.liquid +++ /dev/null @@ -1,23 +0,0 @@ -{% if page.typograms %} - - - -{% endif %} diff --git a/_includes/scripts/vega.liquid b/_includes/scripts/vega.liquid deleted file mode 100644 index 49f1236..0000000 --- a/_includes/scripts/vega.liquid +++ /dev/null @@ -1,47 +0,0 @@ -{% if page.chart and page.chart.vega_lite %} - - - - - -{% endif %} diff --git a/_includes/scripts/wechatModal.liquid b/_includes/scripts/wechatModal.liquid deleted file mode 100644 index aea2e04..0000000 --- a/_includes/scripts/wechatModal.liquid +++ /dev/null @@ -1,18 +0,0 @@ - - - diff --git a/_includes/social.liquid b/_includes/social.liquid index 9535c17..308a928 100644 --- a/_includes/social.liquid +++ b/_includes/social.liquid @@ -77,7 +77,7 @@
WeChat QR
- {% include scripts/wechatModal.liquid %} + {% when 'whatsapp_number' %} {% when 'wikidata_id' %} diff --git a/_layouts/default.liquid b/_layouts/default.liquid index 3f4af10..ea10370 100644 --- a/_layouts/default.liquid +++ b/_layouts/default.liquid @@ -51,27 +51,6 @@ {% include footer.liquid %} - {% include scripts/jquery.liquid %} - {% include scripts/bootstrap.liquid %} - {% include scripts/masonry.liquid %} - {% include scripts/mermaid.liquid %} - {% include scripts/diff2html.liquid %} - {% include scripts/leaflet.liquid %} - {% include scripts/chartjs.liquid %} - {% include scripts/echarts.liquid %} - {% include scripts/vega.liquid %} - {% include scripts/tikzjax.liquid %} - {% include scripts/typograms.liquid %} - {% include scripts/misc.liquid %} - {% include scripts/badges.liquid %} - {% include scripts/mathjax.liquid %} - {% include scripts/pseudocode.liquid %} - {% include scripts/analytics.liquid %} - {% include scripts/progressBar.liquid %} - {% include scripts/wechatModal.liquid %} - {% include scripts/imageLayouts.liquid %} - {% include scripts/jekyll_tabs.liquid %} - {% include scripts/back_to_top.liquid %} - {% include scripts/search.liquid %} + {% include scripts.liquid %} diff --git a/_layouts/distill.liquid b/_layouts/distill.liquid index e5a8bc4..63a0b46 100644 --- a/_layouts/distill.liquid +++ b/_layouts/distill.liquid @@ -2,30 +2,6 @@ {% include head.liquid %} - {% if site.enable_medium_zoom %} - - - - {% endif %} - {% include scripts/jquery.liquid %} - {% include scripts/mathjax.liquid %} - {% include scripts/mermaid.liquid %} - {% include scripts/diff2html.liquid %} - {% include scripts/leaflet.liquid %} - {% include scripts/chartjs.liquid %} - {% include scripts/echarts.liquid %} - {% include scripts/vega.liquid %} - {% include scripts/tikzjax.liquid %} - {% include scripts/typograms.liquid %} - {% include scripts/misc.liquid %} - {% comment %} - misc.liquid loads interactive features like the code copy button to prevent dynamic elements from displaying incorrectly at the end of the article. - {% endcomment %} @@ -131,10 +107,8 @@ {% include footer.liquid %} - {% include scripts/bootstrap.liquid %} - {% include scripts/analytics.liquid %} - {% include scripts/progressBar.liquid %} - {% include scripts/back_to_top.liquid %} - {% include scripts/search.liquid %} + + + {% include distill_scripts.liquid %} diff --git a/_plugins/terser.rb b/_plugins/terser.rb new file mode 100644 index 0000000..830c574 --- /dev/null +++ b/_plugins/terser.rb @@ -0,0 +1,102 @@ +# based on https://github.com/RobertoJBeltran/jekyll-terser +# it should be changed to use `jekyll-terser` gem after https://github.com/RobertoJBeltran/jekyll-terser/pull/1 is merged +require 'terser' + +module Jekyll + module Terser + class JSFile < Jekyll::StaticFile + @@mtimes = {} + + # Initialize a new JSFile. + # +site+ is the Site + # +base+ is the String path to the + # +dir+ is the String path between and the file + # +name+ is the String filename of the file + # +terser+ is the Terser instance + def initialize(site, base, dir, name, terser = nil) + super(site, base, dir, name) + @site = site + @base = base + @dir = dir + @name = name + if terser.nil? + if site.config["terser"].nil? + options = {} + else + options = site.config["terser"] + end + @terser = ::Terser.new(options.transform_keys(&:to_sym)) + + else + @terser = terser + end + end + + # Obtain destination path. + # +dest+ is the String path to the destination dir + # + # Returns destination file path. + def destination(dest) + File.join(dest, @dir, @name) + end + + # Process the .js file + # +dest+ is the String path to the destination dir + # + # Returns false if the file was not modified since last time (no-op). + def write(dest) + dest_path = destination(dest) + + return false if File.exist? dest_path and !modified? + @@mtimes[path] = mtime + + FileUtils.mkdir_p(File.dirname(dest_path)) + begin + content = File.read(path) + content = @terser.compile(content) + File.open(dest_path, 'w') do |f| + f.write(content) + end + rescue => e + STDERR.puts "Terser Exception: #{e.message}" + end + + true + end + end + + class TerserGenerator < Jekyll::Generator + safe true + + # Initialize options from site config. + def initialize(config = {}) + # check if options is not empty + if config["terser"].nil? + @options = {} + else + @options = config["terser"] + end + + @terser = ::Terser.new(@options.transform_keys(&:to_sym)) + end + + # Jekyll will have already added the *.js files as Jekyll::StaticFile + # objects to the static_files array. Here we replace those with a + # JSFile object. + def generate(site) + site.static_files.clone.each do |sf| + # do not process already minified files + if sf.kind_of?(Jekyll::StaticFile) && sf.path =~ /\.js$/ && !sf.path.end_with?(".min.js") + puts "Terser: Minifying #{sf.path}" + site.static_files.delete(sf) + name = File.basename(sf.path) + destination = File.dirname(sf.path).sub(site.source, '') + + js_file = JSFile.new(site, site.source, destination, name, @terser) + site.static_files << js_file + end + end + end + end + end +end diff --git a/_scripts/search.liquid.js b/_scripts/search.liquid.js new file mode 100644 index 0000000..12bb5a9 --- /dev/null +++ b/_scripts/search.liquid.js @@ -0,0 +1,327 @@ +--- +permalink: /assets/js/search-data.js +--- +// get the ninja-keys element +const ninja = document.querySelector('ninja-keys'); + +// add the home and posts menu items +ninja.data = [ + {%- for page in site.pages -%} + {%- if page.permalink == '/' -%}{%- assign about_title = page.title | strip -%}{%- endif -%} + {%- endfor -%} + { + id: "nav-{{ about_title | slugify }}", + title: "{{ about_title | truncatewords: 13 }}", + section: "Navigation", + handler: () => { + window.location.href = "{{ '/' | relative_url }}"; + }, + }, + {%- assign sorted_pages = site.pages | sort: "nav_order" -%} + {%- for p in sorted_pages -%} + {%- if p.nav and p.autogen == null -%} + {%- if p.dropdown -%} + {%- for child in p.children -%} + {%- unless child.title == 'divider' -%} + { + {%- assign title = child.title | escape | strip -%} + {%- if child.permalink contains "/blog/" -%}{%- assign url = "/blog/" -%} {%- else -%}{%- assign url = child.url -%}{%- endif -%} + id: "dropdown-{{ title | slugify }}", + title: "{{ title | truncatewords: 13 }}", + description: "{{ child.description | strip_html | strip_newlines | escape | strip }}", + section: "Dropdown", + handler: () => { + window.location.href = "{{ url | relative_url }}"; + }, + }, + {%- endunless -%} + {%- endfor -%} + + {%- else -%} + { + {%- assign title = p.title | escape | strip -%} + {%- if p.permalink contains "/blog/" -%}{%- assign url = "/blog/" -%} {%- else -%}{%- assign url = p.url -%}{%- endif -%} + id: "nav-{{ title | slugify }}", + title: "{{ title | truncatewords: 13 }}", + description: "{{ p.description | strip_html | strip_newlines | escape | strip }}", + section: "Navigation", + handler: () => { + window.location.href = "{{ url | relative_url }}"; + }, + }, + {%- endif -%} + {%- endif -%} + {%- endfor -%} + {%- for post in site.posts -%} + { + {%- assign title = post.title | escape | strip -%} + id: "post-{{ title | slugify }}", + {% if post.redirect == blank %} + title: "{{ title | truncatewords: 13 }}", + {% elsif post.redirect contains '://' %} + title: '{{ title | truncatewords: 13 }} ', + {% else %} + title: "{{ title | truncatewords: 13 }}", + {% endif %} + description: "{{ post.description | strip_html | strip_newlines | escape | strip }}", + section: "Posts", + handler: () => { + {% if post.redirect == blank %} + window.location.href = "{{ post.url | relative_url }}"; + {% elsif post.redirect contains '://' %} + window.open("{{ post.redirect }}", "_blank"); + {% else %} + window.location.href = "{{ post.redirect | relative_url }}"; + {% endif %} + }, + }, + {%- endfor -%} + {%- for collection in site.collections -%} + {%- if collection.label != 'posts' -%} + {%- for item in collection.docs -%} + { + {%- if item.inline -%} + {%- assign title = item.content | newline_to_br | replace: "
", " " | replace: "
", " " | strip_html | strip_newlines | escape | strip -%} + {%- else -%} + {%- assign title = item.title | newline_to_br | replace: "
", " " | replace: "
", " " | strip_html | strip_newlines | escape | strip -%} + {%- endif -%} + id: "{{ collection.label }}-{{ title | slugify }}", + title: '{{ title | escape | emojify | truncatewords: 13 }}', + description: "{{ item.description | strip_html | strip_newlines | escape | strip }}", + section: "{{ collection.label | capitalize }}", + {%- unless item.inline -%} + handler: () => { + window.location.href = "{{ item.url | relative_url }}"; + }, + {%- endunless -%} + }, + {%- endfor -%} + {%- endif -%} + {%- endfor -%} + {%- if site.socials_in_search -%} + {%- for social in site.data.socials -%} + {%- case social[0] -%} + {%- when "acm_id" -%} + {%- assign social_id = "social-acm" -%} + {%- assign social_title = "ACM DL" -%} + {%- capture social_url %}"https://dl.acm.org/profile/{{ social[1] }}/"{% endcapture -%} + {%- when "blogger_url" -%} + {%- assign social_id = "social-blogger" -%} + {%- assign social_title = "Blogger" -%} + {%- capture social_url %}"{{ social[1] }}"{% endcapture -%} + {%- when "bluesky_url" -%} + {%- assign social_id = "social-bluesky" -%} + {%- assign social_title = "Bluesky" -%} + {%- capture social_url %}"{{ social[1] }}"{% endcapture -%} + {%- when "dblp_url" -%} + {%- assign social_id = "social-dblp" -%} + {%- assign social_title = "DBLP" -%} + {%- capture social_url %}"{{ social[1] }}"{% endcapture -%} + {%- when "discord_id" -%} + {%- assign social_id = "social-discord" -%} + {%- assign social_title = "Discord" -%} + {%- capture social_url %}"https://discord.com/users/{{ social[1] }}"{% endcapture -%} + {%- when "email" -%} + {%- assign social_id = "social-email" -%} + {%- assign social_title = "email" -%} + {%- capture social_url %}"mailto:{{ social[1] | encode_email }}"{% endcapture -%} + {%- when "facebook_id" -%} + {%- assign social_id = "social-facebook" -%} + {%- assign social_title = "Facebook" -%} + {%- capture social_url %}"https://facebook.com/{{ social[1] }}"{% endcapture -%} + {%- when "flickr_id" -%} + {%- assign social_id = "social-flickr" -%} + {%- assign social_title = "Flickr" -%} + {%- capture social_url %}"https://www.flickr.com/{{ social[1] }}"{% endcapture -%} + {%- when "github_username" -%} + {%- assign social_id = "social-github" -%} + {%- assign social_title = "GitHub" -%} + {%- capture social_url %}"https://github.com/{{ social[1] }}"{% endcapture -%} + {%- when "gitlab_username" -%} + {%- assign social_id = "social-gitlab" -%} + {%- assign social_title = "GitLab" -%} + {%- capture social_url %}"https://gitlab.com/{{ social[1] }}"{% endcapture -%} + {%- when "ieee_id" -%} + {%- assign social_id = "social-ieee" -%} + {%- assign social_title = "IEEE Xplore" -%} + {%- capture social_url %}"https://ieeexplore.ieee.org/author/{{ social[1] }}/"{% endcapture -%} + {%- when "inspirehep_id" -%} + {%- assign social_id = "social-inspire" -%} + {%- assign social_title = "Inspire HEP" -%} + {%- capture social_url %}"https://inspirehep.net/authors/{{ social[1] }}"{% endcapture -%} + {%- when "instagram_id" -%} + {%- assign social_id = "social-instagram" -%} + {%- assign social_title = "Instagram" -%} + {%- capture social_url %}"https://instagram.com/{{ social[1] }}"{% endcapture -%} + {%- when "kaggle_id" -%} + {%- assign social_id = "social-kaggle" -%} + {%- assign social_title = "Kaggle" -%} + {%- capture social_url %}"https://www.kaggle.com/{{ social[1] }}"{% endcapture -%} + {%- when "keybase_username" -%} + {%- assign social_id = "social-keybase" -%} + {%- assign social_title = "Keybase" -%} + {%- capture social_url %}"https://keybase.io/{{ social[1] }}"{% endcapture -%} + {%- when "lastfm_id" -%} + {%- assign social_id = "social-lastfm" -%} + {%- assign social_title = "Last FM" -%} + {%- capture social_url %}"https://www.last.fm/user/{{ social[1] }}"{% endcapture -%} + {%- when "lattes_id" -%} + {%- assign social_id = "social-lattes" -%} + {%- assign social_title = "Lattes" -%} + {%- capture social_url %}"http://lattes.cnpq.br/{{ social[1] }}"{% endcapture -%} + {%- when "leetcode_id" -%} + {%- assign social_id = "social-leetcode" -%} + {%- assign social_title = "LeetCode" -%} + {%- capture social_url %}"https://leetcode.com/u/{{ social[1] }}/"{% endcapture -%} + {%- when "linkedin_username" -%} + {%- assign social_id = "social-linkedin" -%} + {%- assign social_title = "LinkedIn" -%} + {%- capture social_url %}"https://www.linkedin.com/in/{{ social[1] }}"{% endcapture -%} + {%- when "mastodon_username" -%} + {%- assign social_id = "social-mastodon" -%} + {%- assign social_title = "Mastodon" -%} + {%- capture social_url %}"https://{{ social[1] }}"{% endcapture -%} + {%- when "medium_username" -%} + {%- assign social_id = "social-medium" -%} + {%- assign social_title = "Medium" -%} + {%- capture social_url %}"https://medium.com/@{{ social[1] }}"{% endcapture -%} + {%- when "orcid_id" -%} + {%- assign social_id = "social-orcid" -%} + {%- assign social_title = "ORCID" -%} + {%- capture social_url %}"https://orcid.org/{{ social[1] }}"{% endcapture -%} + {%- when "osf_id" -%} + {%- assign social_id = "social-osf" -%} + {%- assign social_title = "Open Science Framework" -%} + {%- capture social_url %}"https://osf.io/{{ social[1] }}/"{% endcapture -%} + {%- when "pinterest_id" -%} + {%- assign social_id = "social-pinterest" -%} + {%- assign social_title = "Pinterest" -%} + {%- capture social_url %}"https://www.pinterest.com/{{ social[1] }}"{% endcapture -%} + {%- when "publons_id" -%} + {%- assign social_id = "social-publons" -%} + {%- assign social_title = "Publons" -%} + {%- capture social_url %}"https://publons.com/a/{{ social[1] }}/"{% endcapture -%} + {%- when "quora_username" -%} + {%- assign social_id = "social-quora" -%} + {%- assign social_title = "Quora" -%} + {%- capture social_url %}"https://www.quora.com/profile/{{ social[1] }}"{% endcapture -%} + {%- when "research_gate_profile" -%} + {%- assign social_id = "social-researchgate" -%} + {%- assign social_title = "ResearchGate" -%} + {%- capture social_url %}"https://www.researchgate.net/profile/{{ social[1] }}/"{% endcapture -%} + {%- when "rss_icon" -%} + {%- assign social_id = "social-rss" -%} + {%- assign social_title = "RSS Feed" -%} + {%- capture social_url %}"{{ site.baseurl }}/feed.xml"{% endcapture -%} + {%- when "scholar_userid" -%} + {%- assign social_id = "social-scholar" -%} + {%- assign social_title = "Google Scholar" -%} + {%- capture social_url %}"https://scholar.google.com/citations?user={{ social[1] }}"{% endcapture -%} + {%- when "scopus_id" -%} + {%- assign social_id = "social-scopus" -%} + {%- assign social_title = "Scopus" -%} + {%- capture social_url %}"https://www.scopus.com/authid/detail.uri?authorId={{ social[1] }}"{% endcapture -%} + {%- when "semanticscholar_id" -%} + {%- assign social_id = "social-semanticscholar" -%} + {%- assign social_title = "Semantic Scholar" -%} + {%- capture social_url %}"https://www.semanticscholar.org/author/{{ social[1] }}"{% endcapture -%} + {%- when "spotify_id" -%} + {%- assign social_id = "social-spotify" -%} + {%- assign social_title = "Spotify" -%} + {%- capture social_url %}"https://open.spotify.com/user/{{ social[1] }}"{% endcapture -%} + {%- when "stackoverflow_id" -%} + {%- assign social_id = "social-stackoverflow" -%} + {%- assign social_title = "Stackoverflow" -%} + {%- capture social_url %}"https://stackoverflow.com/users/{{ social[1] }}"{% endcapture -%} + {%- when "strava_userid" -%} + {%- assign social_id = "social-strava" -%} + {%- assign social_title = "Strava" -%} + {%- capture social_url %}"https://www.strava.com/athletes/{{ social[1] }}"{% endcapture -%} + {%- when "telegram_username" -%} + {%- assign social_id = "social-telegram" -%} + {%- assign social_title = "telegram" -%} + {%- capture social_url %}"https://telegram.me/{{ social[1] }}"{% endcapture -%} + {%- when "unsplash_id" -%} + {%- assign social_id = "social-unsplash" -%} + {%- assign social_title = "Unsplash" -%} + {%- capture social_url %}"https://unsplash.com/@{{ social[1] }}"{% endcapture -%} + {%- comment -%} + // check how to add wechat qr code + {%- when "wechat_qr" -%} + {%- assign social_id = "social-wechat" -%} + {%- assign social_title = "WeChat" -%} + {%- capture social_url %}"https://wechat.com/{{ social[1] }}"{% endcapture -%} + {%- endcomment -%} + {%- when "whatsapp_number" -%} + {%- assign social_id = "social-whatsapp" -%} + {%- assign social_title = "whatsapp" -%} + {%- capture social_url %}"https://wa.me/{{ social[1] }}"{% endcapture -%} + {%- when "wikidata_id" -%} + {%- assign social_id = "social-wikidata" -%} + {%- assign social_title = "Wikidata" -%} + {%- capture social_url %}"https://www.wikidata.org/wiki/{{ social[1] }}"{% endcapture -%} + {%- when "wikipedia_id" -%} + {%- assign social_id = "social-wikipedia" -%} + {%- assign social_title = "Wikipedia" -%} + {%- capture social_url %}"https://wikipedia.org/wiki/User:{{ social[1] }}"{% endcapture -%} + {%- when "work_url" -%} + {%- assign social_id = "social-work" -%} + {%- assign social_title = "Work" -%} + {%- capture social_url %}"{{ social[1] }}"{% endcapture -%} + {%- when "x_username" -%} + {%- assign social_id = "social-x" -%} + {%- assign social_title = "X" -%} + {%- capture social_url %}"https://twitter.com/{{ social[1] }}"{% endcapture -%} + {%- when "youtube_id" -%} + {%- assign social_id = "social-youtube" -%} + {%- assign social_title = "YouTube" -%} + {%- capture social_url %}"https://youtube.com/@{{ social[1] }}"{% endcapture -%} + {%- when "zotero_username" -%} + {%- assign social_id = "social-zotero" -%} + {%- assign social_title = "Zotero" -%} + {%- capture social_url %}"https://www.zotero.org/{{ social[1] }}"{% endcapture -%} + {%- else -%} + {%- assign social_id = "social-" | append: social[0] -%} + {%- assign social_title = social[0] | capitalize -%} + {%- capture social_url %}"{{ social[1].url }}"{% endcapture -%} + {%- endcase -%} + { + id: '{{ social_id }}', + title: '{{ social_title }}', + section: 'Socials', + handler: () => { + window.open({{ social_url }}, "_blank"); + }, + }, + {%- endfor -%} + {%- endif -%} + {%- if site.enable_darkmode -%} + { + id: 'light-theme', + title: 'Change theme to light', + description: 'Change the theme of the site to Light', + section: 'Theme', + handler: () => { + setThemeSetting("light"); + }, + }, + { + id: 'dark-theme', + title: 'Change theme to dark', + description: 'Change the theme of the site to Dark', + section: 'Theme', + handler: () => { + setThemeSetting("dark"); + }, + }, + { + id: 'system-theme', + title: 'Use system default theme', + description: 'Change the theme of the site to System Default', + section: 'Theme', + handler: () => { + setThemeSetting("system"); + }, + }, + {%- endif -%} +]; diff --git a/assets/js/chartjs-setup.js b/assets/js/chartjs-setup.js new file mode 100644 index 0000000..b5c83d2 --- /dev/null +++ b/assets/js/chartjs-setup.js @@ -0,0 +1,14 @@ +$(document).ready(function () { + var $canvas = null, + $this = null, + _ctx = null, + _text = ""; + $(".language-chartjs").each(function () { + $this = $(this); + $canvas = $(""); + _text = $this.text(); + $this.text("").append($canvas); + _ctx = $canvas.get(0).getContext("2d"); + _ctx && _text && new Chart(_ctx, JSON.parse(_text)) && $this.attr("data-processed", true); + }); +}); diff --git a/assets/js/cronitor-analytics-setup.js b/assets/js/cronitor-analytics-setup.js new file mode 100644 index 0000000..537bc5b --- /dev/null +++ b/assets/js/cronitor-analytics-setup.js @@ -0,0 +1,6 @@ +window.cronitor = + window.cronitor || + function () { + (window.cronitor.q = window.cronitor.q || []).push(arguments); + }; +cronitor("config", { clientKey: "{{ site.cronitor_analytics }}" }); diff --git a/assets/js/diff2html-setup.js b/assets/js/diff2html-setup.js new file mode 100644 index 0000000..dedcd8b --- /dev/null +++ b/assets/js/diff2html-setup.js @@ -0,0 +1,20 @@ +let diff2HtmlTheme = determineComputedTheme(); + +/* Create diff2html as another node and hide the code block, appending the diff2html node after it + this is done to enable retrieving the code again when changing theme between light/dark */ +document.addEventListener("readystatechange", () => { + if (document.readyState === "complete") { + document.querySelectorAll("pre>code.language-diff2html").forEach((elem) => { + const textData = elem.textContent; + const backup = elem.parentElement; + backup.classList.add("unloaded"); + /* create diff node */ + let diffElement = document.createElement("div"); + diffElement.classList.add("diff2html"); + backup.after(diffElement); + const configuration = { colorScheme: diff2HtmlTheme, drawFileList: true, highlight: true, matching: "lines" }; + const diff2htmlUi = new Diff2HtmlUI(diffElement, textData, configuration); + diff2htmlUi.draw(); + }); + } +}); diff --git a/assets/js/echarts-setup.js b/assets/js/echarts-setup.js new file mode 100644 index 0000000..074f6ab --- /dev/null +++ b/assets/js/echarts-setup.js @@ -0,0 +1,29 @@ +let echartsTheme = determineComputedTheme(); + +/* Create echarts chart as another node and hide the code block, appending the echarts node after it + this is done to enable retrieving the code again when changing theme between light/dark */ +document.addEventListener("readystatechange", () => { + if (document.readyState === "complete") { + document.querySelectorAll("pre>code.language-echarts").forEach((elem) => { + const jsonData = elem.textContent; + const backup = elem.parentElement; + backup.classList.add("unloaded"); + /* create echarts node */ + let chartElement = document.createElement("div"); + chartElement.classList.add("echarts"); + backup.after(chartElement); + + /* create echarts */ + if (echartsTheme === "dark") { + var chart = echarts.init(chartElement, "dark-fresh-cut"); + } else { + var chart = echarts.init(chartElement); + } + + chart.setOption(JSON.parse(jsonData)); + window.addEventListener("resize", function () { + chart.resize(); + }); + }); + } +}); diff --git a/assets/js/google-analytics-setup.js b/assets/js/google-analytics-setup.js new file mode 100644 index 0000000..c66e201 --- /dev/null +++ b/assets/js/google-analytics-setup.js @@ -0,0 +1,6 @@ +window.dataLayer = window.dataLayer || []; +function gtag() { + window.dataLayer.push(arguments); +} +gtag("js", new Date()); +gtag("config", "{{ site.google_analytics }}"); diff --git a/assets/js/leaflet-setup.js b/assets/js/leaflet-setup.js new file mode 100644 index 0000000..d1f4607 --- /dev/null +++ b/assets/js/leaflet-setup.js @@ -0,0 +1,22 @@ +/* Create leaflet map as another node and hide the code block, appending the leaflet node after it */ +document.addEventListener("readystatechange", () => { + if (document.readyState === "complete") { + document.querySelectorAll("pre>code.language-geojson").forEach((elem) => { + const jsonData = elem.textContent; + const backup = elem.parentElement; + backup.classList.add("unloaded"); + /* create leaflet node */ + let mapElement = document.createElement("div"); + mapElement.classList.add("map"); + backup.after(mapElement); + + var map = L.map(mapElement); + L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", { + maxZoom: 19, + attribution: '© OpenStreetMap', + }).addTo(map); + let geoJSON = L.geoJSON(JSON.parse(jsonData)).addTo(map); + map.fitBounds(geoJSON.getBounds()); + }); + } +}); diff --git a/assets/js/mathjax-setup.js b/assets/js/mathjax-setup.js new file mode 100644 index 0000000..c821206 --- /dev/null +++ b/assets/js/mathjax-setup.js @@ -0,0 +1,5 @@ +window.MathJax = { + tex: { + tags: "ams", + }, +}; diff --git a/assets/js/mermaid-setup.js b/assets/js/mermaid-setup.js new file mode 100644 index 0000000..c555f92 --- /dev/null +++ b/assets/js/mermaid-setup.js @@ -0,0 +1,37 @@ +let mermaidTheme = determineComputedTheme(); + +/* Create mermaid diagram as another node and hide the code block, appending the mermaid node after it + this is done to enable retrieving the code again when changing theme between light/dark */ +document.addEventListener("readystatechange", () => { + if (document.readyState === "complete") { + document.querySelectorAll("pre>code.language-mermaid").forEach((elem) => { + const svgCode = elem.textContent; + const backup = elem.parentElement; + backup.classList.add("unloaded"); + /* create mermaid node */ + let mermaid = document.createElement("pre"); + mermaid.classList.add("mermaid"); + const text = document.createTextNode(svgCode); + mermaid.appendChild(text); + backup.after(mermaid); + }); + + mermaid.initialize({ theme: mermaidTheme }); + + /* Zoomable mermaid diagrams */ + if (typeof d3 !== "undefined") { + window.addEventListener("load", function () { + var svgs = d3.selectAll(".mermaid svg"); + svgs.each(function () { + var svg = d3.select(this); + svg.html("" + svg.html() + ""); + var inner = svg.select("g"); + var zoom = d3.zoom().on("zoom", function (event) { + inner.attr("transform", event.transform); + }); + svg.call(zoom); + }); + }); + } + } +}); diff --git a/assets/js/open-panel-analytics-setup.js b/assets/js/open-panel-analytics-setup.js new file mode 100644 index 0000000..fbd4833 --- /dev/null +++ b/assets/js/open-panel-analytics-setup.js @@ -0,0 +1,11 @@ +window.op = + window.op || + function (...args) { + (window.op.q = window.op.q || []).push(args); + }; +window.op("init", { + clientId: "{{ site.openpanel_analytics }}", + trackScreenViews: true, + trackOutgoingLinks: true, + trackAttributes: true, +}); diff --git a/assets/js/photoswipe-setup.js b/assets/js/photoswipe-setup.js new file mode 100644 index 0000000..dc6a74a --- /dev/null +++ b/assets/js/photoswipe-setup.js @@ -0,0 +1,8 @@ +import PhotoSwipeLightbox from "{{ site.third_party_libraries.photoswipe-lightbox.url.js }}"; +import PhotoSwipe from "{{ site.third_party_libraries.photoswipe.url.js }}"; +const photoswipe = new PhotoSwipeLightbox({ + gallery: ".pswp-gallery", + children: "a", + pswpModule: PhotoSwipe, +}); +photoswipe.init(); diff --git a/assets/js/progress-bar.js b/assets/js/progress-bar.js new file mode 100644 index 0000000..3604934 --- /dev/null +++ b/assets/js/progress-bar.js @@ -0,0 +1,73 @@ +/* + * This JavaScript code has been adapted from the article + * https://css-tricks.com/reading-position-indicator/ authored by Pankaj Parashar, + * published on the website https://css-tricks.com on the 7th of May, 2014. + * Couple of changes were made to the original code to make it compatible + * with the `al-foio` theme. + */ +const progressBar = $("#progress"); +/* + * We set up the bar after all elements are done loading. + * In some cases, if the images in the page are larger than the intended + * size they'll have on the page, they'll be resized via CSS to accomodate + * the desired size. This mistake, however, breaks the computations as the + * scroll size is computed as soon as the elements finish loading. + * To account for this, a minimal delay was introduced before computing the + * values. + */ +window.onload = function () { + setTimeout(progressBarSetup, 50); +}; +/* + * We set up the bar according to the browser. + * If the browser supports the progress element we use that. + * Otherwise, we resize the bar thru CSS styling + */ +function progressBarSetup() { + if ("max" in document.createElement("progress")) { + initializeProgressElement(); + $(document).on("scroll", function () { + progressBar.attr({ value: getCurrentScrollPosition() }); + }); + $(window).on("resize", initializeProgressElement); + } else { + resizeProgressBar(); + $(document).on("scroll", resizeProgressBar); + $(window).on("resize", resizeProgressBar); + } +} +/* + * The vertical scroll position is the same as the number of pixels that + * are hidden from view above the scrollable area. Thus, a value > 0 is + * how much the user has scrolled from the top + */ +function getCurrentScrollPosition() { + return $(window).scrollTop(); +} + +function initializeProgressElement() { + let navbarHeight = $("#navbar").outerHeight(true); + $("body").css({ "padding-top": navbarHeight }); + $("progress-container").css({ "padding-top": navbarHeight }); + progressBar.css({ top: navbarHeight }); + progressBar.attr({ + max: getDistanceToScroll(), + value: getCurrentScrollPosition(), + }); +} +/* + * The offset between the html document height and the browser viewport + * height will be greater than zero if vertical scroll is possible. + * This is the distance the user can scroll + */ +function getDistanceToScroll() { + return $(document).height() - $(window).height(); +} + +function resizeProgressBar() { + progressBar.css({ width: getWidthPercentage() + "%" }); +} +// The scroll ratio equals the percentage to resize the bar +function getWidthPercentage() { + return (getCurrentScrollPosition() / getDistanceToScroll()) * 100; +} diff --git a/assets/js/pseudocode-setup.js b/assets/js/pseudocode-setup.js new file mode 100644 index 0000000..8a16f83 --- /dev/null +++ b/assets/js/pseudocode-setup.js @@ -0,0 +1,33 @@ +window.MathJax = { + tex: { + inlineMath: [ + ["$", "$"], + ["\\(", "\\)"], + ], + displayMath: [ + ["$$", "$$"], + ["\\[", "\\]"], + ], + processEscapes: true, + processEnvironments: true, + }, +}; + +document.addEventListener("readystatechange", () => { + if (document.readyState === "complete") { + document.querySelectorAll("pre>code.language-pseudocode").forEach((elem) => { + const texData = elem.textContent; + const parent = elem.parentElement.parentElement; + /* create pseudocode node */ + let pseudoCodeElement = document.createElement("pre"); + pseudoCodeElement.classList.add("pseudocode"); + const text = document.createTextNode(texData); + pseudoCodeElement.appendChild(text); + /* add pseudocode node and remove the original code block */ + parent.appendChild(pseudoCodeElement); + parent.removeChild(elem.parentElement); + /* embed the visualization in the container */ + pseudocode.renderElement(pseudoCodeElement); + }); + } +}); diff --git a/assets/js/search-setup.js b/assets/js/search-setup.js new file mode 100644 index 0000000..12294f7 --- /dev/null +++ b/assets/js/search-setup.js @@ -0,0 +1,17 @@ +let searchTheme = determineComputedTheme(); +const ninjaKeys = document.querySelector("ninja-keys"); + +if (searchTheme === "dark") { + ninjaKeys.classList.add("dark"); +} else { + ninjaKeys.classList.remove("dark"); +} + +const openSearchModal = () => { + // collapse navbarNav if expanded on mobile + const $navbarNav = $("#navbarNav"); + if ($navbarNav.hasClass("show")) { + $navbarNav.collapse("hide"); + } + ninjaKeys.open(); +}; diff --git a/assets/js/tooltips-setup.js b/assets/js/tooltips-setup.js new file mode 100644 index 0000000..4c847cd --- /dev/null +++ b/assets/js/tooltips-setup.js @@ -0,0 +1,3 @@ +$(function () { + $('[data-toggle="tooltip"]').tooltip(); +}); diff --git a/assets/js/typograms.js b/assets/js/typograms.js index ba5327e..1d6eed4 100644 --- a/assets/js/typograms.js +++ b/assets/js/typograms.js @@ -1,5 +1,6 @@ // based on the original typograms code from https://github.com/google/typograms/blob/main/src/typograms.js -// only moved the css to its own file (_sass/_typograms.scss) and commented the last line of the file +// only moved the css to its own file (_sass/_typograms.scss), commented the last line of the file (module.exports = create;) +// and added the last function to the end of the file const ratio = 2; function grid(width, height) { @@ -1320,3 +1321,21 @@ function around(diagram, [x, y]) { } // module.exports = create; + +/* Create typogram as another node and hide the code block, appending the typogram node after it +this is done to enable retrieving the code again when changing theme between light/dark */ +document.addEventListener("readystatechange", () => { + if (document.readyState === "complete") { + document.querySelectorAll("pre>code.language-typograms").forEach((elem) => { + const texData = elem.textContent; + const parent = elem.parentElement.parentElement; + /* create typograms node */ + let typogram = document.createElement("pre"); + typogram.classList.add("typogram"); + const svg = create("\n" + texData, 0.3, false); + typogram.appendChild(svg); + parent.appendChild(typogram); + parent.removeChild(elem.parentElement); + }); + } +}); diff --git a/assets/js/vega-setup.js b/assets/js/vega-setup.js new file mode 100644 index 0000000..058ea3d --- /dev/null +++ b/assets/js/vega-setup.js @@ -0,0 +1,24 @@ +let vegaTheme = determineComputedTheme(); + +/* Create vega lite chart as another node and hide the code block, appending the vega lite node after it + this is done to enable retrieving the code again when changing theme between light/dark */ +document.addEventListener("readystatechange", () => { + if (document.readyState === "complete") { + document.querySelectorAll("pre>code.language-vega_lite").forEach((elem) => { + const jsonData = elem.textContent; + const backup = elem.parentElement; + backup.classList.add("unloaded"); + /* create vega lite node */ + let chartElement = document.createElement("div"); + chartElement.classList.add("vega-lite"); + backup.after(chartElement); + + /* Embed the visualization in the container */ + if (vegaTheme === "dark") { + vegaEmbed(chartElement, JSON.parse(jsonData), { theme: "dark" }); + } else { + vegaEmbed(chartElement, JSON.parse(jsonData)); + } + }); + } +}); diff --git a/assets/js/venobox-setup.js b/assets/js/venobox-setup.js new file mode 100644 index 0000000..582693e --- /dev/null +++ b/assets/js/venobox-setup.js @@ -0,0 +1,5 @@ +document.addEventListener("readystatechange", () => { + if (document.readyState === "complete") { + new VenoBox(); + } +}); diff --git a/assets/js/wechat.js b/assets/js/wechat.js new file mode 100644 index 0000000..2fa51aa --- /dev/null +++ b/assets/js/wechat.js @@ -0,0 +1,14 @@ +var wechatModal = document.getElementById("WeChatMod"); +var wechatBtn = document.querySelectorAll('[id="WeChatBtn"]'); + +for (var i = 0; i < wechatBtn.length; i++) { + wechatBtn[i].onclick = function () { + wechatModal.style.display = "block"; + }; +} + +window.onclick = function (event) { + if (event.target == wechatModal) { + wechatModal.style.display = "none"; + } +};