Hugo生成json文件 Mon, Nov 4, 2024
在主题文件夹layouts\_default中添加index.json文件
{{- $.Scratch.Add "index" slice -}}
{{- range .Site.RegularPages -}}
{{- $.Scratch.Add "index" (dict "title" .Title "permalink" .Permalink "content" .Plain) -}}
{{- end -}}
{{- $.Scratch.Get "index" | jsonify -}}
config.toml中如下设置。
[outputs]
home = ["HTML", "JSON"]
hugo,会在public文件夹中生成index.json文件。