From b52428a2cf70f89234bce9d556ae8362c9d79fb6 Mon Sep 17 00:00:00 2001 From: Adam Ormsby Date: Tue, 28 Apr 2020 20:56:34 -0500 Subject: [PATCH 1/9] copy internal hugo rss for customization --- layouts/_default/rss.xml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 layouts/_default/rss.xml diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml new file mode 100644 index 0000000..81aa8f6 --- /dev/null +++ b/layouts/_default/rss.xml @@ -0,0 +1,36 @@ +{{- $pctx := . -}} +{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}} +{{- $pages := $pctx.RegularPages -}} +{{- $limit := .Site.Config.Services.RSS.Limit -}} +{{- if ge $limit 1 -}} + {{- $pages = $pages | first $limit -}} +{{- end -}} +{{- printf "" | safeHTML }} + + + {{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }} + {{ .Permalink }} + Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }} + Hugo -- gohugo.io{{ with .Site.LanguageCode }} + {{.}}{{end}}{{ with .Site.Author.email }} + {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Author.email }} + {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Copyright }} + {{.}}{{end}}{{ if not .Date.IsZero }} + {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }} + {{ with .OutputFormats.Get "RSS" }} + {{ printf "" .Permalink .MediaType | safeHTML }} + {{ end }} + {{ range $pages }} + + {{ .Title }} + {{ .Permalink }} + {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} + {{ with .Site.Author.email }}{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}} + {{ .Permalink }} + + {{ .Summary | html }} + + + {{ end }} + + \ No newline at end of file From 2583a1c4bfa498e0d71730e956362c160c472d65 Mon Sep 17 00:00:00 2001 From: Adam Ormsby Date: Tue, 28 Apr 2020 20:58:39 -0500 Subject: [PATCH 2/9] add cover image from front matter, set auto cover grab as backup following similar hugo standard --- layouts/_default/rss.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index 81aa8f6..0a3a38e 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -28,6 +28,15 @@ {{ with .Site.Author.email }}{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}} {{ .Permalink }} + {{ if .Params.Cover }} + {{ if .Params.UseRelativeCover }}{{ printf "%s%s%s%s" ""}} + {{ else }}{{ printf "%s%s%s" ""}} + {{ end }} + {{ else }} + {{ $images := .Resources.ByType "image" }} + {{ $featured := $images.GetMatch "{*featured*,*cover*,*thumbnail*}" }} + {{ with $featured }}{{ printf "%s%s%s" ""}}{{ end }} + {{ end }} {{ .Summary | html }} From 9cce3e783eba97987cf313e410af3abba1c63d8a Mon Sep 17 00:00:00 2001 From: Adam Ormsby Date: Tue, 28 Apr 2020 21:32:14 -0500 Subject: [PATCH 3/9] check rssFullText param (new), display either full content, description, or summary in feed --- layouts/_default/rss.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index 0a3a38e..13eb5a5 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -37,8 +37,14 @@ {{ $featured := $images.GetMatch "{*featured*,*cover*,*thumbnail*}" }} {{ with $featured }}{{ printf "%s%s%s" ""}}{{ end }} {{ end }} - {{ .Summary | html }} - + + {{ if .Site.Params.RssFullText }}{{ .Content | html }} + {{ else }} + {{ with .Description }}{{ . | html }} + {{ else }}{{ .Summary | html }} + {{ end }} + {{ end }} + {{ end }} From f62c476876622cb685a03a7177e8c9f5c7cff2cc Mon Sep 17 00:00:00 2001 From: Adam Ormsby Date: Tue, 28 Apr 2020 23:09:55 -0500 Subject: [PATCH 4/9] update readme with RSS enhancements --- README.md | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b3eefdc..69d8220 100644 --- a/README.md +++ b/README.md @@ -10,21 +10,24 @@ This theme is pretty basic and covers all of the essentials. All you have to do --- -- [Features](#features) -- [Built-in shortcodes](#built-in-shortcodes) -- [Code highlighting](#code-highlighting) -- [How to start](#how-to-start) -- [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 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-read-more-button) -- [Add-ons](#add-ons) -- [How to run your site](#how-to-run-your-site) -- [How to edit the theme](#how-to-edit-the-theme) -- [How to contribute](#how-to-contribute) -- [Hello Friend theme user?](#hello-friend-theme-user) -- [Sponsoring](#sponsoring) -- [Licence](#licence) +- [Hello Friend](#hello-friend) + - [DEMO - https://hugo-hello-friend.now.sh/](#demo---httpshugo-hello-friendnowsh) + - [Features](#features) + - [Built-in shortcodes](#built-in-shortcodes) + - [Code highlighting](#code-highlighting) + - [Improved RSS Feed](#improved-rss-feed) + - [How to start](#how-to-start) + - [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 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) + - [Add-ons](#add-ons) + - [How to run your site](#how-to-run-your-site) + - [How to edit the theme](#how-to-edit-the-theme) + - [How to contribute](#how-to-contribute) + - [`Hello Friend` theme user?](#hello-friend-theme-user) + - [Sponsoring](#sponsoring) + - [License](#license) ## Features @@ -53,6 +56,14 @@ 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. +#### Improved RSS Feed + +Some small 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 it's 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. + ## 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. @@ -92,6 +103,10 @@ paginate = 5 # Show reading time in minutes for posts showReadingTime = false + # Show full page content in RSS feed items + #(default is Description or Summary metadata in the front matter) + # rssFullText = true + [languages] [languages.en] title = "Hello Friend" From 043852e38727c6ca0e7dd11fba89742c979b1731 Mon Sep 17 00:00:00 2001 From: Adam Ormsby Date: Tue, 28 Apr 2020 23:25:13 -0500 Subject: [PATCH 5/9] fix minor typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69d8220..eb4dd90 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ By default the theme is using PrismJS to color your code syntax. All you need to Some small 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 it's 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'. +**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. From 05c034a9667e7bee94064a2ebd5f15bbd749e0c0 Mon Sep 17 00:00:00 2001 From: Adam Ormsby Date: Wed, 29 Apr 2020 15:13:15 -0500 Subject: [PATCH 6/9] fix rss top to match hugo internal --- layouts/_default/rss.xml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index 13eb5a5..c15d399 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -1,9 +1,14 @@ {{- $pctx := . -}} {{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}} -{{- $pages := $pctx.RegularPages -}} +{{- $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 -}} +{{- $pages = $pages | first $limit -}} {{- end -}} {{- printf "" | safeHTML }} From b4504b35b2800ba9f1ce0517e6c462df5883f257 Mon Sep 17 00:00:00 2001 From: Adam Ormsby Date: Wed, 20 May 2020 12:43:00 -0500 Subject: [PATCH 7/9] fix img tags --- layouts/_default/rss.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index c15d399..4176413 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -34,13 +34,13 @@ {{ .Permalink }} {{ if .Params.Cover }} - {{ if .Params.UseRelativeCover }}{{ printf "%s%s%s%s" ""}} - {{ else }}{{ printf "%s%s%s" ""}} + {{ if .Params.UseRelativeCover }}{{ printf "%s%s%s%s" ""}} + {{ else }}{{ printf "%s%s%s" ""}} {{ end }} {{ else }} {{ $images := .Resources.ByType "image" }} {{ $featured := $images.GetMatch "{*featured*,*cover*,*thumbnail*}" }} - {{ with $featured }}{{ printf "%s%s%s" ""}}{{ end }} + {{ with $featured }}{{ printf "%s%s%s" ""}}{{ end }} {{ end }} {{ if .Site.Params.RssFullText }}{{ .Content | html }} From f35a6c88a1e8341946a1d6b41ee2b956d2442428 Mon Sep 17 00:00:00 2001 From: Adam Ormsby Date: Wed, 20 May 2020 13:59:33 -0500 Subject: [PATCH 8/9] add rss image --- README.md | 38 +++++++++++++++++++------------------- layouts/_default/rss.xml | 8 ++++++++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index eb4dd90..ade0a6a 100644 --- a/README.md +++ b/README.md @@ -10,24 +10,22 @@ This theme is pretty basic and covers all of the essentials. All you have to do --- -- [Hello Friend](#hello-friend) - - [DEMO - https://hugo-hello-friend.now.sh/](#demo---httpshugo-hello-friendnowsh) - - [Features](#features) - - [Built-in shortcodes](#built-in-shortcodes) - - [Code highlighting](#code-highlighting) - - [Improved RSS Feed](#improved-rss-feed) - - [How to start](#how-to-start) - - [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 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) - - [Add-ons](#add-ons) - - [How to run your site](#how-to-run-your-site) - - [How to edit the theme](#how-to-edit-the-theme) - - [How to contribute](#how-to-contribute) - - [`Hello Friend` theme user?](#hello-friend-theme-user) - - [Sponsoring](#sponsoring) - - [License](#license) +- [Features](#features) + - [Built-in shortcodes](#built-in-shortcodes) + - [Code highlighting](#code-highlighting) + - [Improved RSS Feed](#improved-rss-feed) +- [How to start](#how-to-start) +- [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 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-read-more-button) +- [Add-ons](#add-ons) +- [How to run your site](#how-to-run-your-site) +- [How to edit the theme](#how-to-edit-the-theme) +- [How to contribute](#how-to-contribute) +- [`Hello Friend` theme user?](#hello-friend-theme-user) +- [Sponsoring](#sponsoring) +- [License](#license) ## Features @@ -58,12 +56,14 @@ By default the theme is using PrismJS to color your code syntax. All you need to #### Improved RSS Feed -Some small 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. +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 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. diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index 4176413..696cf60 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -14,6 +14,14 @@ {{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }} + + {{ if .Site.Params.RssImage }} + {{ printf "%s%s" .Permalink .Site.Params.RssImage }} + {{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }} + {{ .Permalink }} + + {{ end }} + {{ .Permalink }} Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }} Hugo -- gohugo.io{{ with .Site.LanguageCode }} From 005e9fca71408da1a2b53bde1ff7b1718b9db479 Mon Sep 17 00:00:00 2001 From: Adam Ormsby Date: Tue, 26 May 2020 18:38:15 -0500 Subject: [PATCH 9/9] better printf style --- layouts/_default/rss.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index 696cf60..83dd3d3 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -42,13 +42,13 @@ {{ .Permalink }} {{ if .Params.Cover }} - {{ if .Params.UseRelativeCover }}{{ printf "%s%s%s%s" ""}} - {{ else }}{{ printf "%s%s%s" ""}} + {{ if .Params.UseRelativeCover }}{{ printf "" .Permalink .Params.Cover }} + {{ else }}{{ printf "" (.Params.Cover | absURL) }} {{ end }} {{ else }} {{ $images := .Resources.ByType "image" }} {{ $featured := $images.GetMatch "{*featured*,*cover*,*thumbnail*}" }} - {{ with $featured }}{{ printf "%s%s%s" ""}}{{ end }} + {{ with $featured }}{{ printf "" $featured.Permalink }}{{ end }} {{ end }} {{ if .Site.Params.RssFullText }}{{ .Content | html }}