From 41d6a4f7933f3c1e1c6da48f85490c01e1e7fb6a Mon Sep 17 00:00:00 2001
From: Patrick Kollitsch <davidsneighbourdev+gh@gmail.com>
Date: Sun, 17 May 2026 00:43:47 +0000
Subject: [PATCH] wip: add filter partial
---
layouts/_partials/hook.html | 75 +-----------------
config/_default/params.toml | 2
layouts/_partials/filter.html | 112 ++++++++++++++++++++++++++++
layouts/_partials/hooks/article/test.html | 1
layouts/_partials/func/debug-cli.html | 5 +
layouts/_partials/func/hooks/collector.html | 4
layouts/_partials/func/hooks/collector-dump.html | 13 +--
layouts/baseof.html | 5 +
layouts/single.html | 2
9 files changed, 135 insertions(+), 84 deletions(-)
diff --git a/config/_default/params.toml b/config/_default/params.toml
index 01de554..11e354b 100644
--- a/config/_default/params.toml
+++ b/config/_default/params.toml
@@ -257,4 +257,4 @@
icon = "youtube" # font awesome brand icon name
[ananke.hooks]
-verbosity = "debug" # debug, warning, error
\ No newline at end of file
+verbosity = "debug" # debug, info, warning, error
\ No newline at end of file
diff --git a/layouts/_partials/filter.html b/layouts/_partials/filter.html
new file mode 100644
index 0000000..b2df3af
--- /dev/null
+++ b/layouts/_partials/filter.html
@@ -0,0 +1,112 @@
+{{- $input := . -}}
+{{- $context := collections.Dictionary -}}
+{{- $config := site.Params.ananke.hooks | compare.Default (collections.Dictionary) -}}
+{{- $disableMessages := $config.disable_messages | compare.Default (collections.Slice) -}}
+
+{{- $colourHook := "\033[38;2;170;153;255m" -}}
+{{- $colourUnused := "\033[38;2;204;119;102m" -}}
+{{- $colourReset := "\033[0m" -}}
+{{- $hookSlug := "FILTER" -}}
+
+{{- if reflect.IsMap . -}}
+ {{- with collections.Index . "__ananke_hook_slug" -}}
+ {{- $hookSlug = . -}}
+ {{- end -}}
+
+ {{- with collections.Index . "__ananke_hook_input" -}}
+ {{- $input = . -}}
+ {{- end -}}
+{{- end -}}
+
+{{- if reflect.IsMap $input -}}
+ {{- $context = collections.Merge $context $input -}}
+ {{- $context = collections.Merge $context (collections.Dictionary "type" "full") -}}
+
+ {{- partials.Include "func/debug-cli.html" (collections.Dictionary
+ "message" (fmt.Printf "%s>>> %s: %s%s" $colourHook $hookSlug $context.hook $colourReset)
+ ) -}}
+
+ {{- partials.Include "func/debug-cli.html" (collections.Dictionary
+ "message" "hook is extended"
+ "severity" "debug"
+ ) -}}
+{{- else -}}
+ {{- $context = collections.Merge $context (collections.Dictionary
+ "hook" $input
+ "context" collections.Dictionary
+ "type" "simple"
+ ) -}}
+
+ {{- partials.Include "func/debug-cli.html" (collections.Dictionary
+ "message" (fmt.Printf "%s>>> %s: %s%s" $colourHook $hookSlug $context.hook $colourReset)
+ ) -}}
+
+ {{- partials.Include "func/debug-cli.html" (collections.Dictionary
+ "message" "hook is simple"
+ "severity" "debug"
+ ) -}}
+{{- end -}}
+
+{{- partials.Include "func/hooks/collector.html" (collections.Dictionary
+ "hook" $context.hook
+ "context" $context
+) -}}
+
+{{- $loaded := false -}}
+{{- $output := "" -}}
+
+{{- $partialName := fmt.Printf "hooks/%s.html" $context.hook -}}
+{{- $partialHook := fmt.Printf "_partials/%s" $partialName -}}
+
+{{- partials.Include "func/debug-cli.html" (collections.Dictionary
+ "message" (fmt.Printf "partial Name: %s" $partialName)
+ "severity" "debug"
+) -}}
+
+{{- $cache := false -}}
+
+{{- with $context.cache -}}
+ {{- $cache = . -}}
+{{- else -}}
+ {{- with $context.cached -}}
+ {{- $cache = . -}}
+ {{- end -}}
+{{- end -}}
+
+{{- if templates.Exists $partialHook -}}
+ {{- if compare.Eq true $cache -}}
+ {{- $output = partials.IncludeCached $partialName $context.context $context.hook -}}
+
+ {{- partials.Include "func/debug-cli.html" (collections.Dictionary
+ "message" "included cached"
+ "severity" "debug"
+ ) -}}
+
+ {{- $loaded = true -}}
+ {{- else -}}
+ {{- $output = partials.Include $partialName $context.context -}}
+
+ {{- partials.Include "func/debug-cli.html" (collections.Dictionary
+ "message" "included uncached"
+ "severity" "debug"
+ ) -}}
+
+ {{- $loaded = true -}}
+ {{- end -}}
+{{- end -}}
+
+{{- if compare.Eq $loaded false -}}
+ {{- if not (collections.In $disableMessages "unused_hooks") -}}
+ {{- partials.Include "func/debug-cli.html" (collections.Dictionary
+ "message" (fmt.Printf "%s<<< %s: `%s` %sunused%s" $colourHook $hookSlug $context.hook $colourUnused $colourReset)
+ "context" $input
+ "severity" "info"
+ ) -}}
+ {{- end -}}
+{{- else -}}
+ {{- partials.Include "func/debug-cli.html" (collections.Dictionary
+ "message" (fmt.Printf "%s<<< %s: %s done%s" $colourHook $hookSlug $context.hook $colourReset)
+ ) -}}
+{{- end -}}
+
+{{- return $output -}}
\ No newline at end of file
diff --git a/layouts/_partials/func/hooks/debug-cli.html b/layouts/_partials/func/debug-cli.html
similarity index 91%
rename from layouts/_partials/func/hooks/debug-cli.html
rename to layouts/_partials/func/debug-cli.html
index 37d6280..e80e558 100644
--- a/layouts/_partials/func/hooks/debug-cli.html
+++ b/layouts/_partials/func/debug-cli.html
@@ -47,13 +47,16 @@
{{- else if compare.Eq $severity "error" -}}
{{- $colourLevel = $colourError -}}
{{- $severityLabel = "!ERR" -}}
+{{- else if compare.Eq $severity "debug" -}}
+ {{- $colourLevel = $colourComment -}}
+ {{- $severityLabel = "DEBG" -}}
{{- end -}}
{{- if collections.IsSet . "level" -}}
{{- $level = (cast.ToInt .level) -}}
{{- end -}}
-{{- if compare.Le $severity "error" -}}
+{{- if compare.Eq $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) -}}
diff --git a/layouts/_partials/func/hooks/collector-dump.html b/layouts/_partials/func/hooks/collector-dump.html
index 89b2099..89ba998 100644
--- a/layouts/_partials/func/hooks/collector-dump.html
+++ b/layouts/_partials/func/hooks/collector-dump.html
@@ -1,8 +1,5 @@
-{{- $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
+{{- $scratch := page.Store.Get "ananke.hooks" -}}
+{{- partials.Include "func/debug-cli.html" (collections.Dictionary "message" "Hooks Collector" "severity" "debug") -}}
+{{- range $index, $item := $scratch -}}
+ {{- partials.Include "func/debug-cli.html" (collections.Dictionary "message" (printf "%d: %#v" $index $item) "severity" "debug") -}}
+{{- end -}}
diff --git a/layouts/_partials/func/hooks/collector.html b/layouts/_partials/func/hooks/collector.html
index 98d91a2..b9fcfee 100644
--- a/layouts/_partials/func/hooks/collector.html
+++ b/layouts/_partials/func/hooks/collector.html
@@ -1,6 +1,6 @@
-{{ $scratch := page.Scratch.Get "ananke.hooks" }}
+{{ $scratch := page.Store.Get "ananke.hooks" }}
{{ if eq $scratch "" }}
{{ $scratch = slice }}
{{ end }}
-{{- page.Scratch.Add "ananke.hooks" (slice .hook) -}}
+{{- page.Store.Add "ananke.hooks" (slice .hook) -}}
diff --git a/layouts/_partials/hook.html b/layouts/_partials/hook.html
index 6ee2d35..770b996 100644
--- a/layouts/_partials/hook.html
+++ b/layouts/_partials/hook.html
@@ -1,70 +1,5 @@
-{{- $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 -}}
+{{/* "A hook is just a filter that outputs immediately!" he said and moved on with his life. */}}
+{{- partials.Include "filter.html" (collections.Dictionary
+ "__ananke_hook_input" .
+ "__ananke_hook_slug" "HOOK"
+) -}}
\ No newline at end of file
diff --git a/layouts/_partials/hooks/article/test.html b/layouts/_partials/hooks/article/test.html
new file mode 100644
index 0000000..1805de8
--- /dev/null
+++ b/layouts/_partials/hooks/article/test.html
@@ -0,0 +1 @@
+{{ return printf . "World" }}
\ No newline at end of file
diff --git a/layouts/baseof.html b/layouts/baseof.html
index 00b68a2..9932b8e 100644
--- a/layouts/baseof.html
+++ b/layouts/baseof.html
@@ -78,4 +78,7 @@
</main>
{{ block "footer" . }}{{ partials.IncludeCached "site-footer.html" . }}{{ end }}
</body>
-</html>
\ No newline at end of file
+</html>
+{{- with (templates.Defer (dict "key" "hooks-collector")) -}}
+ {{- partials.Include "func/hooks/collector-dump.html" . }}
+{{ end -}}
\ No newline at end of file
diff --git a/layouts/single.html b/layouts/single.html
index 0fe7e6f..c9c81ae 100644
--- a/layouts/single.html
+++ b/layouts/single.html
@@ -18,7 +18,7 @@
<article class="{{ $post_class }} flex-l {{ if $needs_aside }}mw8{{ else }}mw7{{ end }} center ph3 flex-wrap justify-between">
<header class="mt4 w-100">
{{- partials.Include "hook.html" ( dict "hook" "article/section-link" "context" . ) -}}
- {{- partials.Include "hook.html" ( dict "hook" "article/section-link222" "context" . ) -}}
+ {{- partials.Include "filter.html" ( dict "hook" "article/test" "context" "Hello %s" ) -}}
{{- partials.IncludeCached "social/share.html" . . -}}
<h1 class="f1 athelas mt3 mb1">
{{- .Title -}}
--
Gitblit v1.10.0