hugomods / decap-cms

[Experimental] Hugo Decap CMS Module
https://hugomods.com
MIT License
6 stars 1 forks source link

Either document or support the use of netlify identity? #89

Closed pleasantone closed 7 months ago

pleasantone commented 8 months ago

This is just documenting my own stupidity and I was wondering if it would make sense to either add fragments of this into the module to at least reduce the configuration confusion. I'm not putting it into a pull request since this is configuration dependent.

In order to get decap+netlify identity working with themes cards, I had to do the following:

Perhaps we could create a submodule hugomods/decap-cms-netlify?

config/_default/params.yaml

hugopress:
  modules:
    decap-cms:
      hooks:
        head-end:
          cacheable: false
        body-end:
          cacheable: false

Can't be cacheable because of the if $.Page.IsHome but I don't fully understand the module plugin system so there may be a better place to put these than where I did.

This snippet must be in the /admin/index.html page:

layouts/partials/decap-cms/hooks/head-end.html

<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>

these two must be on the root /index.html page:

layouts/partials/hugopress/modules/decap-cms/hooks/body-end.html

{{- if $.Page.IsHome }}
<script>
    if (window.netlifyIdentity) {
      window.netlifyIdentity.on("init", user => {
        if (!user) {
          window.netlifyIdentity.on("login", () => {
            document.location.href = "/admin/";
          });
        }
      });
    }
  </script>
  {{- end }}

and

layouts/partials/hugopress/modules/decap-cms/hooks/head-end.html

{{- if $.Page.IsHome }}
<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
{{- end }}
razonyang commented 8 months ago

I don't have experience with Netlify Identity, so I can't give you working configurations/instructions.

If you want to insert some HTML into the Decap CMS (typically /admin) page, you can create the following files and put the custom code into those files.

  1. layouts/partials/decap-cms/hooks/head-end.html.
  2. layouts/partials/decap-cms/hooks/body-end.html.

Those hooks will only affact the Decap CMS page, and you don't need to configure the hugopress.

Currently, this docs for module are not complete, it introduces a lot of features since the first version, will find some time to update the docs.

razonyang commented 8 months ago

Perhaps we could create a submodule hugomods/decap-cms-netlify?

Sounds good to have, will do if I find some time, #90.

pleasantone commented 8 months ago

I don't have experience with Netlify Identity, so I can't give you working configurations/instructions.

If you want to insert some HTML into the Decap CMS (typically /admin) page, you can create the following files and put the custom code into those files.

  1. layouts/partials/decap-cms/hooks/head-end.html.
  2. layouts/partials/decap-cms/hooks/body-end.html.

Those hooks will only affact the Decap CMS page, and you don't need to configure the hugopress.

Yep, but unfortunately netlify identity also wants some code on the home page, which is why I did it there too rather than put it into hb-custom. I'm not sure if there home-page-specific hooks, didn't notice them.

razonyang commented 8 months ago

Yep, but unfortunately netlify identity also wants some code on the home page, which is why I did it there too rather than put it into hb-custom.

Your code snippet above is right, but I'd recommend using hb-custom (or any special name), because the decap-cms maybe conflicts in the future.

I'm not sure if there home-page-specific hooks, didn't notice them.

There isn't. Hooks for all kind of pages, you'll need to add render conditions as you did above.

pleasantone commented 7 months ago

147

pleasantone commented 7 months ago

Duplicate of #90