👷 Add CDN vendor automatic switch by config setting.
This commit is contained in:
parent
65c3289491
commit
fc52303ad1
@ -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
|
||||
|
@ -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}
|
||||
|
@ -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 -}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ $lang }}">
|
||||
|
||||
@ -25,7 +29,7 @@
|
||||
<main class="main">
|
||||
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
|
||||
<div class="header-inner">
|
||||
{{- partial "header" (dict "P" $P "Page" .Page) }}
|
||||
{{- partial "header" (dict "P" $P "Page" .Page "Scratch" .Scratch) }}
|
||||
</div>
|
||||
<!-- Sidebar -->
|
||||
{{- if ne $P.sidebar.display "remove" }}
|
||||
@ -42,6 +46,8 @@
|
||||
{{- partial "footer" . }}
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
{{- partial "scripts" (dict "P" $P "Page" .Page "Scratch" .Scratch) }}
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,17 +1,17 @@
|
||||
{{- $vendors := .Page.Site.Data.resources.vendors }}
|
||||
{{- $pluginVen := .P.vendors.plugins }}
|
||||
{{- $pluginCDN := index $vendors $pluginVen }}
|
||||
<!-- Plugin style files -->
|
||||
{{- $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 }}
|
||||
|
19
layouts/partials/scripts.html
Normal file
19
layouts/partials/scripts.html
Normal file
@ -0,0 +1,19 @@
|
||||
<!-- Plugin scripts files -->
|
||||
{{- $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 }}
|
||||
<script type="text/javascript" src="{{ $pluginJS }}"></script>
|
||||
{{- end }}
|
Loading…
Reference in New Issue
Block a user