Parcourir la source

feat: update vendor assets & refactor custom CSS path

- Upgrade MathJax from v2 to v3
- Updated Highlight, Leaflet, Fancybox, Mermaid, FontAwesome
- Fixed multilingual icon paths in Web App Manifest
- View Demo script now binds to all network I/F to enable testing on
  other physical devices like smart phones

BREAKING CHANGES:
Removed `plugins_css` from `params.toml`.
Override `custom.scss` to add custom styling.

Close #1400
George Cushen il y a 5 ans
Parent
commit
ede8cef959

+ 11 - 5
assets/js/mathjax-config.js

@@ -1,10 +1,16 @@
+// MathJax Configuration
+//
+// v2 to v3 upgrade notes:
+// - The CommonHTML.linebreaks option is not yet implemented (but may be in a future release)
+// - The TeX.noUndefined.attributes option is not yet implemented (but may be in a future release)
 window.MathJax = {
-  CommonHTML: {linebreaks: {automatic: true}},
-  tex2jax: {
+  tex: {
     inlineMath: [['$', '$'], ['\\(', '\\)']],
     displayMath: [['$$', '$$'], ['\\[', '\\]']],
-    processEscapes: false
+    processEscapes: false,
+    packages: {'[+]': ['noerrors']}
   },
-  TeX: {noUndefined: {attributes: {mathcolor: 'red', mathbackground: '#FFEEEE', mathsize: '90%'}}},
-  messageStyle: 'none'
+  loader: {
+    load: ['[tex]/noerrors']
+  }
 };

+ 1 - 0
assets/sass/custom.scss

@@ -0,0 +1 @@
+// Override this file to add your own SCSS styling.

+ 1 - 0
assets/sass/main.scss

@@ -38,3 +38,4 @@ $sta-dark-home-section-even: {{ $scr.Get "dark_home_section_even" }};
 @import "bootstrap_variables";
 @import "vendor/bootstrap/bootstrap";
 @import "academic/academic";
+@import "custom";

+ 19 - 19
data/assets.toml

@@ -12,13 +12,13 @@
   sri = "sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
   url = "https://cdnjs.cloudflare.com/ajax/libs/jquery/%s/jquery.min.js"
 [js.highlight]
-  version = "9.15.6"
-  sri = "sha256-aYTdUrn6Ow1DDgh5JTc3aDGnnju48y/1c8s1dgkYPQ8="
+  version = "9.15.10"
+  sri = "sha256-1zu+3BnLYV9LdiY85uXMzii3bdrkelyp37e0ZyTAQh0="
   url = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/%s/highlight.min.js"
 [js.mathJax]
-  version = "2.7.4"
-  sri = "sha256-GhM+5JHb6QUzOQPXSJLEWP7R73CbkisjzK5Eyij4U9w="
-  url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/%s/MathJax.js?config=TeX-AMS_CHTML-full"
+  version = "3"
+  sri = ""  # No SRI as dynamically generated.
+  url = "https://cdn.jsdelivr.net/npm/mathjax@%s/es5/tex-chtml.js"
 [js.isotope]
   version = "3.0.6"
   sri = "sha256-CBrpuqrMhXwcLLUd5tvQ4euBHCdh7wGlDfNz8vbu/iI="
@@ -32,12 +32,12 @@
   sri = "sha256-7vjlAeb8OaTrCXZkCNun9djzuB2owUsaO72kXaFDBJs="
   url = "https://cdnjs.cloudflare.com/ajax/libs/gmaps.js/%s/gmaps.min.js"
 [js.leaflet]
-  version = "1.2.0"
-  sri = "sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log=="
+  version = "1.5.1"
+  sri = "sha256-EErZamuLefUnbMBQbsEqu1USa+btR2oIlCpBJbyD4/g="
   url = "https://cdnjs.cloudflare.com/ajax/libs/leaflet/%s/leaflet.js"
 [js.fancybox]
-  version = "3.2.5"
-  sri = "sha256-X5PoE3KU5l+JcX+w09p/wHl9AzK333C4hJ2I9S5mD4M="
+  version = "3.5.7"
+  sri = "sha256-yt2kYMy0w8AbtF89WXb2P1rfjcP/HTHLT7097U8Y5b8="
   url = "https://cdnjs.cloudflare.com/ajax/libs/fancybox/%s/jquery.fancybox.min.js"
 [js.fuse]
   version = "3.2.1"
@@ -56,27 +56,27 @@
   sri = "sha256-pB/deHc9CGfFpJRjC43imB29Rse8tak+5eXqntO94ck="
   url = "https://cdnjs.cloudflare.com/ajax/libs/anchor-js/%s/anchor.min.js"
 [js.mermaid]
-  version = "8.0.0"
-  sri = "sha256-0w92bcB21IY5+rGI84MGj52jNfHNbXVeQLrZ0CGdjNY="
+  version = "8.3.1"
+  sri = "sha256-vOIuDSYDirTfyr+S2MjFnhOz6Rgiz4ODFAHATG0rFxw="
   url = "https://cdnjs.cloudflare.com/ajax/libs/mermaid/%s/mermaid.min.js"
 
 # CSS
 
 [css.fontAwesome]
-  version = "5.6.0"
-  sri = "sha384-aOkxzJ5uQz7WBObEZcHvV5JvRW3TUc2rNPA7pe3AwnsUohiw1Vj2Rgx2KSOkF5+h"
-  url = "https://use.fontawesome.com/releases/v%s/css/all.css"
+  version = "5.11.2"
+  sri = "sha256-+N4/V/SbAFiW1MPBCXnfnP9QSN3+Keu+NlB+0ev/YKQ="
+  url = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/%s/css/all.min.css"
 [css.academicons]
   version = "1.8.6"
   sri = "sha256-uFVgMKfistnJAfoCUQigIl+JfUaP47GrRKjf6CTPVmw="
   url = "https://cdnjs.cloudflare.com/ajax/libs/academicons/%s/css/academicons.min.css"
 [css.leaflet]
-  version = "1.2.0"
-  sri = "sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ=="
+  version = "1.5.1"
+  sri = "sha256-SHMGCYmST46SoyGgo4YR/9AlK1vf3ff84Aq9yK4hdqM="
   url = "https://cdnjs.cloudflare.com/ajax/libs/leaflet/%s/leaflet.css"
 [css.fancybox]
-  version = "3.2.5"
-  sri = "sha256-ygkqlh3CYSUri3LhQxzdcm0n1EQvH2Y+U5S2idbLtxs="
+  version = "3.5.7"
+  sri = "sha256-Vzbj7sDDS/woiFS3uNKo8eIuni59rjyNGtXfstRzStA="
   url = "https://cdnjs.cloudflare.com/ajax/libs/fancybox/%s/jquery.fancybox.min.css"
 [css.instantsearch]
   version = "2.9.0"
@@ -87,6 +87,6 @@
   sri = "sha256-uL8LUd3zkI/lXvc/Hv/oOu8ld6RJcOZiUY/8c+I+3/o="
   url = "https://cdnjs.cloudflare.com/ajax/libs/instantsearch.js/%s/instantsearch-theme-algolia.min.css"
 [css.highlight]
-  version = "9.15.6"
+  version = "9.15.10"
   sri = ""  # No SRI as highlight style is determined at run time.
   url = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/%s/styles/%s.min.css"

+ 0 - 4
demo.sh

@@ -1,4 +0,0 @@
-#!/usr/bin/env bash
-
-cd exampleSite
-HUGO_THEME=academic hugo --themesDir ../../ -p 1315 --i18n-warnings server

+ 1 - 3
exampleSite/config/_default/params.toml

@@ -163,10 +163,8 @@ sharing = true
 # Link authors to their profile page? (true/false)
 link_authors = true
 
-# Load CSS and JS plugins
-#   E.g. To load `/assets/css/custom.css`, set `plugins_css = ["custom"]`.
+# Load JS plugins
 #   E.g. To load `/assets/js/custom.js`, set `plugins_js = ["custom"]`.
-plugins_css = []
 plugins_js  = []
 
 # Configuration of publication pages.

+ 2 - 2
layouts/index.webmanifest

@@ -6,11 +6,11 @@
   "theme_color": "{{ $scr.Get "primary" }}",
   "background_color": "{{ $scr.Get "primary" }}",
   "icons": [{
-    "src": "img/icon-192.png",
+    "src": "../img/icon-192.png",
     "sizes": "192x192",
     "type": "image/png"
     }, {
-    "src": "img/icon-512.png",
+    "src": "../img/icon-512.png",
     "sizes": "512x512",
     "type": "image/png"
      }],

+ 11 - 14
layouts/partials/site_head.html

@@ -100,23 +100,20 @@
   <link rel="stylesheet" {{ printf "href=\"https://fonts.googleapis.com/css?family=%s&display=swap\"" . | replaceRE "\\|" "%7C" | safeHTMLAttr }}>
   {{ end }}
 
-  {{ $css_options := (dict "targetPath" "css/academic.css" "outputStyle" "compressed") }}
+  {{ $css_comment := printf "/*!* Source Themes Academic v%s (https://sourcethemes.com/academic/) */\n" site.Data.academic.version }}
+  {{ $css_bundle_head := $css_comment | resources.FromString "css/bundle-head.css" }}
+  {{ $css_options := dict "targetPath" "css/academic.css" }}
+  {{- if (eq (getenv "HUGO_ENV") "production") -}}
+    {{- $css_options = merge $css_options (dict "outputStyle" "compressed") -}}
+  {{- end -}}
   {{ $sass_template := resources.Get "sass/main.scss" }}
-  {{ $style := $sass_template | resources.ExecuteAsTemplate "main_parsed.scss" . | toCSS $css_options | minify | fingerprint "md5" }}
+  {{ $style := $sass_template | resources.ExecuteAsTemplate "main_parsed.scss" . | toCSS $css_options }}
+  {{ $style := slice $css_bundle_head $style | resources.Concat "css/academic.css" }}
+  {{- if (eq (getenv "HUGO_ENV") "production") -}}
+    {{- $style = $style | minify | fingerprint "md5" -}}
+  {{- end -}}
   <link rel="stylesheet" href="{{ $style.RelPermalink }}">
 
-  {{ if site.Params.plugins_css }}
-    {{ $css_comment := printf "/* Source Themes Academic v%s | https://sourcethemes.com/academic/ */\n" site.Data.academic.version }}
-    {{ $css_bundle_head := $css_comment | resources.FromString "css/bundle-head.css" }}
-    {{ $css_bundle := slice }}
-    {{ range site.Params.plugins_css }}
-      {{ $css_bundle = $css_bundle | append (resources.Get (printf "css/%s.css" .)) }}
-    {{ end }}
-    {{ $css_bundle := $css_bundle | resources.Concat "css/academic-bundle-pre.css" | minify }}
-    {{ $css_bundle := slice $css_bundle_head $css_bundle | resources.Concat "css/academic.css" | fingerprint "md5" }}
-    <link rel="stylesheet" href="{{ $css_bundle.RelPermalink }}">
-  {{ end }}
-
   {{ partial "marketing/google_analytics" . }}
   {{ partial "marketing/google_tag_manager" . }}
 

+ 3 - 0
scripts/view_demo.sh

@@ -0,0 +1,3 @@
+#!/usr/bin/env zsh
+
+HUGO_THEME=academic hugo --source exampleSite --themesDir ../../ --i18n-warnings --bind=0.0.0.0 -p 1315 --baseURL=http://0.0.0.0:1315 server