Verified Commit 970382e3 authored by Adam Matoušek's avatar Adam Matoušek
Browse files

List newest comments in the sidebar

parent 35610bab
......@@ -103,6 +103,7 @@ use transient
out generate navigation
dep templates/nav.tt
dep index
dep _comment_index
cmd $(tool) mknav
out nav.html
......
......@@ -149,7 +149,16 @@ a:hover {
}
#navigation li {
list-style: none;
line-height: 2;
line-height: 1.6;
overflow-wrap: break-word;
}
#navigation li + li {
margin-top: 0.5em;
}
#navigation .extended li + li {
margin-top: 1em;
}
#navigation li header {
}
#navigation li small {
color: var(--c-weak);
......
......@@ -7,9 +7,24 @@
<header>Škatulky</header>
[%- INCLUDE archive a=categories %]
</nav>
<nav id=latest>
<nav id=latest-comments>
<header>Nové komentáře</header>
<menu class=extended>
[%- FOREACH c IN comments %]
<li><div><a href='[% "$root/$c.article/#comment-$c.id" %]'><header>
[% c.author %]
</header>
<small>
→&nbsp;<em>[% c.title %]</em><br>
<time datetime="[% isostamp(c.published) %]"> [%- datef(c.published) %]</time>
</small>
</a></div></li>
[%- END %]
</menu>
</nav>
<nav id=latest-articles>
<header>Poslední</header>
<menu>
<menu class=extended>
[%- FOREACH a IN latest %]
<li><div><a href="[% root %]/[% a.id %]"><header>[% a.title %]</header>
<small><time datetime="[% isostamp(a.published) %]">
......
......@@ -33,7 +33,8 @@ for my $c ( sort { $a->{stamp} <=> $b->{stamp} } map load_comment($_), @commentf
else {
push @root_comments, $c;
}
$index .= "$article\t$c->{id}\n";
$index .= join "\t", $article, @$c{qw/id stamp author/};
$index .= "\n";
$comments{$c->{id}} = $c;
}
$v{comments} = \@root_comments;
......
......@@ -8,18 +8,36 @@ use open qw/:std :encoding(utf-8)/;
use lib './tools';
use Blogisek;
use List::Util qw/min uniq/;
use File::Slurper qw/read_lines/;
use Time::Piece;
# Page index
my @index = load_index( $ARGV[0] // 'index' );
my %categories;
my %years;
my %article_titles;
foreach ( @index ) {
$categories{$_->{category}}++;
$years{$_->{published}->year}++;
$article_titles{$_->{id}} = $_->{title};
}
# Comment index
my @comment_index;
for my $l ( read_lines( "$outdir/_comment_index" ) ) {
my %record;
@record{qw/article id stamp author/} = split "\t", $l;
$record{published} = localtime $record{stamp};
$record{title} = $article_titles{$record{article}};
push @comment_index, \%record;
}
@comment_index = sort { $b->{stamp} <=> $a->{stamp} } @comment_index;
my %v = (
latest => [ @index[0 .. min(2, $#index)] ],
comments => [ @comment_index[0 .. min(2, $#comment_index)] ],
categories => [ map +{ id => $_, name => "/$_", size => $categories{$_} }, sort keys %categories ],
years => [ map +{ id => $_, name => "/$_", size => $years{$_} }, sort { $b <=> $a } keys %years ],
);
......
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