Implement RSS feed

This commit is contained in:
swag 2023-04-24 14:25:32 -04:00
parent 5f030d5e6b
commit ebfad34e2f
6 changed files with 48 additions and 19 deletions

View File

@ -39,7 +39,6 @@ Run the tests locally (against development environment):
### (Lord knows there's TODOs I could be working on...) ### (Lord knows there's TODOs I could be working on...)
1. RSS feed!!
1. Support at least some Markdown, specifically the code blocks 1. Support at least some Markdown, specifically the code blocks
1. Implement tripcodes (moving this down in priority due to complexity...) 1. Implement tripcodes (moving this down in priority due to complexity...)
1. Return a text response instead of HTML if a `.txt` extension [is 1. Return a text response instead of HTML if a `.txt` extension [is

View File

@ -5,3 +5,5 @@ requires 'Mojolicious::Plugin::AssetPack';
requires 'Crypt::Passphrase::Argon2'; requires 'Crypt::Passphrase::Argon2';
requires 'Crypt::Passphrase::Bcrypt'; # Needed for old passphrases requires 'Crypt::Passphrase::Bcrypt'; # Needed for old passphrases
requires 'Perl::Critic::Community'; requires 'Perl::Critic::Community';
requires 'Date::Format';
requires 'XML::RSS';

View File

@ -115,7 +115,9 @@ sub startup($self) {
->to('thread#flag') ->to('thread#flag')
->name('flag_thread'); ->name('flag_thread');
#$thread->get('feed', [format => ['rss']])->to('thread#feed'); $thread->get('feed', [format => [qw{rss xml}]])
->to('thread#feed')
->name('threads_feed');
# Remark # Remark
my $remark = $r->any('/remark'); my $remark = $r->any('/remark');

View File

@ -1,7 +1,8 @@
package PostText::Controller::Thread; package PostText::Controller::Thread;
use Mojo::Base 'Mojolicious::Controller', -signatures; use Mojo::Base 'Mojolicious::Controller', -signatures;
#use XML::RSS; use Date::Format;
use XML::RSS;
sub create($self) { sub create($self) {
my $v; my $v;
@ -91,16 +92,35 @@ sub by_page($self) {
$self->render; $self->render;
} }
#sub feed($self) { sub feed($self) {
# my $threads = $self->thread->by_page(1); my $threads = $self->thread->by_page(1);
# my $rss = XML::RSS->new(version => '2.0'); my $rss = XML::RSS->new(version => '2.0');
# my $chan_link = $self->url_for(threads_list => {list_page => 1})->to_abs;
# $rss->channel(
# title => 'Post::Text', $rss->channel(
# description => 'In UTF-8 we trust. 🫡', title => 'Post::Text',
# link => $self->url_for('thread_list')->to_abs, description => 'In UTF-8 we trust. 🫡',
# ); link => $chan_link,
#} lastBuildDate => time2str('%a, %d %b %Y %X %Z', time)
);
for my $thread (@{$threads}) {
my $item_link =
$self->url_for(
single_thread => {thread_id => $thread->{'id'}}
)->to_abs;
$rss->add_item(
title => $thread->{'title'},
link => $item_link,
description => $self->truncate_text($thread->{'body'}),
author => $thread->{'author'},
pubDate => $thread->{'date'}
);
}
$self->render(text => $rss->as_string);
}
sub bump($self) { sub bump($self) {
my $thread_id = $self->param('thread_id'); my $thread_id = $self->param('thread_id');

View File

@ -38,6 +38,11 @@ subtest 'View single thread', sub {
->text_like(h2 => qr/Thread #1/); ->text_like(h2 => qr/Thread #1/);
}; };
subtest 'Threads feed', sub {
$t->get_ok('/thread/feed.rss')->status_is(200)
->content_type_is('application/rss+xml')
};
$t->ua->max_redirects(1); $t->ua->max_redirects(1);
subtest 'Post new thread', sub { subtest 'Post new thread', sub {

View File

@ -13,18 +13,19 @@
<% unless (is_mod) { =%> <% unless (is_mod) { =%>
<%= link_to Login => 'mod_login' %> <%= link_to Login => 'mod_login' %>
<% } =%> <% } =%>
<%= link_to RSS => threads_feed => {format => 'rss'} %>
</div> </div>
<div>
<% if (is_mod) { =%> <% if (is_mod) { =%>
<div>
<span>Moderate:</span> <span>Moderate:</span>
<%= link_to Flagged => 'flagged_list' %> <%= link_to Flagged => 'flagged_list' %>
<%= link_to Hidden => 'hidden_list' %> <%= link_to Hidden => 'hidden_list' %>
<%= link_to Reset => 'mod_reset' %> <%= link_to Reset => 'mod_reset' %>
<%= link_to Logout => 'mod_logout' %> <%= link_to Logout => 'mod_logout' %>
<% } =%>
</div> </div>
<div> <% } =%>
<% if (is_admin) { =%> <% if (is_admin) { =%>
<div>
<span>Admin:</span> <span>Admin:</span>
<%= link_to Create => 'create_mod' %> <%= link_to Create => 'create_mod' %>
<%= link_to Reset => 'admin_reset' %> <%= link_to Reset => 'admin_reset' %>
@ -32,8 +33,8 @@
<%= link_to Unlock => 'unlock_mod' %> <%= link_to Unlock => 'unlock_mod' %>
<%= link_to Promote => 'promote_mod' %> <%= link_to Promote => 'promote_mod' %>
<%= link_to Demote => 'demote_admin' %> <%= link_to Demote => 'demote_admin' %>
<% } =%>
</div> </div>
<% } =%>
</nav> </nav>
<hr> <hr>
<% if (flash 'error') { =%> <% if (flash 'error') { =%>