👷 Add CDN vendor automatic switch by config setting.
This commit is contained in:
@@ -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 }}
|
||||
Reference in New Issue
Block a user