mirror of
https://github.com/thegeeklab/hugo-geekblog.git
synced 2024-11-22 05:00:39 +00:00
add template for json feeds
This commit is contained in:
parent
c0a15b9c5f
commit
c3e9abbb34
@ -1,2 +1,2 @@
|
|||||||
- ENHANCEMENT
|
- ENHANCEMENT
|
||||||
- switch back to Hugo internal twitter-card template
|
- add template for Json Feeds
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
57
layouts/_default/list.json.json
Normal file
57
layouts/_default/list.json.json
Normal 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 }}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user