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

Enable RSS for blogs? #297

Closed
utkarsh2102 opened this issue Apr 7, 2020 · 24 comments · Fixed by #316
Closed

Enable RSS for blogs? #297

utkarsh2102 opened this issue Apr 7, 2020 · 24 comments · Fixed by #316

Comments

@utkarsh2102
Copy link
Contributor

Hi @luizdepra,

Thank you for the work you've put in on this so far! This is just amazing!
What's blocking me to use this is the ability to not have the RSS feel for blogs. Or am I missing something?
I need to sync my blog posts so that they appear on planet.debian.org (or any other planet for that matter) which is linked via the RSS. Is there any way to fix this bit?

@clement-pannetier
Copy link
Contributor

clement-pannetier commented Apr 7, 2020

Hi @utkarsh2102, you have access to rss feed with the index.xml file as you can see here on @luizdepra website.

@utkarsh2102
Copy link
Contributor Author

Hi @clement-pannetier, @luizdepra,
Here's my index.xml. It doesn't seem to be showing the complete content of my blogs. Am I missing something again? Or is there something wrong?

@clement-pannetier
Copy link
Contributor

Hi @utkarsh2102, regarding the doc you can find here, the default RSS template that ships with Hugo (I don't see a file in the theme that can override the default rendering of the RSS feed) render the content like this :

<description>{{ .Summary | html }}</description>

as you can see here.
.Summary documentation : https://gohugo.io/content-management/summaries/#readout

So, I think that if you want to change this default behavior, you need to override the RSS template with you own file inside layouts/ folder.

@utkarsh2102
Copy link
Contributor Author

@clement-pannetier, hi,
I really don't have any idea on how to do that :/
Could you please help me in fixing this?
(it'd be great if you could fix this for this theme itself!?)

@utkarsh2102
Copy link
Contributor Author

I see threads like this. But I am still not sure. I'd really appreciate all your help here! <3

@utkarsh2102
Copy link
Contributor Author

Aha, another quick thingy that could work is:

  • Change <description>{{ .Summary | html }}</description> to <description>{{ .Content | html }}</description>

  • Create subdirectories in layouts/ and save the RSS template files (name them rss.xml) in them (one for each subdirectory).

Source: https://yongfu.name/2018/12/13/hugo_rss.html

Unsure how to do it though :P
(I could be stupid sometimes :))

@utkarsh2102
Copy link
Contributor Author

Lastly, I tried doing this in this commit: utkarsh2102/utkarsh2102.org@3a070ee

But the Netlify build fails, saying:

ERROR 2020/04/22 13:22:48 render of "section" failed: "/opt/build/repo/layouts/conferences/rss.xml:5:18": execute of template failed: template: conferences/rss.xml:5:18: executing "conferences/rss.xml" at <$pctx.RegularPages>: can't evaluate field RegularPages in type *hugolib.pageState

@clement-pannetier
Copy link
Contributor

Lastly, I tried doing this in this commit: utkarsh2102/utkarsh2102.com@3a070ee

But the Netlify build fails, saying:

ERROR 2020/04/22 13:22:48 render of "section" failed: "/opt/build/repo/layouts/conferences/rss.xml:5:18": execute of template failed: template: conferences/rss.xml:5:18: executing "conferences/rss.xml" at <$pctx.RegularPages>: can't evaluate field RegularPages in type *hugolib.pageState

Hi @utkarsh2102, I think that your code is ok but the hugo version you are using (0.55.4) is too old, try to update it and tell me if it fixes the problem.

I tried to add the rss.xml file inside the layouts/_default/ directory, it works but the RSS description contains HTML tags...

@clement-pannetier
Copy link
Contributor

I read the RSS specifications, the description element inside elements of "item" is meant to describe the item synopsis, not the full page content.

@utkarsh2102
Copy link
Contributor Author

Hi @clement-pannetier,

I think that your code is ok but the hugo version you are using (0.55.4) is too old, try to update it and tell me if it fixes the problem.

Woot, it indeed fixed the build. However, it doesn't fix the problem. The index.xml is still not complete.

I read the RSS specifications, the description element inside elements of "item" is meant to describe the item synopsis, not the full page content.

Aha! What's the fix then? I am sorry, I am getting clueless now.. 😭

@clement-pannetier
Copy link
Contributor

Woot, it indeed fixed the build. However, it doesn't fix the problem. The index.xml is still not complete.

What's missing ?

Aha! What's the fix then? I am sorry, I am getting clueless now.. 😭

I just say that RSS files are not meant to display the full content of a post for example, why you want to do that 🤔?

@utkarsh2102
Copy link
Contributor Author

What's missing ?

The RSS feed is incomplete. It's just showing the first few lines. Whilst it should show the entire blog post.

I just say that RSS files are not meant to display the full content of a post for example, why you want to do that?

No, that's wrong. They're meant to give you the entire content of the blog.
I have blogs synced with planet.debian.org and similarly other "planets". I ran utkarsh2102.tk which is based on Jekyll. And the feed is: utkarsh2102.tk/feed.xml which is exactly what I want.
And here's the feed.xml file: https://github.com/utkarsh2102/utkarsh2102.github.io/blob/master/feed.xml

It kinda resembles with the present rss.xml file. Could you catch something out of this or know how can I get this working?

@clement-pannetier
Copy link
Contributor

The RSS feed is incomplete. It's just showing the first few lines. Whilst it should show the entire blog post.

It works for me, I ran hugo server command with the exampleSite directory of this theme. I have all the content of the page inside the RSS description element 🤔. I tried to move the rss.xml file from layouts/_default/ to layouts/posts/, same result...

No, that's wrong. They're meant to give you the entire content of the blog.

That's not what's in the spec, but I understand why you want it to be like that.

Element Description Example
title The title of the item. Venice Film Festival Tries to Quit Sinking
link The URL of the item. http://www.nytimes.com/2002/09/07/movies/07FEST.html
description The item synopsis. Some of the most heated chatter at the Venice Film Festival this week was about the way that the arrival of the stars at the Palazzo del Cinema was being staged.
author Email address of the author of the item. More. oprah@oxygen.net
category Includes the item in one or more categories. More. Simpsons Characters
comments URL of a page for comments relating to the item. More. http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290
enclosure Describes a media object that is attached to the item. More.
guid A string that uniquely identifies the item. More. http://inessential.com/2002/09/01.php#a2
pubDate Indicates when the item was published. More. Sun, 19 May 2002 15:21:36 GMT
source The RSS channel that the item came from. More. Quotes of the Day

@utkarsh2102
Copy link
Contributor Author

It works for me, I ran hugo server command with the exampleSite directory of this theme. I have all the content of the page inside the RSS description element thinking. I tried to move the rss.xml file from layouts/_default/ to layouts/posts/, same result...

Wow! I just got it working via:
cp layouts/posts/rss.xml themes/hugo-coder/layouts/_default/ :P

By any chance d'you plan to have this here? It'd be great if you can do so! I'll be happy to raise a PR.
This way I can keep using this as a submodule. Otherwise, with local changes, the Netlify build fails since it clones the submodule separately. And when it doesn't find the things needed here, it'll fail to build.
The other "workaround" is that I use my own sub-module (a fork of this!). This would be a little unnecessary and things could be easier and super awesome if this could be merged here! :D

@clement-pannetier
Copy link
Contributor

Wow! I just got it working via:
cp layouts/posts/rss.xml themes/hugo-coder/layouts/_default/ :P

I don't know why, normally when you override the theme files in your site layouts folder, it works except if the template lookup order is wrong, but there is none .xml files in the theme layouts 🤔.

By any chance d'you plan to have this here? It'd be great if you can do so! I'll be happy to raise a PR.

@luizdepra ?

Otherwise, with local changes, the Netlify build fails since it clones the submodule separately. And when it doesn't find the things needed here, it'll fail to build.

I don't understand, it works fine on my website...

@clement-pannetier
Copy link
Contributor

I cloned your site and ran it locally, it works well as you see below (/posts/index.xml) :

image

I didn't make changes !

@utkarsh2102
Copy link
Contributor Author

I cloned your site and ran it locally, it works well as you see below (/posts/index.xml)
I didn't make changes !

Say whaaaaat!?
I have no clue how's that even possible!?

I just had to put the rss.xml file under layouts/_default and everything then works fine. Not now.
My RSS feed is literally like this: https://utkarsh2102.com/index.xml
(hosted via Netlify @master)

@clement-pannetier
Copy link
Contributor

I cloned your site and ran it locally, it works well as you see below (/posts/index.xml)
I didn't make changes !

Say whaaaaat!?
I have no clue how's that even possible!?

I just had to put the rss.xml file under layouts/_default and everything then works fine. Not now.
My RSS feed is literally like this: https://utkarsh2102.com/index.xml
(hosted via Netlify @master)

🤷‍♂️😅

@luizdepra
Copy link
Owner

I just had to put the rss.xml file under layouts/_default and everything then works fine. Not now.
My RSS feed is literally like this: https://utkarsh2102.com/index.xml
(hosted via Netlify @master)

Templates inside _dafault/ are global unless if it is overridden elsewhere. If you put your custom template inside posts/ it will affect only example.com/posts/index.xml and not example.com/index.xml, which will use the default rss.xml template provided by Hugo.

By any chance d'you plan to have this here? It'd be great if you can do so! I'll be happy to raise a PR.

I have no objections. But we should use the custom _default/rss.xml as default to also affect pages and not only posts.

@utkarsh2102
Copy link
Contributor Author

Thanks, I'll raise a PR for what I'm using (which works for others, too!) :)

@plett
Copy link
Contributor

plett commented May 11, 2020

Hi. This change away from Hugo's default behaviour (RSS feeds including full content instead of just a summary) has caught me out.

I've undone the change and put Hugo's original rss.xml in my site's layouts/_default/rss.xml - which I feel is where the original poster should have made changes to the feed output for their site.

@luizdepra Would you consider reverting the PR for this and advising @utkarsh2102 to use their site's layouts to customise their feed if they want to use a custom template?

I see that @utkarsh2102's source is at https://github.com/utkarsh2102/utkarsh2102.com , I'd happily create a PR there to add a _default/rss.xml for their site if it would be helpful.

@luizdepra
Copy link
Owner

I kinda don't like the way Hugo generates the default summary. It just cut some first sentences from the full article. But ok, I know I can provide a better summary to override the default one generate by Hugo. So, this is not Hugo's and neither RSS' fault.

Gimme a time to think about it.

@luizdepra
Copy link
Owner

luizdepra commented May 14, 2020

@plett and @utkarsh2102. I decided to revert the custom rss template.
This is simple customization that can be made in your theme forks or even in site projects.

@jdheyburn
Copy link

If anyone stumbled across this for a better RSS xml file see my project one here:
https://github.com/jdheyburn/jdheyburn.co.uk/blob/master/layouts/_default/rss.xml

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

Successfully merging a pull request may close this issue.

5 participants