Skip to main content

RSS Feed

cd /var/www/bookstack/themes/custom
mkdir templates

touch includes/rss.feed.php
touch templates/rss.blade.php

chown -R root:www-data /var/www/bookstack/themes/custom/
chmod -R 755 /var/www/bookstack/themes/custom/
  • Defining RSS feed control function. Here take(25) defines a number of pages in the feed, and created_at can be swapped for updated_at for sorting by recently updated pages
nano -w includes/rss.feed.php
<?php

use BookStack\Entities\Models\Page;
use Illuminate\Support\Facades\Route;

Route::get('/rss/pages/new', function() {
    $pages = Page::query()
        ->visible()
        ->orderBy('created_at', 'desc')
        ->take(25)
        ->get();

    return response()->view('templates/rss', ['pages' => $pages], 200, ['Content-Type' => 'text/xml']);
});
  • Defining the RSS feed page template
nano -w templates/rss.blade.php
<?xml version="1.0"?>
<rss version="2.0">
   <channel>
      <title>Latest Project Null Pages</title>
      <link>{{ url('/') }}</link>
      <description>Latest pages at Project Null</description>
      <lastBuildDate>{{ date(DATE_RSS) }}</lastBuildDate>
      @foreach($pages as $page)
        <item>
            <title>{{ $page->name }}</title>
            <link>{{ $page->getUrl() }}</link>
            <description>{{ $page->getExcerpt() }}</description>
            <pubDate>{{ $page->created_at->format(DATE_RSS) }}</pubDate>
            <guid>page#{{ $page->id }}</guid>
        </item>
      @endforeach
   </channel>
</rss>
  • Adding to the theme
nano -w functions.php
<?php

include 'includes/rss.feed.php';