gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.48k stars 7.5k forks source link

RSSLink not working with permalinks.posts #532

Closed msridhar closed 7 years ago

msridhar commented 10 years ago

I seem to have run into a bug with the combination of .RSSLink and use of the permalinks feature. I have the following in my config.toml:

[permalinks]
  posts = "/:year/:month/:day/:title/"

I'm using a minor variant of the standard hyde template, which contains this in its layouts/chrome/head.html file:

  <!-- RSS -->
  <link href="{{ .RSSlink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />

When I look at the HTML generated for one of my posts, however, I see:

  <link href="" rel="alternate" type="application/rss+xml" title="Transitive Closure" />

Note that the href attribute has no value. I see proper links when I use .RSSLink in the sidebar (though there I run into #467). The full blog source is here. Let me know if I can provide further details. And thanks so much for building hugo!

k4rtik commented 9 years ago

Why does it seem to be the correct behavior to me? RSSlink should be populated only for the homepage and the taxonomy list & term pages but probably not for all posts. In fact, the whole <link> tag should be removed from individual posts.

I did a bit of reading about the usecase of OP here, and if RSS <link> is really needed on each page, rel="home" should be used instead of rel="alternate", see: MDN Syndicating

msridhar commented 9 years ago

@k4rtik for me, the desired behavior is that if some reader follows a link directly to one of my posts, she should be able to easily subscribe to the RSS feed in the same manner she would use if she navigated to the main page. From your link, it does seem that rel="home" would be more appropriate for post pages.

k4rtik commented 9 years ago

I think I figured it out.

RSSlink is being populated only for main, sections and taxonomies as expected (see doc: http://gohugo.io/templates/rss/).

The correct way to solve your problem is by fixing the theme. You might want to keep the RSS section of <head> separate for your posts template and for other templates (main/section/taxonomy) OR get rid of it completely for posts (which you probably don't want as mentioned in previous comment).

This is not a hugo bug then, rather a theme bug. Please feel free to close the issue if you think it's clear now.

halostatue commented 9 years ago

There’s two different bugs here. I think you’re right that themes need to be fixed, but I also think that having .Site.RSSLink would make it easier for themes to do the right thing, e.g.:

{{ if .RSSlink }}
<link href="{{ .RSSlink }}" rel="alternate" type="application/atom+xml" title="{{ .Site.Title }}" />
{{ else if .Site.RSSlink }}
<link href="{{ .Site.RSSlink }}" rel="home" type="application/atom+xml" title="{{ .Site.Title }}" />
{{ end }}
k4rtik commented 9 years ago

That sounds like a pretty good alternative to me.

bep commented 9 years ago

node.RSSlink is a method. If the example @halostatue shows is the "correct way", the conditionals in his example should be put in that method ... will make the templates simpler to write.

halostatue commented 9 years ago

@bjornerik Except for the difference between rel="alternate" and rel="home". ;)

msridhar commented 9 years ago

I admit I'm not fully following the discussion, but I'll note that if the theme is buggy, it is also buggy in the spf13/hyde repository:

https://github.com/spf13/hyde/blob/master/layouts/partials/head.html#L23

Let me know if I should file an additional issue there, or if the issue should be there instead of here.

halostatue commented 9 years ago

@msridhar I spent some time looking at the specs that @k4rtik also looked at, and they are somewhat open for interpretation…but basically, <link rel="alternate"…> means that what is there is an alternate link for the page you’re viewing, so pointing to the site RSS feed (or a category RSS feed) as an alternate link from an individual page isn’t accurate. In that sense, pretty much every theme out there for Hugo is buggy…

…but so is pretty much every WordPress theme, etc.

So, there are two things that should be done:

  1. Hugo needs to present a .Site.RSSlink that can be used if .RSSlink is not set.
  2. Themes need to be updated to use .Site.RSSlink in the following fashion (this is a little different than I originally wrote) so that they aren’t buggy. (This also means that each taxonomy/category page will present both RSS feeds.)
{{ if .RSSlink }}
<link href="{{ .RSSlink }}" rel="alternate" type="application/atom+xml" title="{{ .Site.Title }}" />
{{ end }}
{{ if ne .RSSlink .Site.RSSlink }}
<link href="{{ .Site.RSSlink }}" rel="home" type="application/atom+xml" title="{{ .Site.Title }}" />
{{ end }}
k4rtik commented 9 years ago

I rewrote some mechanics of feed generation in Hugo today at #644, there were nasty bugs here and there, especially in relation to standards compliance, alternate links and placement of generated xml files themselves. Although, it doesn't address the .Site.RSSLink issue because I am unclear about how to add it, please have a look if you like.

For my website, at least, I have removed the rel=alternative link for individual posts using https://github.com/k4rtik/liquorice/commit/224cd5bee2eafa793742f97e474f14522470fc12

BTW, @halostatue the MIME type in your examples should be application/rss+xml if we are using RSS 2.0, isn't it?

halostatue commented 9 years ago

You’re right that it should be application/rss+xml, but as you said in #644, we should switch the internal RSS template to an actual Atom template.

I’ll look at your code in that PR a bit later.

bep commented 9 years ago

The stakeholders of this bugg: What is status?

k4rtik commented 9 years ago

As far as my understanding goes, this should not be an issue anymore. Feedly can successfully find the feed in all kinds of pages on my site. I am on v0.14. But then I had hacked/corrected my theme as mentioned earlier.

Perhaps @msridhar might be able to say for sure about the specific problem he described.

msridhar commented 9 years ago

@k4rtik What exactly is the theme fix? With hugo 0.14 and the fix in this comment I get an error that .Site.RSSLink is not defined.

k4rtik commented 9 years ago

@msridhar it is to not expose alternate link for individual blog posts or pages.

Please see: https://github.com/k4rtik/liquorice/commit/224cd5bee2eafa793742f97e474f14522470fc12 for what I did in my case. This ensures that feed is served only for those pages for which Hugo provides a RSS link (homepage, sections, category/tags pages, etc.)

msridhar commented 9 years ago

@k4rtik with this change will Feedly still find a feed on pages for individual posts?

msridhar commented 9 years ago

More specifically, I'd still like the "Subscribe" button that one can enable in Firefox to work on individual post pages. I think that looks for a <link> element giving the URL of the feed.

k4rtik commented 9 years ago

@msridhar I am not sure how Feedly discovers a feed exactly, but on my individual posts I see the icon active though the alternate link is not there if I look up the source of the page.

Why don't you try it out once?

msridhar commented 9 years ago

I checked, and Firefox's RSS Subscribe button does not work on individual posts with the equivalent of k4rtik/liquorice@224cd5b enabled. @k4rtik I went to the site linked from your GitHub profile, and I don't see the button enabled there for individual posts either (though it is enabled for the main page, as expected). When you say that you see an active Feedly icon on your individual posts, what do you mean exactly? Do you have a browser extension installed?

Disappointingly, I tried manually introducing a <link> element with rel="home" on my post pages, and the Firefox subscribe button doesn't work in that case either; I guess it is only looking for the incorrect rel="alternate" tag. I can file a separate bug with them for that issue.

Bottom line, though it may technically violate the specification, I think hugo should support some way for templates to reference the RSSLink URL on individual posts. Having rel="alternate" links on individual posts is extremely common on blogs, from what I can see. Perhaps enabling the .Site.RSSLink variable as suggested by @halostatue would be the best solution.

Also, the bug title mentions the permalinks.posts feature, but I'm now unsure if that has anything to do with this issue. If not, we can rename the issue to something more appropriate.

k4rtik commented 9 years ago

Yeah, I was talking about the Feedly Mini extension. Ideally it should also NOT detect feeds on individual pages as there aren't any <link> tags for feeds on those.

I couldn't test out myself with Firefox (don't have it installed, traveling & on a slow network connection). But yes, if it doesn't detect the feed with <link rel="home" ...>, letting them know is a good idea.

I cannot comment on other points you raised at this point.

jorinvo commented 8 years ago

Glad I found this issue. Run into the same issue. Only realized it because the RSS link was not working on sub pages. After reading this and testing, I set the <link> to rel="alternate" for all pages to support Firefox. Also, I link to {{ "index.xml" | relURL }} because I want the link to work on sub pages. Would be nice if Hugo would take care of this though.

bep commented 7 years ago

This issue has been automatically marked as stale because it has not been commented on for at least four months.

The resources of the Hugo team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, and you feel that it is still valuable, please open a proposal at https://discuss.gohugo.io/.

This issue will automatically be closed in four months if no further activity occurs. Thank you for all your contributions.

bep commented 7 years ago

Note/Update: This issue is marked as stale, and I may have said something earlier about "opening a thread on the discussion forum". Please don't.

If this is a bug and you can still reproduce this error on the latest release or the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.

bep commented 7 years ago

The behaviour here is as designed.

Now RSSLink will only return the link for pages that potentially have a RSS feed (it may be turned off, and RSSLink will still create a link in that case).

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.