Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSS Feed Link is Broken on Posts #160

Closed
gian-hancock opened this issue Jan 4, 2024 · 6 comments · Fixed by #161
Closed

RSS Feed Link is Broken on Posts #160

gian-hancock opened this issue Jan 4, 2024 · 6 comments · Fixed by #161

Comments

@gian-hancock
Copy link

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:

  1. Run the provided exampleSite.
  2. Click the RSS feed link on the home page (it works)
  3. Go to any post, e.g. /posts/table-of-content/
  4. 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

@hugo-sid
Copy link
Owner

hugo-sid commented Jan 5, 2024

Thanks @gian-hancock for reporting this issue.

I will have a look at it when I get some time.

@madshckd
Copy link

madshckd commented Jan 6, 2024

@gian-hancock @hugo-sid

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.

@Dieterbe
Copy link
Contributor

Dieterbe commented Feb 17, 2024

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.

@hugo-sid
Copy link
Owner

hugo-sid commented Mar 7, 2024

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 to layouts/partials/header.html (at the root of your site, not in themes/hugo-blog-awesome), creating the layouts/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.

@poVoq
Copy link
Contributor

poVoq commented Mar 10, 2024

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

@hugo-sid
Copy link
Owner

@poVoq since this issue is closed, I suggest we start a fresh discussion. I have created this :#176 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

5 participants