diff --git a/README.md b/README.md index fac3404..003bf2e 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,13 @@ name: "title" widget: "string" ``` +## Module Settings + +Module settings are set as part of the shared `data/netlifycms/config.yaml` file under the reserved `tnd_netlifycms` map key. + +Available settings are: + - cms_version (default: `^2.0.0`): Semantic versioning string to be used when calling CDN endpoint. + ## Scripts The module faciliate the addiont of extra Netlify CMS scripts for WidgetPreviews, CollectionPreviews etc... diff --git a/func/private/GetCMSVersion.html b/func/private/GetCMSVersion.html new file mode 100644 index 0000000..8329201 --- /dev/null +++ b/func/private/GetCMSVersion.html @@ -0,0 +1,27 @@ +{{/* + GetCMSVersion retrieves the version as set in the tnd_netlifycms settings. + + @author @regisphilibert + + @context Any (.) + + @access public + + @return String (default: ^2.0.0) + + @example - Go Template + {{ partial "path" context }} + {{ partialCached "path" context "variant" }} +*/}} + +{{/* Default is `^2.0.0` for now */}} +{{ $version := `^2.0.0` }} + +{{ with partialCached "tnd-netlifycms/private/GetModuleConfig" . "tnd-netlifycms/private/GetModuleConfig" }} + {{ with .cms_version }} + {{ $version = . }} + {{ end }} +{{ end }} + + +{{ return $version }} \ No newline at end of file diff --git a/func/private/GetModuleConfig.html b/func/private/GetModuleConfig.html new file mode 100644 index 0000000..c97bf0b --- /dev/null +++ b/func/private/GetModuleConfig.html @@ -0,0 +1,24 @@ +{{/* + GetModuleConfig returns the config as set in data/netlifycms/config.yaml's tnd_netlifycms map. + + @author @regisphilibert + + @context Any + + @return Map + + @access private + + @example - Go Template + {{ with partial "tnd-netlifycms/private/GetModuleConfig" . }} + {{ $config = . }} + {{ end }} +*/}} +{{ $return := dict }} +{{ with site.Data.netlifycms.config }} + {{ with .tnd_netlifycms }} + {{ $return = . }} + {{ end }} +{{ end }} + +{{ return $return }} \ No newline at end of file diff --git a/templates/single.html.html b/templates/single.html.html index c938e4c..2d28e14 100644 --- a/templates/single.html.html +++ b/templates/single.html.html @@ -9,7 +9,11 @@ - + {{- $version := partialCached "tnd-netlifycms/private/GetCMSVersion" . "tnd-netlifycms/private//GetCMSVersion" -}} + {{/* Hugo keeps escaping the `^` character potentially used to specify CMS version (`^2.0.0`) in spite of + safeHTML, safeHTMLAttr and the like. Passing the whole tag through `printf` fixes it... */}} + {{- $cdn := printf `` $version -}} + {{ $cdn | safeHTML }} {{ partial "tnd-netlifycms/scripts.html" . }} \ No newline at end of file