Verified Commit 812af573 authored by Adam Matoušek's avatar Adam Matoušek
Browse files

generate an rss feed

parent 378373a1
......@@ -25,6 +25,7 @@ Perl modules (and which Debian packages they come from):
• File::Slurper (‹libfile-slurper-perl›)
• Date::Parse (‹libtimedate-perl›)
• File::Find::Rule (‹libfile-find-rule-perl›)
• Guard (‹libguard-perl›)
## Articles
......
......@@ -204,6 +204,14 @@ dep $(a)/archive.gib
use byproduct
add deployed-files $(out)
# RSS
for a .
out $(a)/articles.rss
dep $(a)/index
dep $(archives.$a)/perex.html
dep templates/rss.tt
cmd $(tool) mkrss
add deployed-files $(out)
# other resources
set copied-resources robots.txt favicon16.png
......
......@@ -91,6 +91,7 @@ html {
--f-serif: 'DejaVu Serif', 'Bitstream Vera Serif', 'Georgia';
--f-sans: 'DejaVu Sans', 'Bitstream Vera Sans', 'Verdana';
--f-mono: 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono';
--i-rss: url('data:image/svg+xml;utf8,<svg width="32" height="32" version="1.1" viewBox="0 0 8.4667 8.4667" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><g transform="translate(0 -161.53)"><path transform="matrix(.26458 0 0 .26458 0 161.53)" d="m3 2v5h3a19 19 0 0 1 19 19v3h5v-3a24 24 0 0 0-24-24h-3zm0 10v5h3a8.9999 8.9999 0 0 1 9 9v3h5v-3a14 14 0 0 0-14-14h-3zm3 10a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4z"/></g></svg>');
}
/* General - fonts and light theme colours */
......@@ -706,6 +707,30 @@ figure.float {
margin: auto 0;
}
a[rel~="alternate"][type="application/rss+xml"] {
font-size: 60%;
}
@supports (mask-image: url()) or (-webkit-mask-image: url()) {
a[rel~="alternate"][type="application/rss+xml"] {
font-size: 0;
visibility: hidden;
}
a[rel~="alternate"][type="application/rss+xml"]::after {
content: "";
display: inline-block;
visibility: visible;
width: 1rem;
height: 1rem;
background-color: currentColor;
-webkit-mask-image: var(--i-rss);
-webkit-mask-size: contain;
-webkit-mask-repeat: no-repeat;
mask-image: var(--i-rss);
mask-size: contain;
mask-repeat: no-repeat;
}
}
/* Small (but not tiny) size */
@media screen and (min-width: 36em) {
#sidebar > header h1 {
......
......@@ -26,7 +26,8 @@
</menu>
</nav>
<nav id=latest-articles class=extended>
<header>Poslední</header>
<header>Nové články <a href='[% root %]/articles.rss' rel=alternate
type='application/rss+xml'>[RSS]</a></header>
<menu>
[%- FOREACH a IN latest %]
<li><div><a href="[% root %]/[% a.id %]"><header>[% a.title %]</header>
......
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Adamatův blogísek</title>
<link>[% root_absolute %]/</link>
<description>Články z Adamatova blogísku</description>
<language>cs</language>
<generator>Adamatův blogískový orloj</generator>
<ttl>1440</ttl>
<atom:link href="[% root_absolute %]/articles.rss" rel="self" type="application/rss+xml" />
[%- FOR i IN items %]
<item>
<title>[% i.title_plain | xml %]</title>
<link>[% root_absolute %]/[% i.id %]/</link>
<guid>[% root_absolute %]/[% i.id %]</guid>
<pubDate>[% rfc822stamp( i.published ) %]</pubDate>
[%- IF i.category %]
<category>[% i.category %]</category>
[%- END %]
<description>[% INSERT "$i.id/perex.html" | utf8 | rsshacks | xml %]</description>
</item>
[%- END %]
</channel>
</rss>
......@@ -16,6 +16,8 @@ use Time::Piece;
use Date::Parse;
use File::Slurper qw/read_lines/;
use Encode qw/decode_utf8/;
use Guard;
use POSIX qw/locale_h/;
# Report use of this module to gib
open my $gibfh, '+<&3';
......@@ -27,9 +29,11 @@ our ($srcdir, $outdir) = @ENV{qw/SRCDIR OUTDIR/};
$srcdir //= '.';
$outdir //= '.';
our @indexfields = qw/id title category ncomments stamp banner banner_alt/;
our @indexfields = qw/id title category ncomments stamp banner banner_alt title_plain/;
our $root = $ENV{DOCUMENT_ROOT} // '';
my $root_absolute = 'https://blogisek.adamat.dev';
my $now = localtime;
our $template = Template->new({
ENCODING => 'utf8',
......@@ -40,16 +44,19 @@ our $template = Template->new({
RECURSION => 1, # for comment replies
FILTERS => {
utf8 => sub { decode_utf8( $_[0] ); },
rsshacks => \&rss_filter,
},
PRE_PROCESS => 'defs',
# COMPILE_DIR => '_tt',
# COMPILE_EXT => '.pl',
VARIABLES => {
root => $root,
root_absolute => $root_absolute,
now => $now,
datef => sub { $_[0]->ymd },
timef => sub { $_[0]->strftime( '%H.%M' ) },
isostamp => sub { $_[0]->strftime( '%FT%T%z' ) },
rfc822stamp => \&rfc822stamp,
plur => \&plural,
qotd => \&qotd,
genimgattr => \&genimgattr,
......@@ -106,6 +113,7 @@ sub load_meta($src) {
}
$h->{banner} //= '';
$h->{banner_alt} //= '';
$h->{title_plain} //= $h->{title};
return {
%$h,
};
......@@ -191,4 +199,16 @@ sub genimgattr($src, $mini=0) {
return $attrs;
}
sub rfc822stamp($t) {
my $original = setlocale( LC_TIME );
my $guard = scope_guard { setlocale( LC_TIME, $original ) };
setlocale( LC_TIME, 'C' );
return $t->strftime( '%a, %d %b %Y %T %z' );
}
sub rss_filter($s) {
$s =~ s,(\b(href)\s*=\s*['"]?)/,$1$root_absolute/,gi;
return $s;
}
1;
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use open qw/:std :encoding(utf-8)/;
use lib './tools';
use Blogisek;
my @index = load_index( '.' )
or die 'Failed to load index';
splice @index, 20;
$template->process( 'rss.tt', { items => \@index }, "articles.rss" )
or die $template->error;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment