diff --git a/guestbook-ng.pl b/guestbook-ng.pl index 279e659..9b16f26 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -34,6 +34,14 @@ helper message => sub { }; # Routes +under sub ($c) { + # Opt out of Google FLoC + # https://paramdeo.com/blog/opting-your-website-out-of-googles-floc-network + $c->res->headers->header('Permissions-Policy', 'interest-cohort=()'); + + 1; +}; + get '/' => sub ($c) { my $posts = $c->message->get_posts(); my $last_page = $c->message->get_last_page(@$posts); @@ -53,8 +61,9 @@ any '/sign' => sub ($c) { if ($c->req->method() eq 'POST') { my $name = $c->param('name'); my $message = $c->param('message'); + my $answer = $c->param('answer'); - $c->message->send_post($name, $message); + $c->message->send_post($name, $message) if $answer; $c->redirect_to('index'); } else { diff --git a/lib/GuestbookNg/Model/Message.pm b/lib/GuestbookNg/Model/Message.pm index b664ab9..e0d9f27 100644 --- a/lib/GuestbookNg/Model/Message.pm +++ b/lib/GuestbookNg/Model/Message.pm @@ -36,7 +36,13 @@ sub max_posts($self, $value = undef) { } sub get_last_page($self, @posts) { - sprintf('%d', scalar(@posts) / $self->{'max_posts'}) + 1 + # Add a page if we have "remainder" posts + if (scalar(@posts) % $self->{'max_posts'}) { + sprintf('%d', scalar(@posts) / $self->{'max_posts'}) + 1 + } + else { + sprintf('%d', scalar(@posts) / $self->{'max_posts'}) + } } 1; diff --git a/templates/sign.html.ep b/templates/sign.html.ep index e6152c2..fadbb17 100644 --- a/templates/sign.html.ep +++ b/templates/sign.html.ep @@ -11,6 +11,27 @@