Skip to content

Commit

Permalink
Random blog button and navbar cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
symkat committed Dec 1, 2021
1 parent 1f7f8e6 commit d6825ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions Web/lib/BlogDB/Web.pm
Expand Up @@ -111,6 +111,7 @@ sub startup ($self) {
$r->post ( '/blog/new/:id' )->to( 'Blog#post_edit_new_blog' )->name( 'do_edit_new_blog' ); # Update a new blog.
$auth->post( '/blog/publish/:id' )->to( 'Blog#post_publish_new_blog')->name( 'do_publish_new_blog' ); # Publish (PendingBlog -> Blog.)
$r->get ( '/blog/v/:slug' )->to( 'Blog#get_view_blog' )->name( 'view_blog' ); # View specific blog
$r->get ( '/blog/r' )->to( 'Blog#get_view_random_blog' )->name( 'view_random_blog' ); # 302 redirect the user to a random blog.
$auth->get ( '/blog/e/:slug' )->to( 'Blog#get_edit_blog' )->name( 'edit_blog' ); # View edit page
$auth->post( '/blog/e/:slug' )->to( 'Blog#post_edit_blog' )->name( 'do_edit_blog' ); # Post edits to blog
$auth->post( '/blog/follow' )->to( 'Blog#post_blog_follow' )->name( 'do_follow_blog' ); # Follow a blog
Expand Down
8 changes: 8 additions & 0 deletions Web/lib/BlogDB/Web/Controller/Blog.pm
Expand Up @@ -24,6 +24,14 @@ sub get_view_blog ($c) {
);
}

sub get_view_random_blog ( $c ) {
my @blogs = $c->db->resultset('Blog')->all;

my $blog = $blogs[int rand scalar @blogs];

$c->redirect_to( $c->url_for( 'view_blog', { slug => $blog->slug }));
}

sub get_edit_blog ($c) {
$c->set_template( 'blog/edit' );

Expand Down
9 changes: 5 additions & 4 deletions Web/templates/simple/_/layout.tx
Expand Up @@ -19,13 +19,14 @@
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item"><a class="nav-link" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="[% $c.url_for('register') %]">Register</a></li>
%% if ( $person ) {
<li class="nav-item"><a class="nav-link" href="[% $c.url_for('tags') %]">Tags Manager</a></li>
%% }
%% } else {
<li class="nav-item"><a class="nav-link" aria-current="page" href="[% $c.url_for( 'homepage' ) %]">Home</a></li>
<li class="nav-item"><a class="nav-link" href="[% $c.url_for('register') %]">Register</a></li>
<li class="nav-item"><a class="nav-link" href="#!">Contact</a></li>
<li class="nav-item"><a class="nav-link active" aria-current="page" href="#">Blog</a></li>
%% }
<li class="nav-item"><a class="nav-link active" href="[% $c.url_for( 'view_random_blog' ) %]">Random Blog Button</a></li>
</ul>
</div>
</div>
Expand Down

0 comments on commit d6825ee

Please sign in to comment.