From 985555cd8bbc02ea454012b94765577152295a76 Mon Sep 17 00:00:00 2001
From: Patrick Kollitsch <davidsneighbourdev+gh@gmail.com>
Date: Sat, 16 May 2026 23:36:35 +0000
Subject: [PATCH] wip: initial hook setup
---
layouts/_partials/hook.html | 70 +++++++++++++++++++++++
config/_default/params.toml | 3 +
layouts/_partials/func/hooks/collector.html | 6 ++
layouts/_partials/func/hooks/collector-dump.html | 8 ++
layouts/_partials/func/hooks/debug-cli.html | 60 ++++++++++++++++++++
layouts/_partials/hooks/article/section-link.html | 3 +
layouts/baseof.html | 2
layouts/single.html | 9 --
.vscode/custom-dictionary.txt | 4 +
9 files changed, 156 insertions(+), 9 deletions(-)
diff --git a/.vscode/custom-dictionary.txt b/.vscode/custom-dictionary.txt
index d049214..989bcbc 100644
--- a/.vscode/custom-dictionary.txt
+++ b/.vscode/custom-dictionary.txt
@@ -1,6 +1,8 @@
Ananke
demosite
Disqus
+Errorf
Kitchensink
licenselink
-Philibert
\ No newline at end of file
+Philibert
+Warnf
diff --git a/config/_default/params.toml b/config/_default/params.toml
index 5b68e47..01de554 100644
--- a/config/_default/params.toml
+++ b/config/_default/params.toml
@@ -255,3 +255,6 @@
color = "#cd201f"
profile = "https://www.youtube.com/@%s"
icon = "youtube" # font awesome brand icon name
+
+[ananke.hooks]
+verbosity = "debug" # debug, warning, error
\ No newline at end of file
diff --git a/layouts/_partials/func/hooks/collector-dump.html b/layouts/_partials/func/hooks/collector-dump.html
new file mode 100644
index 0000000..89b2099
--- /dev/null
+++ b/layouts/_partials/func/hooks/collector-dump.html
@@ -0,0 +1,8 @@
+{{- $scratch := page.Scratch.Get "dnb.hooks" -}}
+{{- partials.Include "func/hooks/debug-cli.html" (collections.Dictionary "message" "Hooks Collector") -}}
+{{- partials.Include "func/hooks/debug-cli.html" (collections.Dictionary "message" (printf "%#v" $scratch)) -}}
+
+{{/*
+{{ partials.Include "func/hooks/collector-dump.html" . }}
+@todo must use stored instead of stashed and must be post processed.
+*/}}
\ No newline at end of file
diff --git a/layouts/_partials/func/hooks/collector.html b/layouts/_partials/func/hooks/collector.html
new file mode 100644
index 0000000..98d91a2
--- /dev/null
+++ b/layouts/_partials/func/hooks/collector.html
@@ -0,0 +1,6 @@
+{{ $scratch := page.Scratch.Get "ananke.hooks" }}
+{{ if eq $scratch "" }}
+ {{ $scratch = slice }}
+{{ end }}
+{{- page.Scratch.Add "ananke.hooks" (slice .hook) -}}
+
diff --git a/layouts/_partials/func/hooks/debug-cli.html b/layouts/_partials/func/hooks/debug-cli.html
new file mode 100644
index 0000000..37d6280
--- /dev/null
+++ b/layouts/_partials/func/hooks/debug-cli.html
@@ -0,0 +1,60 @@
+{{- $config := site.Params.ananke.hooks -}}
+{{/*
+
+$config.namespace
+$config.ignoreErrors
+$config.verbosity
+
+*/}}
+{{/*
+@todo add and document hook verbosity suppression setting via config
+
+[ananke.hooks]
+verbosity = "warning" # debug, warning, error
+
+@todo add and document hook ignoreErrors setting via config
+*/}}
+
+{{/*
+| Primary | `#AA99FF` | `170, 153, 255` |
+| Ananke | `#FF80BF` | `255, 128, 191` |
+| Comment | `#708CA9` | `112, 140, 169` |
+| Error | `#CC7766` | `204, 119, 102` |
+| Warning | `#CCCC66` | `204, 204, 102` |
+| Info | `#6ECC66` | `110, 204, 102` |
+*/}}
+
+{{- $colourPrimary := "\033[38;2;170;153;255m" -}}
+{{- $colourAnanke := "\033[38;2;255;128;191m" -}}
+{{- $colourComment := "\033[38;2;112;140;169m" -}}
+{{- $colourError := "\033[38;2;204;119;102m" -}}
+{{- $colourWarning := "\033[38;2;204;204;102m" -}}
+{{- $colourInfo := "\033[38;2;110;204;102m" -}}
+{{- $colourReset := "\033[0m" -}}
+
+{{- if collections.In $config.ignoreErrors .slug -}}
+ {{- return -}}
+{{- end -}}
+
+{{- $namespace := $config.namespace | compare.Default "ananke" -}}
+{{- $severity := .severity | compare.Default "info" -}}
+{{- $colourLevel := $colourInfo -}}
+{{- $severityLabel := "INFO" -}}
+
+{{- if compare.Eq $severity "warning" -}}
+ {{- $colourLevel = $colourWarning -}}
+ {{- $severityLabel = "WARN" -}}
+{{- else if compare.Eq $severity "error" -}}
+ {{- $colourLevel = $colourError -}}
+ {{- $severityLabel = "!ERR" -}}
+{{- end -}}
+
+{{- if collections.IsSet . "level" -}}
+ {{- $level = (cast.ToInt .level) -}}
+{{- end -}}
+
+{{- if compare.Le $severity "error" -}}
+ {{- fmt.Errorf (fmt.Printf "%s%s%s/%s%s %s%s%s" $colourAnanke $namespace $colourComment $colourLevel $severityLabel $colourComment .message $colourReset) -}}
+{{- else -}}
+ {{- fmt.Warnf (fmt.Printf "%s%s%s/%s%s %s%s%s" $colourAnanke $namespace $colourComment $colourLevel $severityLabel $colourComment .message $colourReset) -}}
+{{- end -}}
\ No newline at end of file
diff --git a/layouts/_partials/hook.html b/layouts/_partials/hook.html
new file mode 100644
index 0000000..6ee2d35
--- /dev/null
+++ b/layouts/_partials/hook.html
@@ -0,0 +1,70 @@
+{{- $context := collections.Dictionary -}}
+{{- $config := site.Params.ananke.hooks -}}
+{{- $colourHook := "\033[38;2;170;153;255m" -}}
+{{- $colourUnused := "\033[38;2;204;119;102m" -}}
+{{- $colourReset := "\033[0m" -}}
+
+{{- /* create context from extended or simple hook */ -}}
+{{- if reflect.IsMap . -}}
+ {{- /* extended use case with map */ -}}
+ {{- $context = collections.Merge $context . }}
+ {{- $context = collections.Merge $context (collections.Dictionary "type" "full") }}
+ {{ partials.Include "func/hooks/debug-cli.html" (collections.Dictionary "message" (fmt.Printf "%s>>> HOOK: %s%s" $colourHook $context.hook $colourReset)) }}
+ {{ partials.Include "func/hooks/debug-cli.html" (collections.Dictionary "message" "hook is extended") }}
+ {{- /* extended use case */ -}}
+ {{- $context = collections.Merge $context . }}
+ {{- $context = collections.Merge $context (collections.Dictionary "type" "full") }}
+{{- else -}}
+ {{ partials.Include "func/hooks/debug-cli.html" (collections.Dictionary "message" (fmt.Printf "%s>>> HOOK: %s%s" $colourHook $context $colourReset)) }}
+ {{ partials.Include "func/hooks/debug-cli.html" (collections.Dictionary "message" "hook is simple") }}
+ {{- /* simple use case */ -}}
+ {{- $context = collections.Merge
+ $context
+ (collections.Dictionary "hook" . "context" collections.Dictionary) -}}
+ {{- $context = collections.Merge $context (collections.Dictionary "type" "simple") }}
+{{- end -}}
+
+{{/**
+
+$context.hook = hook name
+$context.cache = whether to cache the hook (optional, default: false, if used this is used as cache indicator)
+$context.context = context of the hook (e.g. page, section, etc.)
+$context.type = type of the hook (e.g. full, simple)
+
+context is empty for simple hooks
+
+**/}}
+
+{{- /* add hook to collector */ -}}
+{{- partials.Include "func/hooks/collector.html" (collections.Dictionary
+ "hook" $context.hook
+ "context" $context
+) -}}
+
+{{- $loaded := false -}}
+{{- $partialName := fmt.Printf "hooks/%s.html" $context.hook -}}
+{{- $partialHook := fmt.Printf "_partials/%s" $partialName -}}
+{{ partials.Include "func/hooks/debug-cli.html" (collections.Dictionary "message" (fmt.Printf "partial Name: %s" $partialName)) }}
+{{- if templates.Exists $partialHook -}}
+ {{- if compare.Eq true (.cached | compare.Default false) -}}
+ {{- partials.IncludeCached $partialName $context.context -}}
+ {{ partials.Include "func/hooks/debug-cli.html" (collections.Dictionary "message" "included") }}
+ {{- $loaded = true -}}
+ {{- else -}}
+ {{- partials.Include $partialName $context.context -}}
+ {{ partials.Include "func/hooks/debug-cli.html" (collections.Dictionary "message" "included uncached") }}
+ {{- $loaded = true -}}
+ {{- end -}}
+{{- end -}}
+
+{{- if compare.Eq $loaded false -}}
+ {{- if not (collections.In $config.disable_messages "unused_hooks") -}}
+ {{- partials.Include "func/hooks/debug-cli.html" (collections.Dictionary
+ "message" (fmt.Printf "%s<<< HOOK `%s` %sunused%s" $colourHook $context.hook $colourUnused $colourReset)
+ "context" .
+ "severity" "info"
+ ) -}}
+ {{- end -}}
+{{ else }}
+ {{ partials.Include "func/hooks/debug-cli.html" (collections.Dictionary "message" (fmt.Printf "%s<<< HOOK: %s done%s" $colourHook $context.hook $colourReset)) }}
+{{- end -}}
diff --git a/layouts/_partials/hooks/article/section-link.html b/layouts/_partials/hooks/article/section-link.html
new file mode 100644
index 0000000..827bf0d
--- /dev/null
+++ b/layouts/_partials/hooks/article/section-link.html
@@ -0,0 +1,3 @@
+<aside class="instapaper_ignoref b helvetica tracked ttu">
+ {{ .CurrentSection.Title }}
+</aside>
\ No newline at end of file
diff --git a/layouts/baseof.html b/layouts/baseof.html
index 95d89e6..00b68a2 100644
--- a/layouts/baseof.html
+++ b/layouts/baseof.html
@@ -78,4 +78,4 @@
</main>
{{ block "footer" . }}{{ partials.IncludeCached "site-footer.html" . }}{{ end }}
</body>
-</html>
+</html>
\ No newline at end of file
diff --git a/layouts/single.html b/layouts/single.html
index 9afbcf9..0fe7e6f 100644
--- a/layouts/single.html
+++ b/layouts/single.html
@@ -17,13 +17,8 @@
<article class="{{ $post_class }} flex-l {{ if $needs_aside }}mw8{{ else }}mw7{{ end }} center ph3 flex-wrap justify-between">
<header class="mt4 w-100">
- <aside class="instapaper_ignoref b helvetica tracked ttu">
- {{/*
- CurrentSection allows us to use the section title instead of inferring from the folder.
- https://gohugo.io/variables/page/#section-variables-and-methods
- */}}
- {{ .CurrentSection.Title }}
- </aside>
+ {{- partials.Include "hook.html" ( dict "hook" "article/section-link" "context" . ) -}}
+ {{- partials.Include "hook.html" ( dict "hook" "article/section-link222" "context" . ) -}}
{{- partials.IncludeCached "social/share.html" . . -}}
<h1 class="f1 athelas mt3 mb1">
{{- .Title -}}
--
Gitblit v1.10.0