Skip to content

Commit

Permalink
Tag search and display
Browse files Browse the repository at this point in the history
  • Loading branch information
symkat committed Dec 1, 2021
1 parent c8012c3 commit adcf6a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion Web/lib/BlogDB/Web/Controller/Root.pm
Expand Up @@ -6,7 +6,17 @@ use Data::UUID;
sub get_homepage ($c) {
$c->set_template( 'index' );

push @{$c->stash->{blogs}}, $c->db->resultset('Blog')->all;
# Find blogs by tag.
if ( $c->param('tag') ) {
my $tag = $c->db->resultset('Tag')->search({ name => $c->param('tag') })->first;
if ( $tag ) {
push @{$c->stash->{blogs}}, map { $_->blog }
$tag->search_related('blog_tag_maps')->all;
}
}

push @{$c->stash->{blogs}}, $c->db->resultset('Blog')->all
unless exists $c->stash->{blogs};
push @{$c->stash->{tags_a}}, grep { $_->id % 2 == 1 } $c->db->resultset('Tag')->all;
push @{$c->stash->{tags_b}}, grep { $_->id % 2 == 0 } $c->db->resultset('Tag')->all;

Expand Down
4 changes: 2 additions & 2 deletions Web/templates/simple/_/layout.tx
Expand Up @@ -113,14 +113,14 @@
<div class="col-sm-6">
<ul class="list-unstyled mb-0">
%% for $tags_a -> $tag {
<li><a href="#!">#[% $tag.name %]</a></li>
<li><a href="[% $c.url_for('homepage').query( 'tag', $tag.name ) %]">#[% $tag.name %]</a></li>
%% }
</ul>
</div>
<div class="col-sm-6">
<ul class="list-unstyled mb-0">
%% for $tags_b -> $tag {
<li><a href="#!">#[% $tag.name %]</a></li>
<li><a href="[% $c.url_for('homepage').query( 'tag', $tag.name ) %]">#[% $tag.name %]</a></li>
%% }
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion Web/templates/simple/blog/item.html.tx
Expand Up @@ -28,7 +28,7 @@
<h1 class="fw-bolder mb-1"><a class="text-decoration-none link-dark" href="[% $blog.url %]">[% $blog.title %]</a></h1>
<div class="text-muted fst-italic mb-2">[% $blog.tagline %]</div>
%% for $blog.tags -> $tag {
<a class="badge bg-secondary text-decoration-none link-light" href="#!">#[% $tag.name %]</a>
<a class="badge bg-secondary text-decoration-none link-light" href="[% $c.url_for('homepage').query( 'tag', $tag.name ) %]">#[% $tag.name %]</a>
%% }
</header>
<section class="mb-5">
Expand Down

0 comments on commit adcf6a2

Please sign in to comment.