浏览代码

fix paginator doubling and allow linking to user posts, along with reductions

George S. Baugh 4 年之前
父节点
当前提交
880fb3da99
共有 3 个文件被更改,包括 34 次插入27 次删除
  1. 4 2
      lib/Trog/DataModule.pm
  2. 26 22
      lib/Trog/Routes/HTML.pm
  3. 4 3
      www/templates/posts.tx

+ 4 - 2
lib/Trog/DataModule.pm

@@ -101,8 +101,8 @@ sub _fixup ($self, @filtered) {
             $_->{$param} =~ s/ /%20/g;
         }
 
-        #Add routing data for posts which don't have them (/posts/$id)
-        $_->{local_href} = "/posts/$_->{id}"                unless exists($_->{local_href});
+        #XXX Add routing data for posts which don't have them (/posts/$id)
+        $_->{local_href} = "/posts/$_->{id}"           unless exists($_->{local_href});
         $_->{method}     = 'GET'                       unless exists($_->{method});
         $_->{callback}   = "Trog::Routes::HTML::posts" unless exists($_->{callback});
 
@@ -249,6 +249,8 @@ sub add ($self, @posts) {
     my @to_write;
     foreach my $post (@posts) {
         $post->{id} //= UUID::Tiny::create_uuid_as_string(UUID::Tiny::UUID_V1, UUID::Tiny::UUID_NS_DNS);
+        # Generate a local_href so we can build the route correctly and not have to rely on auto-insert in _fixup() someday
+        $post->{local_href} = "/posts/$post->{id}";
         $post->{created} = time();
         my @existing_posts = $self->get( id => $post->{id} );
         if (@existing_posts) {

+ 26 - 22
lib/Trog/Routes/HTML.pm

@@ -31,6 +31,8 @@ our $rightbar      = 'rightbar.tx';
 our $leftbar       = 'leftbar.tx';
 our $footbar       = 'footbar.tx';
 
+# Note to maintainers: never ever remove backends from this list.
+# the auth => 1 is a crucial protection, even with forbidden() guards in these routes.
 our %routes = (
     default => {
         callback => \&Trog::Routes::HTML::setup,
@@ -81,8 +83,24 @@ our %routes = (
         auth     => 1,
         callback => \&Trog::Routes::HTML::themeclone,
     },
+    '/profile' => {
+        method   => 'POST',
+        auth     => 1,
+        callback => \&Trog::Routes::HTML::profile,
+    },
+    '/manual' => {
+        method => 'GET',
+        auth   => 1,
+        callback => \&Trog::Routes::HTML::manual,
+    },
+    '/lib/(.*)' => {
+        method => 'GET',
+        auth   => 1,
+        captures => ['module'],
+        callback => \&Trog::Routes::HTML::manual,
+    },
 
-    # Can also be made into posts
+    #TODO transform intoposts
     '/sitemap', => {
         method   => 'GET',
         callback => \&Trog::Routes::HTML::sitemap,
@@ -134,31 +152,11 @@ our %routes = (
         data     => { tag => ['about'] },
     },
 
-    '/posts' => {
-        method   => 'GET',
-        callback => \&Trog::Routes::HTML::posts,
-    },
-    '/profile' => {
-        method   => 'POST',
-        auth     => 1,
-        callback => \&Trog::Routes::HTML::profile,
-    },
     '/users/(.*)' => {
         method => 'GET',
         callback => \&Trog::Routes::HTML::users,
         captures => ['username'],
     },
-    '/manual' => {
-        method => 'GET',
-        auth   => 1,
-        callback => \&Trog::Routes::HTML::manual,
-    },
-    '/lib/(.*)' => {
-        method => 'GET',
-        auth   => 1,
-        captures => ['module'],
-        callback => \&Trog::Routes::HTML::manual,
-    },
 );
 
 #XXX these need to be fetched dynamically from all the header categories?
@@ -693,7 +691,13 @@ Implements direct user profile view.
 =cut
 
 sub users ($query, $render_cb) {
+    # Capture the username
+    my (undef, undef, $username) = split(/\//, $query->{route});
+
+    $query->{username} //= $username;
     push(@{$query->{acls}}, 'public');
+    $query->{exclude_tags} = ['about'];
+
     my @posts = _post_helper({ limit => 10000 }, ['about'], $query->{acls});
     my @user = grep { $_->{user} eq $query->{username} } @posts;
     $query->{id} = $user[0]->{id};
@@ -858,7 +862,7 @@ sub posts ($query, $render_cb, $direct=0) {
         failure   => $query->{failure},
         to        => $query->{to},
         message   => $query->{failure} ? "Failed to add post!" : "Successfully added Post as $query->{id}",
-        direct    => !!$id,
+        direct    => $direct,
         title     => $query->{title},
         style     => $query->{style},
         posts     => \@posts,

+ 4 - 3
www/templates/posts.tx

@@ -58,7 +58,7 @@
             </video>
         : } else {
             : if ($post.is_profile) {
-            <div class="square circle bigprofile preview" style="background-image:url(<: $post.preview :>)"></div>
+                <div class="square circle bigprofile preview" style="background-image:url(<: $post.preview :>)"></div>
             : } else {
             <div class="responsive preview" style="background-image:url(<: $post.preview :>)"></div>
             : }
@@ -119,6 +119,7 @@
                 <div style="background-image:url(<: $post.href :>);" class="responsive preview"></div>
             : }
             : if ( $post.is_profile ) {
+                <a href="/users/<: $post.title :>" title="<: $post.title :> poasts">
                 <div style="background-image:url(<: $post.wallpaper :>);" class="banner profile">
                     <div style="background-image:url(<: $post.preview :>);" class="circle portrait"></div>
             : }
@@ -137,7 +138,7 @@
                 </div>
             : }
             : if( $post.is_profile ) {
-                </div><br />
+                </div></a><br />
             : }
             : if ( $can_edit ) {
             <br />
@@ -180,7 +181,7 @@
         : }
     : }
 : }
-: if ( $rss || $older ) {
+: if ( !$direct && ( $rss || $older ) ) {
 : include "paginator.tx";
 : }
 : if ( $footer ) {