Compare commits

..

No commits in common. "main" and "template_cleanup" have entirely different histories.

24 changed files with 60 additions and 317 deletions

View File

@ -5,6 +5,7 @@ WORKDIR /opt
COPY lib/ ./lib/
COPY migrations/ ./migrations/
COPY public/ ./public/
COPY t/ ./t/
COPY templates/ ./templates/
COPY script/ ./script/
COPY cpanfile .

View File

@ -61,7 +61,8 @@ tests locally:
## TODOs
- Do I need `SUM` for `by_id()`?
- Figure out why `filter_text` is set to `0` and document that?
- Stop working on this and start the imageboard
## AGPL-3.0+ANTIFA compliance

View File

@ -7,4 +7,3 @@ requires 'XML::RSS';
requires 'Text::Markdown';
requires 'HTML::Restrict';
requires 'Roman::Unicode';
requires 'SlapbirdAPM::Agent::Mojo', '>= 0.012';

View File

@ -4,10 +4,7 @@
remarks_per_page => 5,
results_per_page => 5,
body_max_length => 8_000,
version => 'Feb 11 2025',
secrets => ['t0p_s3cr3t'],
version => 'cool version string here',
slapbirdapm_api_key => 'AyyLmao39b4eb99de26d437633e49555',
development => {
pg_string =>
'postgresql://post_text:t0p_s3cr3t@127.0.0.1/post_text'

View File

@ -19,12 +19,6 @@ sub startup($self) {
$self->plugin('Config');
$self->plugin('TagHelpers::Pagination');
# Alpha testing Slapbird APM
if (my $slapbirdapm_api_key = $self->config->{'slapbirdapm_api_key'}) {
$self->plugin('SlapbirdAPM', key => $slapbirdapm_api_key)
if $self->mode eq 'production'
}
# Helpers
$self->helper(pg => sub ($c) {
state $pg = Mojo::Pg->new($c->config->{$self->mode}{'pg_string'})
@ -36,8 +30,6 @@ sub startup($self) {
$self->helper(hr => sub ($c) {
state $hr = HTML::Restrict->new(
# filter_text breaks greater and less than symbols in Markdown code blocks
# Also breaks Markdown quote blocks
filter_text => 0,
strip_enclosed_content => [],
rules => {
@ -97,7 +89,7 @@ sub startup($self) {
# Finish configuring some things
$self->secrets($self->config->{'secrets'}) || die $@;
$self->pg->migrations->from_dir('migrations')->migrate(16);
$self->pg->migrations->from_dir('migrations')->migrate(15);
if (my $threads_per_page = $self->config->{'threads_per_page'}) {
$self->thread->per_page($threads_per_page)
@ -146,14 +138,7 @@ sub startup($self) {
$c->session(expires => 1);
$c->redirect_to('threads_list');
})->name('new_session');
# Hide a version string to check build later
if (my $version = $self->config->{'version'}) {
$r->get('/version', sub ($c) {
$c->render(text => $version . "\n")
})->name('version_string');
}
});
# Static pages
$r->get('/about')->to('page#about')->name('about_page');

View File

@ -35,8 +35,7 @@ sub create($self) {
$v->required('author' )->size(1, 63);
$v->required('body' )->size(2, $body_limit);
$v->optional('bump' );
$v->optional('preview' );
$v->optional('markdown');
$v->optional('preview');
$v->csrf_protect;
if ($v->has_error('csrf_token')) {
@ -52,8 +51,7 @@ sub create($self) {
my $remark_author = $v->param('author' );
my $remark_body = $v->param('body' );
my $bump_thread = $v->param('bump' );
my $preview = $v->param('preview' );
my $markdown = $v->param('markdown');
my $preview = $v->param('preview');
$self->session(author => $remark_author);
@ -61,8 +59,7 @@ sub create($self) {
$self->remark->create(
$thread_id,
$remark_author,
$remark_body,
$markdown
$remark_body
);
$self->thread->bump($thread_id) if $bump_thread;
@ -73,7 +70,7 @@ sub create($self) {
})->fragment('remarks'));
}
$draft = {body => $remark_body, markdown => $markdown};
$draft = $remark_body;
}
}

View File

@ -14,8 +14,7 @@ sub create($self) {
$v->required('author' )->size(1, 63);
$v->required('title' )->size(1, 127);
$v->required('body' )->size(2, $body_limit);
$v->optional('preview' );
$v->optional('markdown');
$v->optional('preview');
$v->csrf_protect;
if ($v->has_error('csrf_token')) {
@ -31,8 +30,7 @@ sub create($self) {
my $thread_author = $v->param('author' );
my $thread_title = $v->param('title' );
my $thread_body = $v->param('body' );
my $preview = $v->param('preview' );
my $markdown = $v->param('markdown');
my $preview = $v->param('preview');
$self->session(author => $thread_author);
@ -40,8 +38,7 @@ sub create($self) {
my $new_thread_id = $self->thread->create(
$thread_author,
$thread_title,
$thread_body,
$markdown
$thread_body
);
return $self->redirect_to(
@ -49,7 +46,7 @@ sub create($self) {
);
}
$draft = {body => $thread_body, markdown => $markdown};
$draft = $thread_body;
}
}

View File

@ -238,8 +238,7 @@ sub thread_by_id($self, $thread_id) {
t.thread_title AS title,
t.thread_body AS body,
COUNT(r.*) AS remark_tally,
t.bump_tally AS bump_tally,
t.markdown_status AS markdown
t.bump_tally AS bump_tally
FROM threads AS t
LEFT JOIN remarks AS r
ON t.thread_id = r.thread_id
@ -256,8 +255,7 @@ sub remark_by_id($self, $remark_id) {
TO_CHAR(remark_date, ?) AS date,
remark_author AS author,
remark_body AS body,
thread_id,
markdown_status AS markdown
thread_id
FROM remarks
WHERE remark_id = ?;
END_SQL

View File

@ -18,8 +18,7 @@ sub by_page_for($self, $thread_id, $this_page = 1) {
SELECT remark_id AS id,
TO_CHAR(remark_date, ?) AS date,
remark_author AS author,
remark_body AS body,
markdown_status AS markdown
remark_body AS body
FROM remarks
WHERE thread_id = ?
AND NOT hidden_status
@ -28,25 +27,9 @@ sub by_page_for($self, $thread_id, $this_page = 1) {
END_SQL
}
sub create(
$self,
$thread_id,
$author,
$body,
$markdown //= 0,
$hidden = 0,
$flagged = 0
)
{
sub create($self, $thread_id, $author, $body, $hidden = 0, $flagged = 0) {
my $clean_body = $self->hr->process($body);
my @data = (
$thread_id,
$author,
$clean_body,
$hidden,
$flagged,
$markdown
);
my @data = ($thread_id, $author, $clean_body, $hidden, $flagged);
$self->pg->db->query(<<~'END_SQL', @data);
INSERT INTO remarks (
@ -54,10 +37,9 @@ sub create(
remark_author,
remark_body,
hidden_status,
flagged_status,
markdown_status
flagged_status
)
VALUES (?, ?, ?, ?, ?, ?);
VALUES (?, ?, ?, ?, ?);
END_SQL
}
@ -87,8 +69,7 @@ sub last_for($self, $thread_id) {
SELECT remark_id AS id,
TO_CHAR(remark_date, ?) AS date,
remark_author AS author,
remark_body AS body,
markdown_status AS markdown
remark_body AS body
FROM remarks
WHERE thread_id = ?
ORDER BY remark_date
@ -104,8 +85,7 @@ sub by_id($self, $remark_id) {
TO_CHAR(remark_date, ?) AS date,
remark_author AS author,
remark_body AS body,
thread_id,
markdown_status AS markdown
thread_id
FROM remarks
WHERE remark_id = ?
AND NOT hidden_status;
@ -142,8 +122,7 @@ sub feed($self) {
$self->pg->db->query(<<~'END_SQL', $date_format)->hashes;
SELECT remark_id AS id,
TO_CHAR(remark_date, ?) AS date,
remark_body AS body,
markdown_status AS markdown
remark_body AS body
FROM remarks
WHERE NOT hidden_status
GROUP BY remark_id

View File

@ -8,25 +8,9 @@ has per_page => 5;
has date_format => 'Dy, FMDD Mon YYYY HH24:MI:SS TZHTZM';
sub create(
$self,
$author,
$title,
$body,
$markdown //= 0,
$hidden = 0,
$flagged = 0
)
{
sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
my $clean_body = $self->hr->process($body);
my @data = (
$author,
$title,
$clean_body,
$hidden,
$flagged,
$markdown
);
my @data = ($author, $title, $clean_body, $hidden, $flagged);
$self->pg->db->query(<<~'END_SQL', @data)->hash->{'thread_id'};
INSERT INTO threads (
@ -34,10 +18,9 @@ sub create(
thread_title,
thread_body,
hidden_status,
flagged_status,
markdown_status
flagged_status
)
VALUES (?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?)
RETURNING thread_id;
END_SQL
# The indented heredoc got a little confused by this one...
@ -60,8 +43,7 @@ sub by_page($self, $this_page = 1) {
THEN 1
ELSE 0
END) AS remark_tally,
t.bump_tally AS bump_tally,
t.markdown_status AS markdown
t.bump_tally AS bump_tally
FROM threads AS t
LEFT JOIN remarks AS r
ON t.thread_id = r.thread_id
@ -105,8 +87,7 @@ sub by_id($self, $thread_id) {
t.thread_title AS title,
t.thread_body AS body,
COUNT(r.*) AS remark_tally,
t.bump_tally AS bump_tally,
t.markdown_status AS markdown
t.bump_tally AS bump_tally
FROM threads AS t
LEFT JOIN remarks AS r
ON t.thread_id = r.thread_id
@ -140,8 +121,7 @@ sub feed($self) {
SELECT thread_id AS id,
TO_CHAR(thread_date, ?) AS date,
thread_title AS title,
thread_body AS body,
markdown_status AS markdown
thread_body AS body
FROM threads
WHERE NOT hidden_status
GROUP BY thread_id

View File

@ -1,5 +0,0 @@
ALTER TABLE threads
DROP COLUMN markdown_status;
ALTER TABLE remarks
DROP COLUMN markdown_status;

View File

@ -1,22 +0,0 @@
ALTER TABLE threads
ADD COLUMN markdown_status BOOLEAN;
-- Since Markdown was default, set existing threads to true
UPDATE threads
SET markdown_status = TRUE;
-- Now we can make it NOT NULL
ALTER TABLE threads
ALTER COLUMN markdown_status
SET NOT NULL;
-- Do the same for remarks
ALTER TABLE remarks
ADD COLUMN markdown_status BOOLEAN;
UPDATE remarks
SET markdown_status = TRUE;
ALTER TABLE remarks
ALTER COLUMN markdown_status
SET NOT NULL;

View File

@ -27,7 +27,6 @@
}
body {
background-color: black;
background-image: url('/images/background_stars_anm.gif');
width: 95vmin;
margin: 0 auto;

View File

@ -130,9 +130,3 @@
padding: 1em;
background-color: var(--transparent);
}
.plain-text {
white-space: pre-wrap;
display: inline-block;
margin: 1em 0;
}

View File

@ -1,98 +0,0 @@
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('PostText');
# For CAPTCHA
my %good_captcha = (answer => 1, number => '');
my $bump_thread_url =
'/captcha/H4sIAImTzmQAA8soKSmw0tfPyU9OzMnILy6xMjYwMNDPKM1NzNMvyShKTUzRTyrNLdA3BAD5ek7T%0AKQAAAA==%0A';
my %markdown_thread = (
author => 'Anonymous',
title => 'hi',
body => '# ayy... lmao',
preview => 1,
markdown => 1
);
my %markdown_remark = (
author => 'Anonymous',
body => '# ayy... lmao',
preview => 1,
markdown => 1
);
my %plain_text_thread = (
author => 'Anonymous',
title => 'hi',
body => '# ayy... lmao',
preview => 1
);
my %plain_text_remark = (
author => 'Anonymous',
body => '# ayy... lmao',
preview => 1
);
# Do CAPTCHA
$t->get_ok($bump_thread_url);
$good_captcha{'csrf_token'} =
$t->tx->res->dom->at('input[name="csrf_token"]')->val;
$t->post_ok($bump_thread_url, form => \%good_captcha)
->status_is(302)
->header_like(Location => qr{human/thread/bump/1});
subtest 'Check the form + button', sub {
$t->get_ok('/human/remark/post/1')->status_is(200)
->element_exists('input[id="markdown"]');
$t->get_ok('/human/thread/post')->status_is(200)
->element_exists('input[id="markdown"]');
};
subtest 'Submit markdown input', sub {
$t->get_ok('/human/remark/post/1');
$markdown_remark{'csrf_token'} =
$t->tx->res->dom->at('input[name="csrf_token"]')->val;
$t->post_ok('/human/remark/post/1', form => \%markdown_remark)
->status_is(200)
->text_like('div.form-preview h1', qr/ayy\.\.\. lmao/);
$t->get_ok('/human/thread/post');
$markdown_thread{'csrf_token'} =
$t->tx->res->dom->at('input[name="csrf_token"]')->val;
$t->post_ok('/human/thread/post', form => \%markdown_thread)
->status_is(200)
->text_like('div.form-preview h1', qr/ayy\.\.\. lmao/);
};
subtest 'Submit plain text input', sub {
$t->get_ok('/human/remark/post/1');
$plain_text_remark{'csrf_token'} =
$t->tx->res->dom->at('input[name="csrf_token"]')->val;
$t->post_ok('/human/remark/post/1', form => \%plain_text_remark)
->status_is(200)
->text_like('span.plain-text', qr/# ayy\.\.\. lmao/);
$t->get_ok('/human/thread/post');
$plain_text_thread{'csrf_token'} =
$t->tx->res->dom->at('input[name="csrf_token"]')->val;
$t->post_ok('/human/thread/post', form => \%plain_text_thread)
->status_is(200)
->text_like('span.plain-text', qr/# ayy\.\.\. lmao/);
};
done_testing;

View File

@ -13,15 +13,13 @@ my %preview_thread = (
author => 'Anonymous',
title => 'hi',
body => 'ayy... lmao',
preview => 1,
markdown => 1
preview => 1
);
my %preview_remark = (
author => 'Anonymous',
body => 'ayy... lmao',
preview => 1,
markdown => 1
preview => 1
);
# Do CAPTCHA

View File

@ -93,9 +93,6 @@
<%= content =%>
<footer class="site-footer">
<p>In UTF-8 we trust. 🫡</p>
<p><%= link_to new_session => begin %>
New Session/Identity
<% end %></p>
<p><%= link_to javascript_page =>
('data-jslicense', 1),
begin %>JavaScript License Information<% end %></p>

View File

@ -10,11 +10,7 @@
</h4>
<h5 class="post__author"><%= $remark->{'author'} %></h5>
<div class="post__body">
<% if ($remark->{'markdown'}) { =%>
<%== markdown $remark->{'body'} =%>
<% } else { =%>
<span class="plain-text"><%= $remark->{'body'} %></span>
<% } =%>
</div>
<nav class="post__nav">
<%= link_to Hide => hide_remark => {remark_id => $remark->{'id'}},

View File

@ -11,11 +11,7 @@
<h4 class="post__date"><%= $thread->{'date'} %></h4>
<h5 class="post__author"><%= $thread->{'author'} %></h5>
<div class="post__body">
<% if ($thread->{'markdown'}) { =%>
<%== markdown $thread->{'body'} =%>
<% } else { =%>
<span class="plain-text"><%= $thread->{'body'} %></span>
<% } =%>
</div>
<nav class="post__nav">
<%= link_to Hide => hide_thread => {thread_id => $thread->{'id'}},

View File

@ -25,11 +25,7 @@
</h4>
<h5 class="post__author"><%= $remark->{'author'} %></h5>
<div class="post__body">
<% if ($remark->{'markdown'}) { =%>
<%== markdown $remark->{'body'} =%>
<% } else { =%>
<span class="plain-text"><%= $remark->{'body'} %></span>
<% } =%>
</div>
<nav class="post__nav">
<%= link_to Thread => single_thread =>

View File

@ -14,13 +14,9 @@
content="Remark on thread #<%= $thread->{'id'} %>.">
<% end %>
<form method="post" class="form-body">
<% if (keys %{$draft}) { =%>
<% if ($draft) { =%>
<div class="form-preview">
<% if ($draft->{'markdown'}) { =%>
<%== markdown $draft->{'body'} =%>
<% } else { =%>
<span class="plain-text"><%= $draft->{'body'} =%></span>
<% } =%>
<%== markdown $draft =%>
</div>
<% } =%>
<div class="form-field">
@ -55,10 +51,6 @@
<%= check_box bump => 1, id => 'bump', checked => undef %>
<%= label_for bump => 'Bump' %>
</div>
<div class="form-checkbox">
<%= check_box markdown => 1, id => 'markdown' %>
<%= label_for markdown => 'Markdown' %>
</div>
<div class="form-checkbox">
<%= check_box preview => 1, id => 'preview' %>
<%= label_for preview => 'Preview' %>
@ -80,11 +72,7 @@
</h4>
<h5 class="post__author"><%= $last_remark->{'author'} %></h5>
<div class="post__body">
<% if ($last_remark->{'markdown'}) { =%>
<%== markdown $last_remark->{'body'} =%>
<% } else { =%>
<span class="plain-text"><%= $last_remark->{'body'} %></span>
<% } =%>
</div>
<nav class="post__nav">
<%= link_to Thread => single_thread =>
@ -110,11 +98,7 @@
<h4 class="post__date"><%= $thread->{'date'} %></h4>
<h5 class="post__author"><%= $thread->{'author'} %></h5>
<div class="post__body">
<% if ($thread->{'markdown'}) { =%>
<%== markdown $thread->{'body'} =%>
<% } else { =%>
<span class="plain-text"><%= $thread->{'body'} %></span>
<% } =%>
</div>
<nav class="post__nav">
<%= link_to post_remark => {thread_id => $thread->{'id'}},

View File

@ -24,11 +24,7 @@
<h4 class="post__date"><%= $thread->{'date'} %></h4>
<h5 class="post__author"><%= $thread->{'author'} %></h5>
<div class="post__body">
<% if ($thread->{'markdown'}) { =%>
<%== markdown $thread->{'body'} =%>
<% } else { =%>
<span class="plain-text"><%= $thread->{'body'} %></span>
<% } =%>
</div>
<nav class="post__nav">
<%= link_to post_remark => {thread_id => $thread->{'id'}},
@ -59,11 +55,7 @@
</h4>
<h5 class="post__author"><%= $remark->{'author'} %></h5>
<div class="post__body">
<% if ($remark->{'markdown'}) { =%>
<%== markdown $remark->{'body'} =%>
<% } else { =%>
<span class="plain-text"><%= $remark->{'body'} %></span>
<% } =%>
</div>
<nav class="post__nav">
<%= link_to Remark => post_remark =>

View File

@ -28,19 +28,11 @@
<summary>
<%= truncate_text $thread->{'body'} %>
</summary>
<% if ($thread->{'markdown'}) { =%>
<%== markdown $thread->{'body'} =%>
<% } else { =%>
<span class="plain-text"><%= $thread->{'body'} %></span>
<% } =%>
</details>
<% } else { =%>
<div class="post__body">
<% if ($thread->{'markdown'}) { =%>
<%== markdown $thread->{'body'} =%>
<% } else { =%>
<span class="plain-text"><%= $thread->{'body'} %></span>
<% } =%>
</div>
<% } =%>
<nav class="post__nav">

View File

@ -11,15 +11,9 @@
% end
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<% if (keys %{$draft}) { =%>
<% if ($draft) { =%>
<div class="form-preview">
<% if ($draft->{'markdown'}) { =%>
<%== markdown $draft->{'body'} =%>
<% } else { =%>
<span class="plain-text">
<%= $draft->{'body'} =%>
</span>
<% } =%>
<%== markdown $draft =%>
</div>
<% } =%>
<div class="form-field">
@ -63,10 +57,6 @@
rows => 6
) %>
</div>
<div class="form-checkbox">
<%= check_box markdown => 1, id => 'markdown' %>
<%= label_for markdown => 'Markdown' %>
</div>
<div class="form-checkbox">
<%= check_box preview => 1, id => 'preview' %>
<%= label_for preview => 'Preview' %>