diff --git a/data/resources.yaml b/data/resources.yaml new file mode 100644 index 0000000..4b5fb64 --- /dev/null +++ b/data/resources.yaml @@ -0,0 +1,27 @@ +# Public CDN vender list +# +vendors: { + "cdnjs": "//cdnjs.cloudflare.com/ajax/libs/${name}/${version}/${file}", + "unpkg": "//unpkg.com/${name}@${version}/${file}" +} + +# Javascript Resources +# +js: + - name: anime + version: 3.2.1 + file: lib/anime.min.js + - name: mathjax + version: 3.2.0 + file: es5/tex-mml-chtml.js + +# CSS Resources +# +css: + - name: '@fortawesome/fontawesome-free' + version: 6.1.1 + file: css/all.min.css + alias: font-awesome + - name: animate.css + version: 3.1.1 + file: animate.min.css \ No newline at end of file diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 61afb54..f67a226 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -911,7 +911,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: jsdelivr + plugins: unpkg # Custom CDN URL # For example: # custom_cdn_url: https://cdn.jsdelivr.net/npm/${npm_name}@${version}/${minified} diff --git a/layouts/partials/head/style.html b/layouts/partials/head/style.html index d80bc48..0f7466e 100644 --- a/layouts/partials/head/style.html +++ b/layouts/partials/head/style.html @@ -1,5 +1,23 @@ - - +{{- $vendors := .Page.Site.Data.resources.vendors }} +{{- $pluginVen := .P.vendors.plugins }} +{{- $pluginCDN := index $vendors $pluginVen }} + +{{- $cssRes := .Page.Site.Data.resources.css }} +{{- range $css := $cssRes }} + {{- $npm := $css.name }} + {{- $file := $css.file }} + {{- if eq $pluginVen "cndjs" }} + {{- $npm = $.css.alias }} + {{ $file }} + {{- $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 }} + +{{- end }} + {{- $scss := resources.Get "css/main.scss" }} {{- $scss = $scss | resources.ExecuteAsTemplate "main.scss" . }} {{- $css := $scss | toCSS (dict "targetPath" "/css/main.css" "outputStyle" "expanded") }}