Closed jmb closed 1 year ago
I don't know how and where you modified your code. So I'm just guessing here ...
I guess I would create a new layout/partials/analytics.html
to surcharge the original in your theme with 1 line calling the plausible partial inside this analytics partial (while also removing GA
and Fathom
calls).
Plausible already take care of site.IsServer
:
<!-- Just one line calling plausible head partial -->
{{ partial “plausible_head.html” . }}
Yes you encounter a context problem. You need to pass the right context because the error origin is line 76 when testing if it is a 404 page. So the simplest for you is my previous advice I guess.
{{- if eq .Page.Kind "404" }}
<script>plausible("404",{ props: { path: document.location.pathname } });</script>
{{- end }}
I have created the one-line analytics.html as suggested.
The congo theme has a chain of partials/templates I think. From the errors:
baseof.html
calls <partial "head.html" . >
which calls <partialCached "analytics.html" .Site >
where I have entered the call to <partial "plausible_head.html" . >
So am I right in thinking that plausible_head only gets .Site
but needs more context? If I change the call to the analytics.html
partial to .
, then maybe that will fix it.
If I change the call to the
analytics.html
partial to.
, then maybe that will fix it.
This seems to have fixed the problem - I copied the head.html
from the congo source to my layouts/partials and changed the .Site
to .
. I will go back to the congo repo and see if it can be changed there.
Ah yes if the context passed to analytics.html
is .Site
it will surely fails because of the contexte not being .
for plausible partial.
I think you've done the right thing. Closing this one then.
If anyone else is following, here is the issue over at the congo repo: https://github.com/jpanther/congo/issues/480
This has now been fixed in Congo. ☺️
I’m trying to use the module approach with the
congo
theme, but I don’t suppose this is limited solely to the this theme.I’ve added
{{ partial “plausible_head.html” . }}
to thelayouts/partials/analytics.html
file which the congo theme uses to store all the analytics stuff that will be put into the header.However I suspect the variable scope/context is causing an issue (error:
<.Page.Kind>: can't evaluate field Page in type *hugolib.SiteInfo
), so I’m wondering if there is a more generic way to make this work using$.
to get the global context?Full error message below.