Files
FixIt/layouts/partials/feed/rss.html
T
Cell 3ffef8acb0 ♻️ Refactor: refactor the feed and search features (#490)
* 🔍 Refactor: add JSON feed support and refactor output formats build in FixIt

Close #475

* 🚚 Feat: migrate index templates to layouts/_default folder and home.[name].html

* 📝 Style(ignore): fix typo

* 🚚 Chore: migrate index templates to default home templates

* 🚚 Chore: migrate section templates to layouts/section folder

*  Feat: add JSON feed support for section pages (#475)

* 🚧 Feat: add common template for JSON feed (#475)

* 🚧 Feat: add JSON feed support for section and term list pages

* 🚀 Chore: fix git stage error in update-version script

*  Perf: add front matter hiddenFromFeed for JSON feed (#475)

* 🔍 Feat: add tags attribute for JSON feed (#475)

* ♻️ Refactor: refactor RSS feed templates

Close #488

* 🚧 WIP: rename json-feed.html to json.html

* 🚧 Feat: revert single.md

*  Perf: enhance JSON feed 1.1 compatibility

* ♻️ Refactor: refactor post author map getting

*  WIP: add featured image support in feed

* 📝 Docs: update README and screenshot

* 🔧 Chore: update changelog template

* 🚧 WIP: add feed scoped config for section and list

* 🔥 Feat: migrate JSON feed to hugo-fixit/hugo-json-feed

Close hugo-fixit/hugo-json-feed#1

* 🚚 Feat: remove front matter hiddenFromRss and rssFullText,  add  front matter hiddenFromFeed
2024-08-24 17:30:31 +08:00

73 lines
3.5 KiB
HTML

{{- $pages := .Pages -}}
{{- /* Front matter: password */ -}}
{{- $pages = where $pages "Params.password" "eq" nil -}}
{{- /* Front matter: hiddenFromFeed */ -}}
{{- $pages = where $pages "Params.hiddenFromFeed" "ne" true -}}
{{- if ge .Config.limit 1 -}}
{{- $pages = $pages | first .Config.limit -}}
{{- end -}}
{{- $length := $pages.Len -}}
{{- /* TODO 文章内图片链接、分类、标签等处理 */ -}}
{{- 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>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<description>{{ .Site.Params.description | default .Site.Title }}</description>
<generator>Hugo {{ hugo.Version }} &amp; FixIt {{ .Version }}</generator>
<language>{{ .Site.Language.LanguageCode }}</language>{{ with .Site.Params.author.email }}
<managingEditor>{{.}}{{ with $.Site.Params.author.name }} ({{ . }}){{ end }}</managingEditor>{{ end }}{{ with .Site.Params.author.email }}
<webMaster>{{ . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end }}</webMaster>{{ end }}{{ with .Site.Copyright }}
<copyright>{{ . }}</copyright>{{ end }}{{ if not .Date.IsZero }}
<lastBuildDate>{{ (index $pages.ByLastmod.Reverse 0).Lastmod.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 $page := $pages }}
{{- $params := .Params | merge .Site.Params.Page }}
{{- $fullText := ((.Params.feed | default dict) | merge $.Config ).fullText }}
{{- $author := partial "function/get-author-map.html" .Params.author }}
{{- $image := $params.featuredimagepreview | default $params.featuredimage }}
{{- with $image }}
{{- if not (hasPrefix . "/") }}
{{- $image = (printf "%s%s" $page.RelPermalink .) | safeURL }}
{{- end }}
{{- $image = $image | absURL }}
{{- end }}
{{- with .Resources.GetMatch "featured-image" }}
{{- $image = .Permalink }}
{{- end }}
{{- with .Resources.GetMatch "featured-image-preview" }}
{{- $image = .Permalink }}
{{- end }}
<item>
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
{{- with $author.email }}<author>{{ . }}{{ with $author.name }} ({{ . }}){{ end }}</author>{{ end }}
<guid>{{ .Permalink }}</guid>
{{- with .GetTerms "categories" }}
{{- range . }}
<category domain="{{ .Permalink }}">{{ .LinkTitle }}</category>
{{- end }}
{{- end }}
{{- if $fullText }}
<description>
{{- "<![CDATA[" | safeHTML }}
{{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" }}
{{- /* {{- $content | replaceRE `<figure[^>]*>.*</figure>` "" | replaceRE `<img[^>]*( /)?>` "" | safeHTML -}} */ -}}
{{- with $image }}
{{- $content = add (printf "<img src=%q alt=%q referrerpolicy=%q>" . "featured image" "no-referrer") $content | safeHTML }}
{{- end }}
{{- $content | transform.XMLEscape | safeHTML }}
{{- "]]>" | safeHTML -}}
</description>
{{- else }}
<description>{{ (.Summary | default .Description | default .Title) | transform.XMLEscape | safeHTML }}</description>
{{- end }}
</item>
{{- end }}
</channel>
</rss>