generated from hugomods/template-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add netlify-identity module (#147)
* feat: add the `decap-cms-head-end` and `decap-cms-body-end` hooks --------- Co-authored-by: Razon Yang <razonyang@gmail.com>
- Loading branch information
1 parent
1f7ccc5
commit 0e35b70
Showing
11 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
``` |
11 changes: 11 additions & 0 deletions
11
modules/netlify-identity/assets/decap-cms/modules/netlify-identity/callback.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
19 changes: 19 additions & 0 deletions
19
...entity/layouts/partials/hugopress/modules/decap-cms-netlify-identity/callback-script.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
3 changes: 3 additions & 0 deletions
3
...dentity/layouts/partials/hugopress/modules/decap-cms-netlify-identity/hooks/body-end.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
1 change: 1 addition & 0 deletions
1
...youts/partials/hugopress/modules/decap-cms-netlify-identity/hooks/decap-cms-head-end.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ partialCached "hugopress/modules/decap-cms-netlify-identity/script" . }} |
3 changes: 3 additions & 0 deletions
3
...dentity/layouts/partials/hugopress/modules/decap-cms-netlify-identity/hooks/head-end.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
1 change: 1 addition & 0 deletions
1
...etlify-identity/layouts/partials/hugopress/modules/decap-cms-netlify-identity/script.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script src="{{ site.Params.decap_cms._netlify_identity.js_url }}"></script> |