Implement RSS feed
This commit is contained in:
parent
5f030d5e6b
commit
ebfad34e2f
|
@ -39,7 +39,6 @@ Run the tests locally (against development environment):
|
|||
|
||||
### (Lord knows there's TODOs I could be working on...)
|
||||
|
||||
1. RSS feed!!
|
||||
1. Support at least some Markdown, specifically the code blocks
|
||||
1. Implement tripcodes (moving this down in priority due to complexity...)
|
||||
1. Return a text response instead of HTML if a `.txt` extension [is
|
||||
|
|
2
cpanfile
2
cpanfile
|
@ -5,3 +5,5 @@ requires 'Mojolicious::Plugin::AssetPack';
|
|||
requires 'Crypt::Passphrase::Argon2';
|
||||
requires 'Crypt::Passphrase::Bcrypt'; # Needed for old passphrases
|
||||
requires 'Perl::Critic::Community';
|
||||
requires 'Date::Format';
|
||||
requires 'XML::RSS';
|
||||
|
|
|
@ -115,7 +115,9 @@ sub startup($self) {
|
|||
->to('thread#flag')
|
||||
->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
|
||||
my $remark = $r->any('/remark');
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package PostText::Controller::Thread;
|
||||
|
||||
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||
#use XML::RSS;
|
||||
use Date::Format;
|
||||
use XML::RSS;
|
||||
|
||||
sub create($self) {
|
||||
my $v;
|
||||
|
@ -91,16 +92,35 @@ sub by_page($self) {
|
|||
$self->render;
|
||||
}
|
||||
|
||||
#sub feed($self) {
|
||||
# my $threads = $self->thread->by_page(1);
|
||||
# my $rss = XML::RSS->new(version => '2.0');
|
||||
#
|
||||
# $rss->channel(
|
||||
# title => 'Post::Text',
|
||||
# description => 'In UTF-8 we trust. 🫡',
|
||||
# link => $self->url_for('thread_list')->to_abs,
|
||||
# );
|
||||
#}
|
||||
sub feed($self) {
|
||||
my $threads = $self->thread->by_page(1);
|
||||
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',
|
||||
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) {
|
||||
my $thread_id = $self->param('thread_id');
|
||||
|
|
|
@ -38,6 +38,11 @@ subtest 'View single thread', sub {
|
|||
->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);
|
||||
|
||||
subtest 'Post new thread', sub {
|
||||
|
|
|
@ -8,23 +8,24 @@
|
|||
<h1>Post::Text</h1>
|
||||
<nav>
|
||||
<div>
|
||||
<%= link_to List => threads_list => {list_page => 1} %>
|
||||
<%= link_to New => 'post_thread' %>
|
||||
<%= link_to List => threads_list => {list_page => 1} %>
|
||||
<%= link_to New => 'post_thread' %>
|
||||
<% unless (is_mod) { =%>
|
||||
<%= link_to Login => 'mod_login' %>
|
||||
<% } =%>
|
||||
<%= link_to RSS => threads_feed => {format => 'rss'} %>
|
||||
</div>
|
||||
<% if (is_mod) { =%>
|
||||
<div>
|
||||
<% if (is_mod) { =%>
|
||||
<span>Moderate:</span>
|
||||
<%= link_to Flagged => 'flagged_list' %>
|
||||
<%= link_to Hidden => 'hidden_list' %>
|
||||
<%= link_to Reset => 'mod_reset' %>
|
||||
<%= link_to Logout => 'mod_logout' %>
|
||||
<% } =%>
|
||||
</div>
|
||||
<% } =%>
|
||||
<% if (is_admin) { =%>
|
||||
<div>
|
||||
<% if (is_admin) { =%>
|
||||
<span>Admin:</span>
|
||||
<%= link_to Create => 'create_mod' %>
|
||||
<%= link_to Reset => 'admin_reset' %>
|
||||
|
@ -32,8 +33,8 @@
|
|||
<%= link_to Unlock => 'unlock_mod' %>
|
||||
<%= link_to Promote => 'promote_mod' %>
|
||||
<%= link_to Demote => 'demote_admin' %>
|
||||
<% } =%>
|
||||
</div>
|
||||
<% } =%>
|
||||
</nav>
|
||||
<hr>
|
||||
<% if (flash 'error') { =%>
|
||||
|
|
Loading…
Reference in a new issue