factor out post-link method

This commit is contained in:
Nathan McCarty 2025-02-07 02:33:40 -05:00
parent 68e20af5d7
commit 72bd2a238c
2 changed files with 16 additions and 14 deletions

View file

@ -1,6 +1,8 @@
use v6.e.PREVIEW;
unit module Render::Util;
use DB::Post;
sub opt($test, $item) is export {
if $test {
$item
@ -16,3 +18,14 @@ sub optl($test, &item) is export {
[]
}
}
#| 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"
}
}