Creating an RSS feed for r-bloggers for my blogdown
I am following Yongfu’s blog: I copy here the content in case it is moved:
Copy the default RSS template
Change
{{ .Summary | html }} to{{ .Content | html }}
Create subdirectories in layouts/ and save the RSS template files (name them rss.xml) in them (one for each subdirectory).
I was first confused when I wanted to copy the rss.xml file mentioned and didn’t know where to go. I finally found the section from which I could go to the file I was supposed to copy.
So far so good, so without further testing I assume this worked.
Following the instructions, I moved the rss.xml file to layouts/post/
to only report posts of the blog, not new projects or other leafs from Hugo.
I also created a rss.xml on layouts/categories/
.
As the templates provided by gohugo.io didn’t work I copied and pasted the files from Yongfu’s Blog.
To check that it worked I went to llrs.dev/categories/cran/index.xml
.
It did but not for all the posts. I kept getting an error even when I set a limit of 20 post on the config.toml file rssLimit = 20
.
I abandoned this for a while, other projects, pandemia…
When I came back I updated the template on 30/12/2021 and the same error was still happening. After some digging I found that there is a bug on Hugo generating invalid XML code for the feeds.
I started looking for workarounds but adding a php function or a go function didn’t work well. I couldn’t correctly set up the php function and I don’t know how to write go.
Then I started thinking on limiting the issue, which let it to rssLimit. After several checks I didn’t manage to make it work.
But while reading a post I realized that rssLimit was no longer used (if it was ever on the first place).
So after adding:
[Services.RSS]
limit = 10
on my config.toml with the new template, the xml feeds are working again. There is only one problem. The twitter tag feed doesn’t work, because the post that creates invalid content is there.
Hope that this save people some time if they try to do that. If you follow the linked posts like this one and take into account this change on how to limit RSS you might avoid the problem.
Reproducibility
## ─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
## setting value
## version R version 4.2.0 (2022-04-22)
## os Ubuntu 20.04.4 LTS
## system x86_64, linux-gnu
## ui X11
## language (EN)
## collate en_US.UTF-8
## ctype en_US.UTF-8
## tz Europe/Madrid
## date 2022-05-09
## pandoc 2.17.1.1 @ /usr/lib/rstudio/bin/quarto/bin/ (via rmarkdown)
##
## ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
## package * version date (UTC) lib source
## blogdown 1.9 2022-03-28 [1] CRAN (R 4.2.0)
## bookdown 0.26 2022-04-15 [1] CRAN (R 4.2.0)
## bslib 0.3.1 2021-10-06 [1] CRAN (R 4.2.0)
## cli 3.3.0 2022-04-25 [1] CRAN (R 4.2.0)
## digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.0)
## evaluate 0.15 2022-02-18 [1] CRAN (R 4.2.0)
## fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0)
## htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.2.0)
## jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.2.0)
## jsonlite 1.8.0 2022-02-22 [1] CRAN (R 4.2.0)
## knitr 1.39 2022-04-26 [1] CRAN (R 4.2.0)
## magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0)
## R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0)
## rlang 1.0.2 2022-03-04 [1] CRAN (R 4.2.0)
## rmarkdown 2.14 2022-04-25 [1] CRAN (R 4.2.0)
## rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.2.0)
## sass 0.4.1 2022-03-23 [1] CRAN (R 4.2.0)
## sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0)
## stringi 1.7.6 2021-11-29 [1] CRAN (R 4.2.0)
## stringr 1.4.0 2019-02-10 [1] CRAN (R 4.2.0)
## xfun 0.30 2022-03-02 [1] CRAN (R 4.2.0)
## yaml 2.3.5 2022-02-21 [1] CRAN (R 4.2.0)
##
## [1] /home/lluis/bin/R/4.2.0/lib/R/library
##
## ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────