add template for json feeds

This commit is contained in:
Robert Kaussow 2020-08-24 09:03:56 +02:00
parent c0a15b9c5f
commit c3e9abbb34
No known key found for this signature in database
GPG Key ID: 65362AE74AF98B61
4 changed files with 73 additions and 2 deletions

View File

@ -1,2 +1,2 @@
- ENHANCEMENT - ENHANCEMENT
- switch back to Hugo internal twitter-card template - add template for Json Feeds

View File

@ -30,7 +30,18 @@ outputFormats:
name: "Atom" name: "Atom"
mediaType: "application/atom+xml" mediaType: "application/atom+xml"
# generated file: <baseName>.<mediaType."application/atom+xml".suffixes[0]> = atom.xml # generated file: <baseName>.<mediaType."application/atom+xml".suffixes[0]> = atom.xml
baseName: "atom" baseName: "feed"
isPlainText: false
rel: "alternate"
isHTML: false
noUgly: true
permalinkable: false
Json:
# https://www.jsonfeed.org/2020/08/07/json-feed-version.html
name: "Json"
mediaType: "application/json"
# generated file: <baseName>.<mediaType."application/feed+json".suffixes[0]> = feed.json
baseName: "feed"
isPlainText: false isPlainText: false
rel: "alternate" rel: "alternate"
isHTML: false isHTML: false
@ -41,6 +52,7 @@ outputs:
home: home:
- HTML - HTML
- ATOM - ATOM
- JSON
page: page:
- HTML - HTML
section: section:
@ -50,6 +62,7 @@ outputs:
term: term:
- HTML - HTML
- ATOM - ATOM
- JSON
enableRobotsTXT: true enableRobotsTXT: true

View File

@ -31,6 +31,7 @@ This post works as a documentation for the features of the theme.
- Simple sticky posts - Simple sticky posts
- Content tags - Content tags
- Multiple authors - Multiple authors
- Supports Atom and Json feeds
## Configuration ## Configuration

View File

@ -0,0 +1,57 @@
{{- $title := .Site.Title -}}
{{- with .Title -}}
{{- if (not (eq . $title)) -}}
{{- $title = printf `%s on %s` . $title -}}
{{- end -}}
{{- end -}}
{
"version": "https://jsonfeed.org/version/1.1",
"title": {{ $title | jsonify }},
{{- with .Site.Params.subtitle }}
"description": {{ . | jsonify }},
{{- end }}
"home_page_url" : "{{ .Site.BaseURL }}",
{{- with .OutputFormats.Get "json" }}
"feed_url" : "{{ .Permalink }}",
{{- end }}
{{- with .Site.Params.GeekblogAuthor -}}
{{ with index $.Site.Data.authors . }}
"authors" : [
{
"name" : "{{ .name }}"{{ with .url }},
"url": "{{ . }}"{{ end }}{{ with .avatar }},
"avatar": "{{ . }}"{{ end }}
}
],
{{- end }}
{{- end }}
"items" : [
{{- $pages := where .RegularPages "Type" "in" .Site.Params.mainSections -}}
{{- if (eq .Kind "home") -}}
{{- $pages = where .Site.RegularPages "Type" "in" .Site.Params.mainSections -}}
{{- end -}}
{{- $len := (len $pages) }}
{{- range $i, $page := $pages }}
{
"title" : {{ .Title | jsonify }},
"date_published" : {{ (.Date.Format "2006-01-02T15:04:05Z07:00") | jsonify }},
"date_modified" : {{ (.Lastmod.Format "2006-01-02T15:04:05Z07:00") | jsonify }},
"id" : "{{ .Permalink }}",
"url" : "{{ .Permalink }}",
{{- with .Params.authors -}}
"authors" : [
{{- $authors := (sort .) }}
{{- $authors_len := (len $authors) }}
{{- range $i, $element := $authors -}}
{{- $author := index $.Site.Data.authors $element }}
{
"name" : "{{ $author.name }}"
}{{ if ne (add $i 1) $authors_len }},{{ end }}
{{- end }}
],
{{- end }}
"content_html" : {{ .Content | jsonify }}
}{{ if ne (add $i 1) $len }},{{ end }}
{{- end }}
]
}