Attempt to fix RSS encoding
This commit is contained in:
parent
1cde952f62
commit
67f1ee0770
2 changed files with 44 additions and 2 deletions
|
@ -11,7 +11,10 @@
|
||||||
{{- $pages = $pages | first $limit -}}
|
{{- $pages = $pages | first $limit -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
|
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
|
||||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
||||||
|
xmlns:atom="http://www.w3.org/2005/Atom"
|
||||||
|
xml:base="{{ .Site.BaseURL }}">
|
||||||
<channel>
|
<channel>
|
||||||
<title>{{ .Site.Author.name }}'s blog</title>
|
<title>{{ .Site.Author.name }}'s blog</title>
|
||||||
<link>{{ .Permalink }}</link>
|
<link>{{ .Permalink }}</link>
|
||||||
|
@ -31,7 +34,8 @@
|
||||||
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
|
<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}}
|
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
|
||||||
<guid>{{ .Permalink }}</guid>
|
<guid>{{ .Permalink }}</guid>
|
||||||
<description>{{ .Content | html }}</description>
|
<description>{{ "<![CDATA[" | safeHTML }} {{ .Summary }}]]></description>
|
||||||
|
<content:encoded>{{ "<![CDATA[" | safeHTML }} {{ partial "rss.html" . | safeHTML }}]]></content:encoded>
|
||||||
</item>
|
</item>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</channel>
|
</channel>
|
||||||
|
|
38
themes/red/layouts/partials/rss.html
Normal file
38
themes/red/layouts/partials/rss.html
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
{{ $html := .Content | safeHTML }}
|
||||||
|
|
||||||
|
{{ $hrefs := findRE "href=\"([^\"]*)\"" $html }}
|
||||||
|
{{ range $href := $hrefs}}
|
||||||
|
{{ $absHref := strings.TrimPrefix "href=\"" $href }}
|
||||||
|
{{ $absHref = strings.TrimSuffix "\"" $absHref }}
|
||||||
|
{{ $absHref = printf "href=\"%s\"" ($absHref | absURL) }}
|
||||||
|
{{ $html = replace $html $href $absHref }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ $srcs := findRE "src=\"([^\"]*)\"" $html }}
|
||||||
|
{{ range $src := $srcs}}
|
||||||
|
{{ $absSrc := strings.TrimPrefix "src=\"" $src }}
|
||||||
|
{{ $absSrc = strings.TrimSuffix "\"" $absSrc }}
|
||||||
|
{{ $absSrc = printf "src=\"%s\"" ($absSrc | absURL) }}
|
||||||
|
{{ $html = replace $html $src $absSrc }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ $srcset := findRE "srcset=\"([^\"]*)\"" $html }}
|
||||||
|
{{ range $set := $srcset}}
|
||||||
|
{{ $parts := strings.TrimPrefix "srcset=\"" $set }}
|
||||||
|
{{ $parts = strings.TrimSuffix "\"" $parts }}
|
||||||
|
{{ $parts = split $parts "," }}
|
||||||
|
{{ $newSrcset := slice }}
|
||||||
|
{{ range $part := $parts }}
|
||||||
|
{{ $part = $part | replaceRE "^\\s*(.*)\\s*$" "$1" }}
|
||||||
|
{{ $lg := split $part " " }}
|
||||||
|
{{ $href := index $lg 0 | absURL }}
|
||||||
|
{{ $size := index $lg 1 }}
|
||||||
|
{{ $newSrcset = $newSrcset | append (printf "%s %s" $href $size) }}
|
||||||
|
{{ end }}
|
||||||
|
{{ $newSrcset = delimit $newSrcset ", " }}
|
||||||
|
{{ $newSrcset = printf "srcset=\"%s\"" $newSrcset }}
|
||||||
|
{{ $html = replace $html $set $newSrcset }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ return $html }}
|
Loading…
Add table
Reference in a new issue