factor out post-link method
This commit is contained in:
parent
68e20af5d7
commit
72bd2a238c
2 changed files with 16 additions and 14 deletions
|
@ -3,6 +3,7 @@ use v6.e.PREVIEW;
|
|||
use HTML::Functional;
|
||||
|
||||
use Render::Head;
|
||||
use Render::Util;
|
||||
use DB::BlogMeta;
|
||||
use DB::Post;
|
||||
|
||||
|
@ -194,13 +195,7 @@ method generate-post(Post:D $post, BlogMeta:D $meta) {
|
|||
method generate-blurb(Int:D $id, $db) {
|
||||
my $post = $db.posts{$id};
|
||||
my $desc = $post.description;
|
||||
my @slugs = $post.all-slugs;
|
||||
# Use the primary slug if there is one, the id if there isn't
|
||||
my $link = do if @slugs.elems {
|
||||
"/posts/by-slug/{@slugs[*-1]}.html"
|
||||
} else {
|
||||
"/posts/by-id/$id.html"
|
||||
}
|
||||
my $link = post-link $id, $post;
|
||||
div :class<post-blurb>, [
|
||||
div :class<post-blurb-title>, [
|
||||
a :href($link), span [
|
||||
|
@ -272,13 +267,7 @@ method generate-archive($db) {
|
|||
method generate-tag-blurb($db, $tag, $limit?) {
|
||||
sub post-to-link($id, $post) {
|
||||
my $desc = $post.description;
|
||||
my @slugs = $post.all-slugs;
|
||||
# Use the primary slug if there is one, the id if there isn't
|
||||
my $link = do if @slugs.elems {
|
||||
"/posts/by-slug/{@slugs[*-1]}.html"
|
||||
} else {
|
||||
"/posts/by-id/$id.html"
|
||||
}
|
||||
my $link = post-link $id, $post;
|
||||
div :class<tag-blurb-post>, [
|
||||
div :class<tag-blurb-post-title>, [
|
||||
a :href($link), span [
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue