diff --git a/app/controllers/blog_feed_controller.ts b/app/controllers/blog_feed_controller.ts new file mode 100644 index 0000000..9b8f421 --- /dev/null +++ b/app/controllers/blog_feed_controller.ts @@ -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, + }) + } +} diff --git a/commands/build_static.ts b/commands/build_static.ts index 53c720d..8f9ee8b 100644 --- a/commands/build_static.ts +++ b/commands/build_static.ts @@ -9,6 +9,7 @@ import type { CommandOptions } from '@adonisjs/core/types/ace' import { HttpContextFactory } from '@adonisjs/core/factories/http' import SupportProgramController from '#controllers/support_program_controller' import CaseStudiesController from '#controllers/case_studies_controller' +import BlogFeedController from '#controllers/blog_feed_controller' export default class BuildStatic extends BaseCommand { static commandName = 'build:static' @@ -47,6 +48,22 @@ export default class BuildStatic extends BaseCommand { this.logger.success('created dist/contact.html') } + /** + * Creates a static copy of the RSS feeds. + */ + protected async buildFeeds() { + const blogFeedController = new BlogFeedController() + const ctx = new HttpContextFactory().create() + await mkdir(app.makePath('dist/feeds'), { recursive: true }) + + /** + * Create blog feed + */ + const feed = await blogFeedController.handle(ctx) + await writeFile(app.makePath('dist/feeds/blog.xml'), feed) + this.logger.success('created dist/feeds/blog.xml') + } + /** * Creates a static copy of the blog listing and * individual blog posts. @@ -126,6 +143,7 @@ export default class BuildStatic extends BaseCommand { await this.buildAboutPage() await this.buildContactPage() await this.buildBlog() + await this.buildFeeds() // await this.buildCaseStudies() } } diff --git a/resources/views/components/layouts/main.edge b/resources/views/components/layouts/main.edge index e411213..190c560 100644 --- a/resources/views/components/layouts/main.edge +++ b/resources/views/components/layouts/main.edge @@ -7,6 +7,7 @@