RSS Feed Link is Broken on Posts
gian-hancock opened this issue · 6 comments
Describe the bug
The RSS Feed link at the bottom of posts 404s. The link works correctly on the /posts/
list and the home page.
Steps to reproduce
Tested with v1.13.0
:
- Run the provided exampleSite.
- Click the RSS feed link on the home page (it works)
- Go to any post, e.g.
/posts/table-of-content/
- Click the RSS feed link (it 404s)
Expected behavior
I don't know what the best behaviour is, in my case I overrode the footer partial with to disable the RSS link for posts:
// filepath: <root>/layouts/partials/footer.html
// ... snip
<div class="footer_social-icons">
{{- if .Page.IsPage -}}
<!-- Remove RSS feed icon for pages -->
{{- partial "socialIcons.html" (where site.Params.socialIcons "name" "!=" "Rss") -}}
{{- else -}}
{{- partial "socialIcons.html" site.Params.socialIcons -}}
{{- end -}}
</div>
// snip ...
For the example site, it would make sense to link to the /posts
feed, however in general I think there could be cases where a post appears in multiple feeds, so it might be unclear which is the best feed to pick. I'm a Hugo newbie so I don't know if this "ambiguous" feed thing is an actual possibility.
Device information
Windows 11
Hugo 0.121.1 installed via Chocolatey
Thanks @gian-hancock for reporting this issue.
I will have a look at it when I get some time.
In socialIcons.html
it just sets the href to url value. when url is set to "index.xml".
It just adds this string to the page url which is not a problem if you are in a menu like posts
or about
but when you are reading a post in a certain menu, the url is resolved as baseURL/menu/tile_of_the_post/index.xml
, which does not exist.
If you are trying to provide rss feed links for separate menus or tabs in your website it is better to have feeds in a separate page.
- set url of rss icon as ->
url = "/feeds/"
(or name it as you like) - by clicking rss icon it redirects to ->
baseURL/feeds/
- create new content with feeds/index.md
- change title if you want, maybe delete the date entry so that it won't be displayed
- add
index.xml
for each menus or tabs in your website
only mention relative page, so that you can recheck in your development server.
like
(/index.xml)
for rss feed for the site and
(/posts/index.xml)
for rss feed of posts
menu in your site.
It just adds this string to the page url which is not a problem if you are in a menu like posts or about
since you mention "about", i just wanted to mention this page has the same problem. when you load the exampleSite, go to about, and click the rss link, it goes to http://localhost:1313/pages/about/index.xml - which returns 404
@gian-hancock your workaround works brilliantly. it removes the brokes RSS icon for my custom content pages, as well as the single post pages, but keeps it on /posts/ and on / , which is the exact behavior i expected.
1. Introduction
Thank you @Dieterbe, @madshckd & @gian-hancock for your valuable contributions.
In socialIcons.html it just sets the href to url value. when url is set to "index.xml".
@gian-hancock thank you for this observation.
2. What was the RSS link intended for?
I originally included the RSS link in the footer to provide access to the RSS feed. When I mention "the RSS feed," I'm simply referring to the page independent RSS feed located at {{ baseURL }}/index.xml
.
I thought a website would have only one RSS feed that includes content from all sections (I mean Hugo content sections).
Let's call this as the 'Unified RSS feed' approach.
3. What it was not intended for?
- to provide different RSS feed for different pages
- to provide rss feed links for separate menus
- to have feeds in a separate page
Let's call this as the 'Multiple RSS feed' approach.
Those who are interested walking this route, may implement the workarounds/modifications mentioned above. However, keep in mind that you may face some difficulties (or you may have to take some extra steps) when you try to upgrade to the latest version of the theme.
To avoid any conflicts, I suggest that you take advantage of the Hugo template override feature.
Hugo template override
Here is a simple description of the override feature for those who are unaware of it.
For example, say you wish to add some HTML code to the navigation bar.
- Copy the relevant file
themes/hugo-blog-awesome/layouts/partials/header.html
tolayouts/partials/header.html
(at the root of your site, not inthemes/hugo-blog-awesome
), creating thelayouts/partials
folders if they do not exist. - Add the HTML code you want to your copy of the file.
This will override the theme's version.
4. What you should do now?
If you plan to use the 'Unified RSS feed' approach, which the theme supports, you don't have to do anything.
If you plan to use the 'Multiple RSS feed' approach, you can use Hugo's template override to keep your custom RSS feed template and still get theme updates.
5. Conclusion
Going forward, I want to emphasize that I'm open to exploring new ideas and suggestions to enhance the RSS feed. Please feel free to share your thoughts and recommendations (if any) in the GitHub discussion associated with this repository.
Thank you.
I just updated to 0.14.0 and this broke the previously working /index.xml and just gives a 404 link. Anything I might have missed during the upgrade?
I already changed the social icon from index.xml
to /index.xml
but no difference.
Edit: Seems like it fails to build them:
ERROR 2024/03/10 14:43:55 render of "home" failed: "/*folder*/themes/hugo-blog-awesome/layouts/_default/rss.xml:22:17": execute of template failed: template: _default/rss.xml:22:17: executing "_default/rss.xml" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2024/03/10 14:43:55 render of "taxonomy" failed: "/*folder*/themes/hugo-blog-awesome/layouts/_default/rss.xml:22:17": execute of template failed: template: _default/rss.xml:22:17: executing "_default/rss.xml" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2024/03/10 14:43:55 render of "section" failed: "/*folder*/themes/hugo-blog-awesome/layouts/_default/rss.xml:22:17": execute of template failed: template: _default/rss.xml:22:17: executing "_default/rss.xml" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2024/03/10 14:43:55 render of "taxonomy" failed: "/*folder*/themes/hugo-blog-awesome/layouts/_default/rss.xml:22:17": execute of template failed: template: _default/rss.xml:22:17: executing "_default/rss.xml" at <site>: can't evaluate field LanguageCode in type *langs.Language
Error: Error building site: failed to render pages: render of "section" failed: "/*folder*/themes/hugo-blog-awesome/layouts/_default/rss.xml:22:17": execute of template failed: template: _default/rss.xml:22:17: executing "_default/rss.xml" at <site>: can't evaluate field LanguageCode in type *langs.Language