summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-04-20 13:22:38 +0200
committerDanilo M. <danix@danix.xyz>2026-04-20 13:22:38 +0200
commitb6d4089bc8db863d361e21759469c2fcbfcd854c (patch)
tree0d0bc307d3f43f146bca6d2923b64a5e8ae736e3
parentc7d64a6fa58da9337ce6acc16ab8427798235341 (diff)
downloaddanixxyz-b6d4089bc8db863d361e21759469c2fcbfcd854c.tar.gz
danixxyz-b6d4089bc8db863d361e21759469c2fcbfcd854c.zip
feat: add search index JSON generation template
Generates /search-index.json at build time containing title, url, date, and summary for all articles. Template uses Hugo's jsonify and plainify filters for safe JSON output. Includes outputFormats configuration in hugo.toml to enable JSON output format. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
-rw-r--r--hugo.toml14
-rw-r--r--themes/danix-xyz-hacker/layouts/index.json13
2 files changed, 27 insertions, 0 deletions
diff --git a/hugo.toml b/hugo.toml
index 0b7963b..0a7a233 100644
--- a/hugo.toml
+++ b/hugo.toml
@@ -4,6 +4,20 @@ title = "danix.xyz"
theme = "danix-xyz-hacker"
enableRobotsTXT = true
+# Output format definitions
+[outputFormats]
+ [outputFormats.JSON]
+ name = "JSON"
+ mediaType = "application/json"
+ baseName = "search-index"
+ isPlainText = true
+
+# Output formats
+[outputs]
+ home = ["HTML", "JSON"]
+ section = ["HTML"]
+ page = ["HTML"]
+
# Hugo Pipes
[minify]
minifyOutput = false
diff --git a/themes/danix-xyz-hacker/layouts/index.json b/themes/danix-xyz-hacker/layouts/index.json
new file mode 100644
index 0000000..e17e31e
--- /dev/null
+++ b/themes/danix-xyz-hacker/layouts/index.json
@@ -0,0 +1,13 @@
+{{- $articles := where .Site.RegularPages "Section" "articles" -}}
+{{- $articles = $articles.ByDate.Reverse -}}
+[
+ {{- range $index, $article := $articles -}}
+ {
+ "title": {{ $article.Title | jsonify }},
+ "url": {{ $article.Permalink | jsonify }},
+ "date": {{ $article.Date.Format "Jan 02, 2006" | jsonify }},
+ "summary": {{ substr ($article.Summary | plainify) 0 160 | jsonify }}
+ }
+ {{- if ne (add $index 1) (len $articles) }},{{ end }}
+ {{- end }}
+]