Add json feed
This commit is contained in:
parent
2e2e603a3b
commit
58f744a223
5 changed files with 57 additions and 21 deletions
13
exampleSite/config.toml
vendored
13
exampleSite/config.toml
vendored
|
@ -16,9 +16,8 @@ disableKinds = ['RSS']
|
|||
|
||||
[outputs]
|
||||
# TODO:
|
||||
# home = [ "HTML", "Atom", "JSON", "humanstxt" ]
|
||||
# section = [ "HTML", "Atom" ]
|
||||
home = [ 'HTML', 'Atom', 'FEED', 'humanstxt' ]
|
||||
home = [ 'HTML', 'Atom', 'FEED', 'JSON', 'humanstxt' ]
|
||||
|
||||
# Atom feed.
|
||||
# For more see: https://validator.w3.org/feed/docs/atom.html#whatIsAtom
|
||||
|
@ -51,6 +50,16 @@ disableKinds = ['RSS']
|
|||
noUgly = true
|
||||
permalinkable = false
|
||||
|
||||
# For more see: https://www.jsonfeed.org/
|
||||
[outputFormats.JSON]
|
||||
name = 'Json'
|
||||
mediaType = 'application/json'
|
||||
baseName = 'feeds/feed'
|
||||
rel = 'alternate'
|
||||
isPlainText = true
|
||||
isHTML = false
|
||||
noUgly = false
|
||||
|
||||
# For more see: https://gohugo.io/templates/output-formats/
|
||||
[outputFormats.humanstxt]
|
||||
mediaType = 'text/plain'
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
xml:lang="{{ site.LanguageCode }}">
|
||||
{{ printf `<title type="html"><![CDATA[%s]]></title>` site.Title | safeHTML }}
|
||||
{{ with site.Params.description }}{{ printf `<subtitle type="html"><![CDATA[%s]]></subtitle>` . | safeHTML }}{{ end }}
|
||||
<link href="{{ "/" | absURL }}" type="text/html" />
|
||||
<link href="{{ site.BaseURL | absURL }}" type="text/html" />
|
||||
{{ with site.Home.OutputFormats.Get "ATOM" }}<link href="{{ .Permalink | absURL }}" rel="self" type="{{ .MediaType.Type | html }}" />{{ end }}
|
||||
{{ with site.Home.OutputFormats.Get "FEED"}}<link href="{{ .Permalink | absURL }}" rel="alternate" type="{{ .MediaType.Type | html }}" />{{end}}
|
||||
{{ with site.Home.OutputFormats.Get "JSON"}}<link href="{{ .Permalink | absURL }}" rel="alternate" type="{{ .MediaType.Type | html }}" />{{end}}
|
||||
{{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) }}{{ $logo = $logo.Resize "96x96" }}<icon>{{ $logo.Permalink | absURL }}</icon>
|
||||
<logo>{{ $logo.Permalink | absURL }}</logo>
|
||||
{{ with site.Author.name }}<author>
|
||||
|
|
|
@ -9,20 +9,21 @@
|
|||
xmlns:media="http://search.yahoo.com/mrss/"
|
||||
xml:lang="{{ site.LanguageCode }}">
|
||||
<channel>
|
||||
{{ printf `<title type="html"><![CDATA[%s RSS]]></title>` site.Title | safeHTML }}
|
||||
{{ printf `<title type="html"><![CDATA[%s RSS 2.0]]></title>` site.Title | safeHTML }}
|
||||
</channel>
|
||||
<link type="text/html">{{ "/" | absURL }}</link>
|
||||
<link type="text/html">{{ site.BaseURL | absURL }}</link>
|
||||
{{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) }}{{ $logo = $logo.Resize "96x96" }}
|
||||
<image>
|
||||
<url>{{ $logo.Permalink | absURL }}</url>
|
||||
{{ printf `<title type="html"><![CDATA[%s RSS]]></title>` site.Title | safeHTML }}
|
||||
<link>{{ "/" | absURL }}</link>
|
||||
{{ printf `<title type="html"><![CDATA[%s RSS 2.0]]></title>` site.Title | safeHTML }}
|
||||
<link>{{ site.BaseURL | absURL }}</link>
|
||||
<width>{{ $logo.Width }}</width>
|
||||
<height>{{ $logo.Height }}</height>
|
||||
</image>
|
||||
<link href="{{ "/" | absURL }}" type="text/html" />
|
||||
<link href="{{ site.BaseURL | absURL }}" type="text/html" />
|
||||
{{ with site.Home.OutputFormats.Get "FEED"}}<atom:link href="{{ .Permalink | absURL }}" rel="self" type="{{ .MediaType.Type | html }}" />{{end}}
|
||||
{{ with site.Home.OutputFormats.Get "ATOM"}}<atom:link href="{{ .Permalink | absURL }}" rel="alternate" type="{{ .MediaType.Type | html }}" />{{end}}
|
||||
{{ with site.Home.OutputFormats.Get "JSON"}}<link href="{{ .Permalink | absURL }}" rel="alternate" type="{{ .MediaType.Type | html }}" />{{end}}
|
||||
{{ with site.Params.description }}{{ printf `<description type="html"><![CDATA[%s]]></description>` . | safeHTML }}{{ end }}
|
||||
<generator>Hugo {{ hugo.Version }}</generator>
|
||||
{{ with site.Author.name }}{{ printf `<dc:creator type="html"><![CDATA[%s]]></dc:creator>` . | safeHTML }}{{ end }}
|
||||
|
|
26
layouts/_default/home.json.json
Normal file
26
layouts/_default/home.json.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"version": "https://jsonfeed.org/version/1.1",
|
||||
"title": {{ (printf "%s JSON Feed" site.Title) | jsonify }},
|
||||
"home_page_url": {{ site.BaseURL | absURL | jsonify }},
|
||||
{{ with .OutputFormats.Get "JSON" }}"feed_url": {{.Permalink | absURL | jsonify }},{{ end }}
|
||||
{{ with site.Params.description}}"description": {{site.Params.description | jsonify}},{{end}}
|
||||
{{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) }}{{ $logo = $logo.Resize "96x96" }}
|
||||
"icon": {{ $logo.Permalink | jsonify }},
|
||||
"favicon": {{ $logo.Permalink | jsonify }},
|
||||
{{ with site.Author.name }}"author":
|
||||
{
|
||||
"name": {{ . | jsonify }}
|
||||
},{{ end }}
|
||||
{{ with site.LanguageCode }}"language" : "{{ . }}",{{ end }}{{ $feedsize := site.Params.feedSize | default 25 }}
|
||||
"items": [{{ $r := first $feedsize (where site.RegularPages.ByDate.Reverse "Type" "in" site.Params.mainSections) }} {{ range $i, $ := $r }}{{ if $i }},{{ end }}
|
||||
{
|
||||
"id": {{ $uuid := sha1 (.Permalink | absURL)}}"{{substr $uuid 0 8}}-{{substr $uuid 8 4}}-5{{substr $uuid 13 3}}-{{substr $uuid 16 1}}9{{substr $uuid 17 2}}-{{substr $uuid 21 12}}",
|
||||
"url": {{ .Permalink | jsonify }},
|
||||
"title": {{ .Title | plainify | chomp | jsonify }},
|
||||
"summary": {{ .Summary | plainify | chomp | jsonify }},
|
||||
"date_published": {{ .PublishDate.UTC.Format site.Params.dateFormatFeed | jsonify }},
|
||||
"date_modified" : {{ .Lastmod.UTC.Format site.Params.dateFormatFeed | jsonify }}
|
||||
}
|
||||
{{- end}}
|
||||
]
|
||||
}
|
25
theme.toml
25
theme.toml
|
@ -11,32 +11,31 @@ demosite = "https://sergeyklay.github.io/gohugo-theme-ed/"
|
|||
|
||||
tags = [
|
||||
"blog",
|
||||
"responsive",
|
||||
"simple",
|
||||
"clean",
|
||||
"customizable",
|
||||
"ed",
|
||||
"light",
|
||||
"minimal",
|
||||
"minimalist",
|
||||
"customizable",
|
||||
"ed"
|
||||
"responsive",
|
||||
"simple"
|
||||
]
|
||||
|
||||
# The theme's features:
|
||||
features = [
|
||||
"blog",
|
||||
"shortcodes",
|
||||
"responsive",
|
||||
"posts",
|
||||
"opengraph",
|
||||
"favicon",
|
||||
# "archive",
|
||||
# "search",
|
||||
"clean",
|
||||
"simple",
|
||||
"favicon",
|
||||
"feed",
|
||||
"minimal",
|
||||
"minimalist",
|
||||
"mobile"
|
||||
"mobile",
|
||||
"opengraph",
|
||||
"posts",
|
||||
"responsive",
|
||||
"rss",
|
||||
"shortcodes",
|
||||
"simple"
|
||||
]
|
||||
|
||||
min_version = "0.95.0"
|
||||
|
|
Loading…
Reference in a new issue