-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RSS support for Blog entries (#19)
* Add RSS support for Blog entries * Limit the number of posts in the feed * Add feeds generation to static build command * Update resources/views/feeds/blog.edge Co-authored-by: Romain Lanz <[email protected]> * Update resources/views/feeds/blog.edge Co-authored-by: Romain Lanz <[email protected]> * Update resources/views/feeds/blog.edge Co-authored-by: Romain Lanz <[email protected]> --------- Co-authored-by: Romain Lanz <[email protected]>
- Loading branch information
1 parent
2314adf
commit 2c2b2b9
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
import BlogPosts from '../collections/blog_posts.js' | ||
|
||
export default class BlogFeedController { | ||
async handle({ view, response }: HttpContext) { | ||
response.append('Content-Type', 'text/xml') | ||
|
||
const publishedBlogPosts = await new BlogPosts().published() | ||
|
||
// Only publish the most recent 20 posts | ||
const feedBlogPosts = publishedBlogPosts.slice(0, 20) | ||
|
||
return view.render('feeds/blog', { | ||
blogPosts: feedBlogPosts, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"> | ||
<channel> | ||
<title>AdonisJS Framework Blog</title> | ||
<link>https://adonisjs.com/</link> | ||
<description>All the latest AdonisJS Framework news.</description> | ||
<lastBuildDate>{{new Date()}}</lastBuildDate> | ||
<docs>https://validator.w3.org/feed/docs/rss2.html</docs> | ||
<language>en</language> | ||
<image> | ||
<title>AdonisJS Framework Blog</title> | ||
<url>https://adonisjs.com/icons/favicon-32x32.png</url> | ||
<link>https://adonisjs.com/blog</link> | ||
</image> | ||
<atom:link href="https://adonisjs.com/feeds/blog.xml" rel="self" type="application/rss+xml"/> | ||
@each(post in blogPosts) | ||
<item> | ||
<title><![CDATA[{{ post.title }}]]></title> | ||
<link>{{ route('blog.show', [post.slug]) }}</link> | ||
<guid>{{ post.slug }}</guid> | ||
<pubDate>{{ post.publishedAt }}</pubDate> | ||
<description><![CDATA[ {{{ post.contentHtml.summary }}} ]]></description> | ||
<content:encoded><![CDATA[ {{{ post.contentHtml.contents }}} ]]></content:encoded> | ||
</item> | ||
@end | ||
</channel> | ||
</rss> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters