Titles, Emojis, Greentexts, and more

FossilOrigin-Name: 7166edf7fcd136ffbda39d2f36e96832690cf978a1c5df4bb6d172f8a2e905ac
This commit is contained in:
nekobit 2022-07-31 05:59:21 +00:00
parent 849b63640c
commit 7d0de2754f
6 changed files with 76 additions and 18 deletions

View file

@ -39,6 +39,10 @@ all:
$(MAKE) make_pagescobj
$(MAKE) $(TARGET)
install_deps:
cpan HTML::Escape
cpan Template::Toolkit
make_ctmpls: $(TMPLS_C)
make_pages: $(PAGES_CMP)
make_pagesc: $(PAGES_C)
@ -103,4 +107,4 @@ clean_deps:
clean_all: clean clean_deps
.PHONY: all filec clean update clean clean_deps clean_all test
.PHONY: all filec clean update clean clean_deps clean_all test install_deps

23
dist/treebird.css vendored
View file

@ -85,10 +85,9 @@ a, a:visited, a:hover, a:active
border-radius: 3px;
}
.greentext
{
color: #00aa00;
}
.greentext { color: #00aa00; }
.bluetext { color: #0060aa; }
.yellowtext { color: #cccc00; }
/* Cleans up most of the tables */
table.ui-table td
@ -1038,6 +1037,15 @@ input[type=checkbox].hidden:not(:checked) + .reply-form
display: block;
}
.status-content .title
{
display: block;
padding: 2px 2px 7px;
margin-bottom: 7px;
font-style: italic;
border-bottom: 1px solid #cacaca;
}
.status .status-content p,
.status .status-content a
{
@ -1509,12 +1517,7 @@ p}
{
display: inline-block;
padding: 3px 0px 3px;
min-width: 35px;
}
.status-interact .statbtn-last
{
min-width: 26px;
min-width: 25px;
}
.status-interact .statbtn.view-btn

View file

@ -24,6 +24,20 @@ Run `make`. This will also clone mastodont-c, and compile both it and Treebird.
If you `fossil update` any changes, `make update` should be run after updating
## Perl dependencies
Treebird renders most of the content that you see in Perl using the Template Toolkit.
You can install it by running `make install_deps`
If that doesn't work, you can open a CPAN shell
```
perl -MCPAN -e shell
install Template::Toolkit
install HTML::Escape
```
## Installation
Run `# make install`

View file

@ -1,7 +1,8 @@
package status;
use strict;
use warnings;
use string_helpers qw( reltime_to_str );
use HTML::Escape 'escape_html';
use string_helpers qw( reltime_to_str greentextify emojify format_username );
use icons qw( get_icon visibility_to_icon );
use attachments 'generate_attachment';
use emojis 'generate_emoji';
@ -19,9 +20,16 @@ sub generate_status
prefix => '',
ssn => $ssn,
status => $status,
# Functions
icon => \&get_icon,
rel_to_str => \&reltime_to_str,
vis_to_icon => \&visibility_to_icon,
make_att => \&generate_attachment,
make_emoji => \&generate_emoji,
greentextify => \&greentextify,
emojify => \&emojify,
escape => \&escape_html,
format_username => \&format_username,
);
to_template(\%vars, \$data->{'status.tt'});
@ -40,8 +48,6 @@ sub content_status
statuses_after => $statuses_after,
# Functions
create_status => \&generate_status,
make_att => \&generate_attachment,
make_emoji => \&generate_emoji,
);

View file

@ -1,10 +1,10 @@
package string_helpers;
use strict;
use warnings;
use HTML::Escape 'escape_html';
use Exporter 'import';
our @EXPORT = qw( &reltime_to_str );
our @EXPORT = qw( reltime_to_str greentextify emojify format_username );
sub reltime_to_str
{
@ -17,3 +17,31 @@ sub reltime_to_str
return int($since / (60 * 60 * 24 * 31)) . 'mon' if $since < 60 * 60 * 24 * 365;
return int($since / (60 * 60 * 24 * 365)) . 'yr';
}
sub greentextify
{
my $text = shift;
$text =~ s/((?:^|<br\/?>| )&gt;.*?)(?:<br\/?>|$)/<span class="greentext">$1<\/span><br>/gs;
$text =~ s/((?:^|<br\/?>| )&lt;.*?)(?:<br\/?>|$)/<span class="bluetext">$1<\/span><br>/gs;
$text =~ s/((?:^|<br\/?>| )\^.*?)(?:<br\/?>|$)/<span class="yellowtext">$1<\/span><br>/gs;
$text;
}
sub emojify
{
my ($text, $emojis) = @_;
foreach my $emoji (@{$emojis})
{
my $emo = $emoji->{shortcode};
my $url = $emoji->{url};
$text =~ s/:$emo:/<img class="emoji" src="$url" loading="lazy">/gsi;
}
$text;
}
sub format_username
{
my $username = shift;
emojify escape_html($username);
}

View file

@ -8,7 +8,7 @@
</td>
<td class="status-info">
<div class="poster-stats">
<span class="username">[% status.account.display_name %]</span>
<span class="username">[% format_username(status.account.display_name) %]</span>
<a class="instance-info" href="$prefix/@[% status.account.acct %]">[% status.account.acct %]</a>
<span class="alignend">
<div class="menu-container status-visibility">
@ -56,7 +56,10 @@
</span>
[% END %]
<span class="status-content">
[% status.content %]
[% IF status.spoiler_text %]
<span class="title">[% emojify(escape(status.spoiler_text), status.emojis) %]</span>
[% END %]
[% greentextify(emojify(status.content, status.emojis)) %]
</span>
[% IF status.media_attachments %]
<div class="attachments">