Finish RSS and Atom implementations
This commit is contained in:
parent
d971696e11
commit
256eae44e9
9 changed files with 118 additions and 0 deletions
6
layouts/_default/atom_entry.atom
Normal file
6
layouts/_default/atom_entry.atom
Normal file
|
@ -0,0 +1,6 @@
|
|||
<entry>
|
||||
{{ partial "feeds/atom/entry_metadata.xml" . }}
|
||||
{{- if .Content -}}
|
||||
{{ `<content type="html"><![CDATA[` | safeHTML }}{{ .Content }}]]></content>
|
||||
{{- end -}}
|
||||
</entry>
|
4
layouts/_default/rss_item.rss
Normal file
4
layouts/_default/rss_item.rss
Normal file
|
@ -0,0 +1,4 @@
|
|||
<item>
|
||||
{{ partial "feeds/rss/item_metadata.xml" . }}
|
||||
<description>{{ `<![CDATA[` | safeHTML }}{{ .Content }}]]></description>
|
||||
</item>
|
7
layouts/_default/section.atom
Normal file
7
layouts/_default/section.atom
Normal file
|
@ -0,0 +1,7 @@
|
|||
{{- $page := . -}}
|
||||
{{- $pages := $page.RegularPages -}}
|
||||
{{- $limit := $.Site.Config.Services.RSS.Limit -}}
|
||||
{{- if ge $limit 1 -}}
|
||||
{{- $pages = $pages | first $limit -}}
|
||||
{{- end -}}
|
||||
{{ partial "feeds/atom/base.xml" (dict "context" $page "pages" $pages "limit" $limit) }}
|
7
layouts/index.atom
Normal file
7
layouts/index.atom
Normal file
|
@ -0,0 +1,7 @@
|
|||
{{- $pages := .Site.RegularPages -}}
|
||||
{{- $limit := .Site.Config.Services.RSS.Limit -}}
|
||||
{{- if ge $limit 1 -}}
|
||||
{{- $pages = $pages | first $limit -}}
|
||||
{{- end -}}
|
||||
|
||||
{{ partial "feeds/atom/base.xml" (dict "context" . "pages" $pages) }}
|
18
layouts/index.rss
Normal file
18
layouts/index.rss
Normal file
|
@ -0,0 +1,18 @@
|
|||
{{- $pageContext := . -}}
|
||||
{{- if .IsHome -}}
|
||||
{{ $pageContext = .Site }}
|
||||
{{- end -}}
|
||||
|
||||
{{- $pages := slice -}}
|
||||
{{- if or $.IsHome $.IsSection -}}
|
||||
{{- $pages = $pageContext.RegularPages -}}
|
||||
{{- else -}}
|
||||
{{- $pages = $pageContext.Pages -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $limit := .Site.Config.Services.RSS.Limit -}}
|
||||
{{- if ge $limit 1 -}}
|
||||
{{- $pages = $pages | first $limit -}}
|
||||
{{- end -}}
|
||||
|
||||
{{ partial "feeds/rss/base.xml" (dict "context" . "pages" $pages "Site" .Site) }}
|
26
layouts/partials/feeds/atom/base.xml
Normal file
26
layouts/partials/feeds/atom/base.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
{{- $context := .context -}}
|
||||
{{- $pages := .pages -}}
|
||||
{{- $limit := .limit -}}
|
||||
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>{{ $context.Site.Title }}</title>
|
||||
<link href="{{ $context.Permalink }}" />
|
||||
<link href="{{ `/feed.atom` | absURL }}" rel="self" />
|
||||
<link href="{{ `/icons/favicon.png` | absURL }}" rel="shortcut icon" />
|
||||
{{ with $context.Date }}
|
||||
<updated>{{ . | time.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</updated>
|
||||
{{ end }}
|
||||
<id>{{ $context.Permalink }}</id>
|
||||
{{ with $context.Site.Author }}
|
||||
<author>
|
||||
{{ with .name }}<name>{{ . }}</name>{{ end }}
|
||||
{{ with .email }}<email>{{ . }}</email>{{ end }}
|
||||
<uri>{{ $context.Site.Home.Permalink }}</uri>
|
||||
</author>
|
||||
{{ end }}
|
||||
<generator version="{{ hugo.Version }}" uri="https://gohugo.io">Hugo {{ hugo.Version }}</generator>
|
||||
<rights>© 2020-{{ now.Year }} Eryn Wells</rights>
|
||||
{{ range $pages }}
|
||||
{{ .Render "atom_entry" }}
|
||||
{{ end }}
|
||||
</feed>
|
11
layouts/partials/feeds/atom/entry_metadata.xml
Normal file
11
layouts/partials/feeds/atom/entry_metadata.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<title>{{ .Title }}</title>
|
||||
<id>{{ .Permalink }}</id>
|
||||
<link href="{{ .Permalink }}" />
|
||||
<published>{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</published>
|
||||
<updated>{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</updated>
|
||||
{{ range slice "series" "categories" "tags" }}
|
||||
{{- range $.GetTerms . }}
|
||||
{{- $scheme := (.Site.GetPage (printf "/%s" .Section)).Permalink -}}
|
||||
<category term="{{ .Name }}" scheme="{{ $scheme }}" label="{{ .Title }}" />
|
||||
{{ end -}}
|
||||
{{ end -}}
|
28
layouts/partials/feeds/rss/base.xml
Normal file
28
layouts/partials/feeds/rss/base.xml
Normal file
|
@ -0,0 +1,28 @@
|
|||
{{- $context := .context -}}
|
||||
{{- $pages := .pages -}}
|
||||
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title>{{ $context.Site.Title }}</title>
|
||||
<link>{{ $context.Permalink }}</link>
|
||||
<description>Recent content on {{ $context.Site.Title }}</description>
|
||||
<generator>Hugo {{ hugo.Version }}</generator>
|
||||
{{ with $context.Site.LanguageCode }}<language>{{ . }}</language>{{ end }}
|
||||
{{ with $context.Site.Author }}
|
||||
<managingEditor>{{ .name }} <{{ .email }}></managingEditor>
|
||||
<webMaster>{{ .name }} <{{ .email }}></webMaster>
|
||||
{{ end }}
|
||||
{{ with $context.Site.Copyright -}}
|
||||
<copyright>{{ . }}</copyright>
|
||||
{{- end }}
|
||||
{{ if not .Date.IsZero }}
|
||||
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>
|
||||
{{ end }}
|
||||
{{ with .OutputFormats.Get "RSS" }}{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}{{ end }}
|
||||
{{ range $pages }}
|
||||
{{ if not .Date.IsZero }}
|
||||
{{ .Render "rss_item" }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</channel>
|
||||
</rss>
|
11
layouts/partials/feeds/rss/item_metadata.xml
Normal file
11
layouts/partials/feeds/rss/item_metadata.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<title>{{ .Title }}</title>
|
||||
<link>{{ .Permalink }}</link>
|
||||
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
|
||||
{{ with .Site.Author.email }}<author>{{ . }}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
|
||||
<guid>{{ .Permalink }}</guid>
|
||||
{{- range slice "series" "categories" "tags" -}}
|
||||
{{ range $.GetTerms . }}
|
||||
{{- $domain := (.Site.GetPage (printf "/%s" .Section)).Permalink -}}
|
||||
<category domain="{{ $domain }}">{{ .Title }}</category>
|
||||
{{ end }}
|
||||
{{- end -}}
|
Loading…
Add table
Add a link
Reference in a new issue