Skip to content

Commit

Permalink
Enhancements to rss.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
1bl4z3r committed Jan 10, 2025
1 parent a11725e commit a42ca01
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ __Sites using hermit-V2__ is a user contributed list of all the blogs/pages that

You can find currently listed sites from [Sites-using-hermit‐V2 (https://github.com/1bl4z3r/hermit-V2/wiki#sites-using-hermit-v2)](https://github.com/1bl4z3r/hermit-V2/wiki#sites-using-hermit-v2) and you can add your site by raising an [issue](https://github.com/1bl4z3r/hermit-V2/issues/new?assignees=1bl4z3r&labels=hermit-V2+sites&projects=&template=add-remove-sites-using-hermit-v2.md&title=Add+to+Sites+using+hermit-V2).

## To-Do
- [ ] Add support for [Speculation Rules API](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API#browser_compatibility) when it is stable
## Share your thoughts
Share your thoughts on how to make this theme more suited for you. It could be a general feedback or something that couldn't be classified as an Issue. You can share it in Discussions : [https://github.com/1bl4z3r/hermit-V2/discussions](https://github.com/1bl4z3r/hermit-V2/discussions)

Expand Down
4 changes: 3 additions & 1 deletion content/posts/post-with-featured-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ title: "Post With Featured Image"
date: 2018-10-01T16:15:09+08:00
draft: false
images:
- https://picsum.photos/1024/768/?random
- https://picsum.photos/seed/picsum/1024/768
- images/928-600x400.jpg
featuredImg: "images/928-600x400.jpg"
tags:
- Demo
- Image
Expand Down
8 changes: 4 additions & 4 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ defaultContentLanguage = "en"
defaultContentLanguageInSubdir = true
enableRobotsTXT = true

enableEmoji = true

# [outputs]
# home = ['html', 'rss']
# page = ['html']
# home = ['html']
# page = ['html', 'rss']
# rss = ['rss']
# section = ['html', 'rss']
# taxonomy = ['html', 'rss']
# term = ['html', 'rss']

enableEmoji = true

[languages]
[languages.en]
title = 'Hermit - V2'
Expand Down
29 changes: 29 additions & 0 deletions layouts/partials/rss-image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{/* This partial is to help `rss.xml` on generating proper links to images in feed */}}
{{- with $path := .path -}}
{{- if not (or (findRE `http[s]{0,1}://` $path 1) (findRE `^\/.*` $path 1)) -}}
{{- with resources.Get $path -}}
<enclosure url="{{ .RelPermalink | absURL }}" length="" type="{{ .MediaType }}" />
<media:thumbnail url="{{ .RelPermalink | absURL }}" width="{{ .Width}}" height="{{ .Height}}" />
<media:content url="{{ .RelPermalink | absURL }}" medium="{{ .MediaType.MainType }}" type="{{ .MediaType}}" width="{{ .Width}}" height="{{ .Height}}" >
<media:title type="html">{{ . }}</media:title>
</media:content>
{{- end -}}
{{- else if findRE `^\/.*` $path 1 -}}
{{ $path := printf "%s%s" .Site.BaseURL (strings.TrimLeft "/" $path) }}
{{- with resources.GetRemote $path -}}
<enclosure url="{{ .Permalink }}" length="" type="{{ .MediaType }}" />
<media:thumbnail url="{{ .Permalink }}" width="{{ .Width}}" height="{{ .Height}}" />
<media:content url="{{ .Permalink }}" medium="{{ .MediaType.MainType }}" type="{{ .MediaType}}" width="{{ .Width}}" height="{{ .Height}}" >
<media:title type="html">{{ . }}</media:title>
</media:content>
{{- end -}}
{{- else -}}
{{- with resources.GetRemote . -}}
<enclosure url="{{ .Permalink }}" length="" type="{{ .MediaType }}" />
<media:thumbnail url="{{ .Permalink }}" width="{{ .Width}}" height="{{ .Height}}" />
<media:content url="{{ .Permalink }}" medium="{{ .MediaType.MainType }}" type="{{ .MediaType}}" width="{{ .Width}}" height="{{ .Height}}" >
<media:title type="html">{{ . }}</media:title>
</media:content>
{{- end -}}
{{- end -}}
{{- end -}}
38 changes: 32 additions & 6 deletions layouts/posts/rss.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
{{- $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" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<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 }}
<generator>Hugo -- {{ hugo.Version }}</generator>{{ with .Site.LanguageCode }}
<language>{{.}}</language>{{end}}{{ 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 }}
Expand All @@ -12,15 +25,28 @@
{{ with .OutputFormats.Get "RSS" -}}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{ end -}}
{{ range .Pages }}
{{- with $.Site.Params.images }}
<image>
<title>{{ site.Title }}</title>
<url>{{ index . 0 | absURL }}</url>
<link>{{ index . 0 | absURL }}</link>
</image>
{{- 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.Params.author.email }}<author>{{.}}{{ with $.Site.Params.author.name }} ({{.}}){{end}}</author>{{end}}
{{- with .Page.Params.author | default .Site.Params.author.name -}}<author>{{ . }}</author>{{- end -}}
<guid>{{ .Permalink }}</guid>
<description>{{ printf `<![CDATA[%s]]>` .Page.Params.description | safeHTML }}</description>
<content type="html">{{ printf `<![CDATA[%s]]>` .Content | safeHTML }}</content>
<description>{{- with .Page.Params.description | html }}{{ printf `<![CDATA[%s]]>` . | safeHTML }}{{ else }}{{ .Summary | html }}{{ end -}}</description>
{{- with .Page.Params.featuredImg -}}
{{- partial "rss-image.xml" (dict "path" .) -}}
{{- end -}}
{{- range .Page.Params.images -}}
{{- partial "rss-image.xml" (dict "path" .) -}}
{{- end -}}
<content type="text/html" mode="escaped">{{ (printf `<![CDATA[%s]]>` .Content) | safeHTML }}</content>
</item>
{{ end }}
</channel>
Expand Down

0 comments on commit a42ca01

Please sign in to comment.