]> danix's work - danix.xyz-2.git/commitdiff
feat: add search index JSON generation template
authorDanilo M. <redacted>
Mon, 20 Apr 2026 11:22:38 +0000 (13:22 +0200)
committerDanilo M. <redacted>
Mon, 20 Apr 2026 11:22:38 +0000 (13:22 +0200)
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 <redacted>
hugo.toml
themes/danix-xyz-hacker/layouts/index.json [new file with mode: 0644]

index 0b7963b1f8bddae1f2d33d0e3067becfe7df3e19..0a7a233fd9a23f4f029876e8d909d17e9023d14f 100644 (file)
--- 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 (file)
index 0000000..e17e31e
--- /dev/null
@@ -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 }}
+]