diff options
author | Queensferry <queensferry.me@gmail.com> | 2021-02-25 16:56:26 +0300 |
---|---|---|
committer | Queensferry <queensferry.me@gmail.com> | 2021-02-25 17:24:11 +0300 |
commit | 316adf0604319cf6eaf3bf1e744e9cee05bbc9bc (patch) | |
tree | 3dc7218551d4e915e9b3383651cb9eab7eaf363e | |
parent | 2fbbf29bbc5fd9183c3eb12d772cdd01b9b72e51 (diff) |
feat: introduce option for full text rss
-rw-r--r-- | exampleSite/config.toml | 1 | ||||
-rw-r--r-- | layouts/_default/rss.xml | 46 | ||||
-rw-r--r-- | layouts/partials/head.html | 30 |
3 files changed, 65 insertions, 12 deletions
diff --git a/exampleSite/config.toml b/exampleSite/config.toml index a5657c9..a89ce22 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -38,6 +38,7 @@ name = "author" [params] custom_css = [] description = "an example site for hugo theme TeXify" + enableFullRSS = true enable_mathjax = true footnote = "Follow me on <a class=link href=https://github.com/queensferryme>GitHub</a>, <a class=link href=https://twitter.com/queensferryme>Twitter</a> or <a class=link href=/index.xml>RSS</a> | <a class=link href=https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh target=_blank rel=noopener>CC BY-NC-SA 4.0</a>" keywords = ["hugo", "latex", "theme"] diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml new file mode 100644 index 0000000..e228d88 --- /dev/null +++ b/layouts/_default/rss.xml @@ -0,0 +1,46 @@ +<!-- https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml --> + +{{- $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> + <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> + {{ if .Site.Params.enableFullRSS }} + <description>{{ .Content | html }}</description> + {{ else }} + <description>{{ .Summary | html }}</description> + {{ end }} + </item> + {{ end }} + </channel> +</rss> + diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 295fb16..5e86c8c 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -21,18 +21,18 @@ <meta name="keywords" content="{{ range $key, $value := .Site.Params.keywords }} {{ $value }} {{ end }}"> {{ end }} -<!-- twitter --> -<meta name="twitter:card" content="summary" /> -<meta name="twitter:title" content="{{ .Title }}" /> -<meta name="twitter:description" content="{{ .Summary }}" /> +<!-- mathjax --> +{{ if .Site.Params.enable_mathjax }} +{{ partial "mathjax.html" . }} +{{ end }} <!-- permalink --> <link rel="canonical" href="{{ .Permalink }}"> -<!-- style --> -<link media="screen" rel="stylesheet" href='{{ "css/common.css" | absURL }}'> -<link media="screen" rel="stylesheet" href='{{ "css/content.css" | absURL }}'> -<link media="screen" rel="stylesheet" href='{{ "css/highlight.css" | absURL }}'> +<!-- rss --> +{{ range .AlternativeOutputFormats -}} + {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} +{{ end -}} <!-- site title --> {{ if .IsHome }} @@ -41,7 +41,13 @@ <title>{{ .Title }} - {{ .Site.Title }}</title> {{ end }} -<!-- mathjax --> -{{ if .Site.Params.enable_mathjax }} -{{ partial "mathjax.html" . }} -{{ end }} +<!-- style --> +<link media="screen" rel="stylesheet" href='{{ "css/common.css" | absURL }}'> +<link media="screen" rel="stylesheet" href='{{ "css/content.css" | absURL }}'> +<link media="screen" rel="stylesheet" href='{{ "css/highlight.css" | absURL }}'> + +<!-- twitter --> +<meta name="twitter:card" content="summary" /> +<meta name="twitter:title" content="{{ .Title }}" /> +<meta name="twitter:description" content="{{ .Summary }}" /> + |