-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add a blog posts RSS channel #425
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yceruto thanks for implementing this feature. I like most of it ... but I've suggested some minor changes.
// This is a ResponseHeaderBag that has some nice methods for getting and | ||
// setting response headers. The header names are normalized so that using | ||
// Content-Type is equivalent to content-type or even content_type. | ||
$response->headers->set('Content-Type', 'application/xhtml+xml'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this. It's great to show how this works in Symfony ... but it may look "horrible" to newcomers because they might think they always need to do that (but it's optional, because $this->render()
takes care of that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Simplified by using _format
.
@@ -0,0 +1,23 @@ | |||
{% spaceless %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just asking: why this tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for remove spaces between tags, but this detail can be ignored for simplicity
👍 Removed!
{% spaceless %} | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<rss version="2.0"> | ||
<channel> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we add these two tags to the <channel>
tag?
<pubDate>{{ 'now'|date('r') }}</pubDate>
<lastBuildDate>{{ (posts|last).publishedAt|default('now')|date('r') }}</lastBuildDate>
- pubDate: The original publication date for the channel or item. (optional)
- lastBuildDate: The most recent time the content of the channel was modified. (optional)
They are totally optional, so if you don't agree that's OK!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Added!
<description>{{ post.summary }}</description> | ||
<link>{{ url('blog_post', {'slug': post.slug}) }}</link> | ||
<guid>{{ url('blog_post', {'slug': post.slug}) }}</guid> | ||
<pubDate>{{ post.publishedAt|date(format=RSS, timezone='GMT') }}</pubDate> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I also have doubts about:
{% set RSS = constant('RSS', date()) %}
<pubDate>{{ post.publishedAt|date(format=RSS, timezone='GMT') }}</pubDate>
Why not using this?
<pubDate>{{ post.publishedAt|date('r', timezone='GMT') }}</pubDate>
Showing the Twig constants and all it's great ... but we should be careful. If newcomers see this, they'll think that Symfony is this complicated and you must do it like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, RFC822 (r
) and RSS constants have the same format. Fixed!
@@ -45,6 +45,12 @@ | |||
|
|||
{% block header_navigation_links %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also add the following to the <head>
part of the page:
<link rel="alternate" type="application/rss+xml" href="{{ path('blog_rss') }}">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Added!
* @Route("/rss.xml", name="blog_rss") | ||
* @Method("GET") | ||
*/ | ||
public function rssAction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yceruto, I think it's not needed to create a particular action. You could use the _format
parameter in the indexAction
. See http://symfony.com/doc/current/quick_tour/the_controller.html#using-formats
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Updated!
@javiereguiluz, @voronkovich Thanks for the review. I have addressed your comments. |
* @Route("/", defaults={"page": "1"}, name="blog_index") | ||
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="blog_index_paginated") | ||
* @Route("/", defaults={"page": "1", "_format"="html"}, name="blog_index") | ||
* @Route("/rss.{_format}", name="blog_rss", defaults={"page": "1", "_format"="xml"}, requirements={"_format": "xml"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide to have a different @Route
for the RSS, maybe we can hardcode some things to simplify:
@Route("/rss.xml", name="blog_rss", defaults={"page": "1", "_format"="xml"})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree! Fixed.
@@ -9,6 +9,7 @@ | |||
<meta charset="UTF-8" /> | |||
<meta name="viewport" content="width=device-width, initial-scale=1"/> | |||
<title>{% block title %}Symfony Demo application{% endblock %}</title> | |||
<link rel="alternate" type="application/rss+xml" href="{{ path('blog_rss') }}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Content-Type
that we return here is text/xml
(by default), is it a contradiction? should change this type
to text/xml
then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I don't know. It makes sense to only use text/xml
... but then, will browsers recognize that as a RSS link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to http://www.rssboard.org/rss-autodiscovery#element-link-type
The type attribute MUST contain the feed's MIME type, which is "application/rss+xml" for RSS 1.0 or RSS 2.0 feeds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@yceruto thanks for implementing this feature and for all the changes added during the review!
* @Route("/", defaults={"page": "1"}, name="blog_index") | ||
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="blog_index_paginated") | ||
* @Route("/", defaults={"page": "1", "_format"="html"}, name="blog_index") | ||
* @Route("/rss.xml", name="blog_rss", defaults={"page": "1", "_format"="xml"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we keep the order of arguments, i.e. move name="blog_rss"
to the end like in others? 😇
*/ | ||
public function indexAction($page) | ||
public function indexAction($page, $_format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still name this variable $format
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We lost then the auto Content-Type
header response specially in blog_rss
route, remember we need the special variable _format
into defaults
option to make it automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, you're right.
@yceruto thanks to the help of @iltar and @fbourigault in the Symfony Slack channel, I've managed to add a commit to your PR. The change I propose is to remove the RSS link from the header, which makes it look crowded: And instead display it in the sidebar of blog/index and blog/show: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@yceruto thanks for implementing this feature. I truly love it. Thanks! |
This PR was merged into the master branch. Discussion ---------- Add a blog posts RSS channel This try to implement a simple RSS channel accepted in #155 since Aug 2015. Knowledge that brings: * Custom XML extension to specify the format of the template (`index.xml.twig`). * How to render a simple XML file. Any suggestions would be welcome! ;) Commits ------- d7420d5 Moved the RSS link to the sidebar cc8fe6b Minor tweaks 8a02a15 add rss title to link element 4e2c7db simplify the blog_rss route definition 254632c Minor tweaks in the translation strings 8a51859 add rss channel
This try to implement a simple RSS channel accepted in #155 since Aug 2015.
Knowledge that brings:
index.xml.twig
).Any suggestions would be welcome! ;)