website/lib/Render/Util.rakumod

38 lines
631 B
Raku
Raw Normal View History

2025-02-07 02:26:17 -05:00
use v6.e.PREVIEW;
unit module Render::Util;
2025-02-07 02:33:40 -05:00
use DB::Post;
2025-02-07 02:44:35 -05:00
use HTML::Functional;
2025-02-07 02:26:17 -05:00
sub opt($test, $item) is export {
if $test {
$item
} else {
[]
}
}
sub optl($test, &item) is export {
if $test {
item
} else {
[]
}
}
2025-02-07 02:33:40 -05:00
#| 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"
}
}
2025-02-07 02:44:35 -05:00
sub icon($icon) is export {
i(:class("bx bx-$icon"))
}