Skip to content

Commit

Permalink
Merge pull request #2 from theNewDynamic/1-cms-version-config
Browse files Browse the repository at this point in the history
NetlifyCMS version settings
  • Loading branch information
regisphilibert committed Jun 1, 2020
2 parents 42f6c76 + e300ab8 commit 2fc0737
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
27 changes: 27 additions & 0 deletions func/private/GetCMSVersion.html
Original file line number Diff line number Diff line change
@@ -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 }}
24 changes: 24 additions & 0 deletions func/private/GetModuleConfig.html
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 5 additions & 1 deletion templates/single.html.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
</head>
<body>
<!-- Include the script that builds the page and powers Netlify CMS -->
<script src="https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js"></script>
{{- $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 `<script src="https://unpkg.com/netlify-cms@%s/dist/netlify-cms.js"></script>` $version -}}
{{ $cdn | safeHTML }}
{{ partial "tnd-netlifycms/scripts.html" . }}
</body>
</html>

0 comments on commit 2fc0737

Please sign in to comment.