Merge pull request #148 from aormsby/PR-rss

RSS Enhancements
This commit is contained in:
Radek Kozieł 2020-05-27 23:22:06 +02:00 committed by GitHub
commit d72593b1b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 3 deletions

View file

@ -11,15 +11,16 @@ This theme is pretty basic and covers all of the essentials. All you have to do
--- ---
- [Hello Friend](#hello-friend) - [Hello Friend](#hello-friend)
- [DEMO - https://hugo-hello-friend.now.sh/](#demo---httpshugo-hello-friendnowsh) - [DEMO - https://hugo-hello-friend.now.sh/](#demo---httpshugo-hello-friendnowsh)
- [Features](#features) - [Features](#features)
- [Built-in shortcodes](#built-in-shortcodes) - [Built-in shortcodes](#built-in-shortcodes)
- [Code highlighting](#code-highlighting) - [Code highlighting](#code-highlighting)
- [Improved RSS Feed](#improved-rss-feed)
- [How to start](#how-to-start) - [How to start](#how-to-start)
- [How to configure](#how-to-configure) - [How to configure](#how-to-configure)
- [How to add a cover image to your posts](#how-to-add-a-cover-image-to-your-posts) - [How to add a cover image to your posts](#how-to-add-a-cover-image-to-your-posts)
- [How to display the Last Modified Date in your posts](#how-to-display-the-last-modified-date-in-your-posts) - [How to display the Last Modified Date in your posts](#how-to-display-the-last-modified-date-in-your-posts)
- [How to hide "Read more" button](#how-to-hide-%22read-more%22-button) - [How to hide "Read more" button](#how-to-hide-read-more-button)
- [Add-ons](#add-ons) - [Add-ons](#add-ons)
- [How to run your site](#how-to-run-your-site) - [How to run your site](#how-to-run-your-site)
- [How to edit the theme](#how-to-edit-the-theme) - [How to edit the theme](#how-to-edit-the-theme)
@ -57,6 +58,16 @@ By default the theme is using PrismJS to color your code syntax. All you need to
**Supported languages**: bash/shell, css, clike, javascript, apacheconf, actionscript, applescript, c, csharp, cpp, coffeescript, ruby, csp, css-extras, diff, django, docker, elixir, elm, markup-templating, erlang, fsharp, flow, git, go, graphql, less, handlebars, haskell, http, java, json, kotlin, latex, markdown, makefile, objectivec, ocaml, perl, php, php-extras, r, sql, processing, scss, python, jsx, typescript, toml, reason, textile, rust, sass, stylus, scheme, pug, swift, yaml, haml, twig, tsx, vim, visual-basic, wasm. **Supported languages**: bash/shell, css, clike, javascript, apacheconf, actionscript, applescript, c, csharp, cpp, coffeescript, ruby, csp, css-extras, diff, django, docker, elixir, elm, markup-templating, erlang, fsharp, flow, git, go, graphql, less, handlebars, haskell, http, java, json, kotlin, latex, markdown, makefile, objectivec, ocaml, perl, php, php-extras, r, sql, processing, scss, python, jsx, typescript, toml, reason, textile, rust, sass, stylus, scheme, pug, swift, yaml, haml, twig, tsx, vim, visual-basic, wasm.
#### Improved RSS Feed
Some enhancements have been made to Hugo's [internal RSS](https://github.com/gohugoio/hugo/blob/25a6b33693992e8c6d9c35bc1e781ce3e2bca4be/tpl/tplimpl/embedded/templates/_default/rss.xml) generation code.
**A page's cover image now appears at the top of its feed display**. This image is set manually using [the cover params](#how-to-add-a-cover-image-to-your-posts). If unset, the RSS generator searches for the first image file in the page bundle whose name includes 'featured', 'cover', or 'thumbnail'.
**You can optionally display the full page content in your RSS feed** (default is Description or Summary data from Front Matter). Set `rssFullText = true` in your `config.toml` file to enable this option.
**You can choose a site image to be displayed when searching for your RSS feed.** Set `rssImage = "image/url/here"` in your `config.toml` file to enable this option.
## How to start ## How to start
You can download the theme manually by going to [https://github.com/panr/hugo-theme-hello-friend.git](https://github.com/panr/hugo-theme-hello-friend.git) and pasting it to `themes/hello-friend` in your root directory. You can download the theme manually by going to [https://github.com/panr/hugo-theme-hello-friend.git](https://github.com/panr/hugo-theme-hello-friend.git) and pasting it to `themes/hello-friend` in your root directory.
@ -98,7 +109,11 @@ paginate = 5
# Show table of contents at the top of your posts (defaults to false) # Show table of contents at the top of your posts (defaults to false)
# Alternatively, add this param to post front matter for specific posts # Alternatively, add this param to post front matter for specific posts
toc = true # toc = true
# Show full page content in RSS feed items
#(default is Description or Summary metadata in the front matter)
# rssFullText = true
[languages] [languages]
[languages.en] [languages.en]

64
layouts/_default/rss.xml Normal file
View file

@ -0,0 +1,64 @@
{{- $pctx := . -}}
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
{{- $pages := slice -}}
{{- if or $.IsHome $.IsSection -}}
{{- $pages = $pctx.RegularPages -}}
{{- else -}}
{{- $pages = $pctx.Pages -}}
{{- end -}}
{{- $limit := .Site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}
{{- 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>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
{{ if .Site.Params.RssImage }}<image>
<url>{{ printf "%s%s" .Permalink .Site.Params.RssImage }}</url>
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<link>{{ .Permalink }}</link>
</image>
{{ end }}
<link>{{ .Permalink }}</link>
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description>
<generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
<language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .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 }}
<item>
<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>
<description>
{{ if .Params.Cover }}
{{ if .Params.UseRelativeCover }}{{ printf "<img src=\"%s%s\"/>" .Permalink .Params.Cover }}
{{ else }}{{ printf "<img src=\"%s\"/>" (.Params.Cover | absURL) }}
{{ end }}
{{ else }}
{{ $images := .Resources.ByType "image" }}
{{ $featured := $images.GetMatch "{*featured*,*cover*,*thumbnail*}" }}
{{ with $featured }}{{ printf "<img src=\"%s\"/>" $featured.Permalink }}{{ end }}
{{ end }}
{{ if .Site.Params.RssFullText }}{{ .Content | html }}
{{ else }}
{{ with .Description }}{{ . | html }}
{{ else }}{{ .Summary | html }}
{{ end }}
{{ end }}
</description>
</item>
{{ end }}
</channel>
</rss>