Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add netlify-identity submodule #147

Merged
merged 12 commits into from
Feb 9, 2024
3 changes: 3 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
min = "0.111.3"
# extended = true

[[module.imports]]
path = "github.com/hugomods/hugopress"

[outputFormats]
[outputFormats.DecapCMSConfig]
baseName = "decap-cms-config"
Expand Down
2 changes: 2 additions & 0 deletions layouts/_default/decap-cms.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
{{- warnf "[decap-cms] please append %q into the %q output in configuration." "DecapCMSConfig" "home" }}
{{- end }}
{{ partialCached "decap-cms/hooks/head-end" . }}
{{ partial "hugopress/functions/render-hooks" (dict "Name" "decap-cms-head-end" "Page" .) }}
</head>
<body>
{{ partialCached "decap-cms/script" . }}
{{ partialCached "decap-cms/init" . }}
{{ partialCached "decap-cms/hooks/body-end" . }}
{{ partial "hugopress/functions/render-hooks" (dict "Name" "decap-cms-body-end" "Page" .) }}
</body>
</html>
19 changes: 19 additions & 0 deletions modules/netlify-identity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Netlify Identity Support for Decap CMS

## Configurations

```toml
[params.decap_cms._netlify_identity]
js_url = "https://identity.netlify.com/v1/netlify-identity-widget.js"
```

## Inject Partials

If your theme doesn't implement HugoPress, you will need to inject the following partials into your homepage.

```html
{{- if .IsHome }}
{{ partialCached "hugopress/modules/decap-cms-netlify-identity/script" . }}
{{ partialCached "hugopress/modules/decap-cms-netlify-identity/callback-script" . }}
{{- end }}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import params from '@params'

if (window.netlifyIdentity) {
window.netlifyIdentity.on('init', user => {
if (!user) {
window.netlifyIdentity.on('login', () => {
document.location.href = params.admin_path
})
}
})
}
3 changes: 3 additions & 0 deletions modules/netlify-identity/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/hugomods/decap-cms/modules/netlify-identity

go 1.18
12 changes: 12 additions & 0 deletions modules/netlify-identity/hugo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[module.imports]]
path = "github.com/hugomods/decap-cms"

[params.hugopress.modules.decap-cms-netlify-identity.hooks.head-end]

[params.hugopress.modules.decap-cms-netlify-identity.hooks.body-end]

[params.hugopress.modules.decap-cms-netlify-identity.hooks.decap-cms-head-end]
cacheable = true

[params.decap_cms._netlify_identity]
js_url = "https://identity.netlify.com/v1/netlify-identity-widget.js"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- $adminPath := "" }}
{{- range where site.Pages "Layout" "decap-cms" }}
{{- $adminPath = .RelPermalink }}
{{- break }}
{{- end }}
{{- if ne $adminPath "" }}
{{- $targetPath := "js/netlify-identity-callback.js" }}
{{- $opts := dict
"targetPath" $targetPath
"minify" hugo.IsProduction
"params" (dict
"admin_path" $adminPath)
}}
{{- $js := resources.Get "decap-cms/modules/netlify-identity/callback.js" | js.Build $opts }}
{{- if hugo.IsProduction }}
{{- $js = $js | fingerprint }}
{{- end }}
<script src="{{ $js.RelPermalink }}"></script>
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- if .Page.IsHome }}
{{ partialCached "hugopress/modules/decap-cms-netlify-identity/callback-script" . }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ partialCached "hugopress/modules/decap-cms-netlify-identity/script" . }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- if .Page.IsHome }}
{{ partialCached "hugopress/modules/decap-cms-netlify-identity/script" . }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script src="{{ site.Params.decap_cms._netlify_identity.js_url }}"></script>