diff --git a/data/resources.yaml b/data/resources.yaml index 4b5fb64..88179ba 100644 --- a/data/resources.yaml +++ b/data/resources.yaml @@ -1,4 +1,4 @@ -# Public CDN vender list +# Public CDN vendor list # vendors: { "cdnjs": "//cdnjs.cloudflare.com/ajax/libs/${name}/${version}/${file}", @@ -8,7 +8,7 @@ vendors: { # Javascript Resources # js: - - name: anime + - name: animejs version: 3.2.1 file: lib/anime.min.js - name: mathjax diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 2bc5678..303616d 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -909,7 +909,7 @@ params: # The default CDN provider of third-party plugins. # Available values: local | jsdelivr | unpkg | cdnjs | custom # Dependencies for `plugins: local`: https://github.com/next-theme/plugins - plugins: unpkg + plugins: cdnjs # Custom CDN URL # For example: # custom_cdn_url: https://cdn.jsdelivr.net/npm/${npm_name}@${version}/${minified} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 9f96ec6..4f23cac 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,6 +1,10 @@ {{- $P := .Site.Params -}} {{- $lang := replaceRE "-([a-z]+)" (upper (substr .Site.Language -3)) .Site.Language -}} {{- .Scratch.Set "lang" $lang -}} +{{- $vendors := .Site.Data.resources.vendors -}} +{{- $pluginVen := $P.vendors.plugins -}} +{{- $pluginCDN := index $vendors $pluginVen -}} +{{- .Scratch.Set "pluginCDN" $pluginCDN -}} @@ -25,7 +29,7 @@
- {{- partial "header" (dict "P" $P "Page" .Page) }} + {{- partial "header" (dict "P" $P "Page" .Page "Scratch" .Scratch) }}
{{- if ne $P.sidebar.display "remove" }} @@ -42,6 +46,8 @@ {{- partial "footer" . }} + + {{- partial "scripts" (dict "P" $P "Page" .Page "Scratch" .Scratch) }} \ No newline at end of file diff --git a/layouts/partials/head/style.html b/layouts/partials/head/style.html index 0f7466e..7191eb9 100644 --- a/layouts/partials/head/style.html +++ b/layouts/partials/head/style.html @@ -1,17 +1,17 @@ -{{- $vendors := .Page.Site.Data.resources.vendors }} -{{- $pluginVen := .P.vendors.plugins }} -{{- $pluginCDN := index $vendors $pluginVen }} {{- $cssRes := .Page.Site.Data.resources.css }} +{{- $vendor := .P.vendors.plugins }} +{{- $vendorCDN := .Scratch.Get "pluginCDN" }} {{- range $css := $cssRes }} + {{- $pluginCSS := $vendorCDN }} {{- $npm := $css.name }} {{- $file := $css.file }} - {{- if eq $pluginVen "cndjs" }} - {{- $npm = $.css.alias }} - {{ $file }} - {{- $file = replaceRE "(dist|lib|source\\/js)\\/" "" $css.file }} + {{- if eq $vendor "cdnjs" }} + {{- with $css.alias }} + {{- $npm = . }} + {{- end }} + {{- $file = replaceRE `(dist|lib|source\/js)\/` "" $css.file }} {{- end }} - {{- $pluginCSS := $pluginCDN }} {{- $pluginCSS = replace $pluginCSS "${name}" $npm }} {{- $pluginCSS = replace $pluginCSS "${version}" $css.version }} {{- $pluginCSS = replace $pluginCSS "${file}" $file }} diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html new file mode 100644 index 0000000..d2d49bf --- /dev/null +++ b/layouts/partials/scripts.html @@ -0,0 +1,19 @@ + +{{- $jsRes := .Page.Site.Data.resources.js }} +{{- $vendor := .P.vendors.plugins }} +{{- $vendorCDN := .Scratch.Get "pluginCDN" }} +{{- range $js := $jsRes }} + {{- $pluginJS := $vendorCDN }} + {{- $npm := $js.name }} + {{- $file := $js.file }} + {{- if eq $vendor "cdnjs" }} + {{- with $js.alias }} + {{- $npm = . }} + {{- end }} + {{- $file = replaceRE `(dist|lib|source\/js)\/` "" $js.file }} + {{- end }} + {{- $pluginJS = replace $pluginJS "${name}" $npm }} + {{- $pluginJS = replace $pluginJS "${version}" $js.version }} + {{- $pluginJS = replace $pluginJS "${file}" $file }} + +{{- end }} \ No newline at end of file