website/lib/Render/Util.rakumod

31 lines
548 B
Raku

use v6.e.PREVIEW;
unit module Render::Util;
use DB::Post;
sub opt($test, $item) is export {
if $test {
$item
} else {
[]
}
}
sub optl($test, &item) is export {
if $test {
item
} else {
[]
}
}
#| Link to the post by the primary slug, if there is one, linking to it by id
#| otherwise
sub post-link(Int:D $id, Post:D $post --> Str:D) is export {
my @slugs = $post.all-slugs;
if @slugs {
"/posts/by-slug/{@slugs[*-1]}.html"
} else {
"/posts/by-id/$id.html"
}
}