4 Commits
Author SHA1 Message Date
danielandClaude Sonnet 5 3f511f5e6f Log a clear console error when the cookie banner is missing
Silently returning made a missing banner.html integration
indistinguishable from a working page, which cost real debugging
time. Fail loud instead, pointing at the README.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-08 19:26:04 +02:00
daniel fe2cb13aff Add missing dot. 2026-06-16 21:02:24 +02:00
daniel 7187f7bb2a Fix element ID. 2026-06-16 20:59:17 +02:00
daniel ac0e1ed8c6 Use dash rather than underscore for class attribute. 2026-06-16 20:35:52 +02:00
5 changed files with 14 additions and 6 deletions
@@ -1,7 +1,14 @@
(function () { (function () {
var KEY = 'cookie_consent'; var KEY = 'cookie_consent';
var banner = document.getElementById('cookie-banner'); var banner = document.getElementById('cookie-banner');
if (!banner) return; if (!banner) {
console.error(
'[hugo_cookie_consent] #cookie-banner not found in the DOM. ' +
'Did you include the hugo_cookie_consent/banner.html partial in your site\'s layout? ' +
'See the module README ("Installation in your Hugo site").'
);
return;
}
updateStatus(); updateStatus();
var consent = localStorage.getItem(KEY); var consent = localStorage.getItem(KEY);
@@ -1,6 +1,6 @@
(function () { (function () {
function trackVisit() { function trackVisit() {
var banner = document.getElementById('cookie_banner'); var banner = document.getElementById('cookie-banner');
if (!banner) return; if (!banner) return;
var matomoUrl = banner.dataset.matomoUrl; var matomoUrl = banner.dataset.matomoUrl;
var siteId = banner.dataset.matomoSiteId; var siteId = banner.dataset.matomoSiteId;
@@ -23,4 +23,4 @@
if (localStorage.getItem('cookie_consent') === 'accepted') { if (localStorage.getItem('cookie_consent') === 'accepted') {
trackVisit(); trackVisit();
} }
})(); })();
@@ -1,7 +1,7 @@
<div id="cookie-banner" style="display:none" role="dialog" <div id="cookie-banner" style="display:none" role="dialog"
aria-label="Cookie consent" aria-live="polite" aria-label="Cookie consent" aria-live="polite"
data-matomo-url="{{ .Site.Params.hugo_cookie_consent.matomo_host }}" data-matomo-url="{{ .Site.Params.hugo_cookie_consent.matomo_host }}"
data-matomo-site-id="{{ .Site.Params.hugo_cookie_consent_matomo_site_id }}" > data-matomo-site-id="{{ .Site.Params.hugo_cookie_consent.matomo_site_id }}" >
<p> <p>
{{ i18n "site_wants_cookie" }} {{ i18n "site_wants_cookie" }}
<a href="{{ .Site.Params.hugo_cookie_consent.privacy_policy_url }}"> <a href="{{ .Site.Params.hugo_cookie_consent.privacy_policy_url }}">
@@ -3,4 +3,5 @@
{{- if eq .Site.Params.hugo_cookie_consent.enable_tracking true -}} {{- if eq .Site.Params.hugo_cookie_consent.enable_tracking true -}}
{{- $js := resources.Get "js/hugo_cookie_consent/tracker_code.js" | minify -}} {{- $js := resources.Get "js/hugo_cookie_consent/tracker_code.js" | minify -}}
<script src="{{ $js.RelPermalink }}" defer></script> <script src="{{ $js.RelPermalink }}" defer></script>
{{- end -}} {{- end -}}
@@ -1,6 +1,6 @@
<p> <p>
{{ i18n "cookie_status" }}: {{ i18n "cookie_status" }}:
<strong id="cookie_status" <strong id="cookie-status"
data-accepted="{{ i18n "cookie_accepted" }}" data-accepted="{{ i18n "cookie_accepted" }}"
data-declined="{{ i18n "cookie_declined" }}" data-declined="{{ i18n "cookie_declined" }}"
data-none="{{ i18n "cookie_none" }}"> data-none="{{ i18n "cookie_none" }}">