Skip to content

Commit

Permalink
feat: add initial support for feed.json
Browse files Browse the repository at this point in the history
Close #879
  • Loading branch information
HEIGE-PCloud committed Mar 29, 2024
1 parent 68e50e4 commit 4a810e0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
3 changes: 3 additions & 0 deletions exampleSite/config/_default/mediaTypes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

["text/plain"]
suffixes = ["md"]

["application/feed+json"]
suffixes = ["feed"]
5 changes: 5 additions & 0 deletions exampleSite/config/_default/outputFormats.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
mediaType = "text/plain"
isPlainText = true
isHTML = false

[JsonFeed]
mediaType = "application/feed+json"
isPlainText = true
notAlternative = true
2 changes: 1 addition & 1 deletion exampleSite/config/_default/outputs.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Options to make hugo output files
# 用于 Hugo 输出文档的设置

home = ["HTML", "RSS", "JSON"]
home = ["HTML", "RSS", "JSON", "JsonFeed"]
page = ["HTML", "MarkDown"]
section = ["HTML", "RSS"]
taxonomy = ["HTML", "RSS"]
45 changes: 45 additions & 0 deletions layouts/index.feed
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{ $list := .Pages -}}
{{ $length := (len $list) -}}
{
"version" : "https://jsonfeed.org/version/1.1",
"title" : "{{- .Site.Title -}}",
"description": "{{- .Site.Params.description | default .Site.Title -}}",
"home_page_url" : "{{ .Site.BaseURL }}",
{{ with .OutputFormats.Get "JsonFeed" -}}
"feed_url" : "{{ .Permalink }}",
{{ end -}}
"icon" : "{{ `/apple-touch-icon.png` | absURL }}",
"favicon" : "{{ `/favicon.ico` | absURL }}",
{{ with .Site.Author.name -}}
"author" : {
"name" : "{{ . }}"{{ with $.Site.Author.link }},
"url": "{{ . }}"{{ end }}{{ with $.Site.Author.avatar }},
"avatar": "{{ . | absURL }}"{{ end }}
},
{{ end -}}
"items" : [
{{ range $index, $element := where .Site.RegularPages "Type" "in" site.Params.mainSections -}}
{
"title" : {{ .Title | jsonify }},
"date_published" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}",
{{ if .Lastmod -}}
"date_modified" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}",
{{ else -}}
"date_modified" : "{{ .LastMod.Format "2006-01-02T15:04:05Z07:00" }}",
{{ end -}}
"id" : "{{ .Permalink }}",
"url" : "{{ .Permalink }}",
{{ with .Summary -}}
"summary": {{ . | plainify | jsonify }},
{{ end -}}
{{ with .Params.author -}}
"author" : {
"name" : "{{ . }}"
},
{{ end -}}
"content_html" : {{ .Content | jsonify }},
"language": {{ .Language.Lang | default $.Lang | jsonify }}
}{{ if ne (add $index 1) $length }},{{ end }}
{{ end -}}
]
}

0 comments on commit 4a810e0

Please sign in to comment.