瀏覽代碼

more #130: killed all the /whatever routes, yay

Now I need to update the series form & kill the backend post routes
George S. Baugh 4 年之前
父節點
當前提交
749d384850
共有 4 個文件被更改,包括 35 次插入13 次删除
  1. 9 0
      data/DUMMY-dist.json
  2. 0 2
      lib/TCMS.pm
  3. 8 1
      lib/Trog/DataModule.pm
  4. 18 10
      lib/Trog/Routes/HTML.pm

+ 9 - 0
data/DUMMY-dist.json

@@ -123,6 +123,7 @@
          "private",
          "admin"
       ],
+      "callback" : "Trog::Routes::HTML::series",
       "title" : "Administrative Posts",
       "user" : "Nobody",
       "version" : 0
@@ -195,6 +196,7 @@
          "topbar",
          "public"
       ],
+      "callback" : "Trog::Routes::HTML::series",
       "title" : "News",
       "user" : "Nobody",
       "version" : 0
@@ -213,6 +215,7 @@
          "topbar",
          "public"
       ],
+      "callback" : "Trog::Routes::HTML::series",
       "title" : "Blog",
       "user" : "Nobody",
       "version" : 0
@@ -231,6 +234,7 @@
          "topbar",
          "public"
       ],
+      "callback" : "Trog::Routes::HTML::series",
       "title" : "Images",
       "user" : "Nobody",
       "version" : 0
@@ -249,6 +253,7 @@
          "topbar",
          "public"
       ],
+      "callback" : "Trog::Routes::HTML::series",
       "title" : "Videos",
       "user" : "Nobody",
       "version" : 0
@@ -267,6 +272,7 @@
          "topbar",
          "public"
       ],
+      "callback" : "Trog::Routes::HTML::series",
       "title" : "Audio",
       "user" : "Nobody",
       "version" : 0
@@ -285,6 +291,7 @@
          "topbar",
          "public"
       ],
+      "callback" : "Trog::Routes::HTML::series",
       "title" : "Files",
       "user" : "Nobody",
       "version" : 0
@@ -303,6 +310,7 @@
          "topbar",
          "public"
       ],
+      "callback" : "Trog::Routes::HTML::series",
       "title" : "Series",
       "user" : "Nobody",
       "version" : 0
@@ -321,6 +329,7 @@
          "topbar",
          "public"
       ],
+      "callback" : "Trog::Routes::HTML::series",
       "title" : "About",
       "user" : "Nobody",
       "version" : 0

+ 0 - 2
lib/TCMS.pm

@@ -36,8 +36,6 @@ use Trog::Data;
 my $conf = Trog::Config::get();
 my $data = Trog::Data->new($conf);
 my %roots = $data->routes();
-use Data::Dumper;
-print Dumper(\%roots);
 
 my %routes = %Trog::Routes::HTML::routes;
 @routes{keys(%Trog::Routes::JSON::routes)} = values(%Trog::Routes::JSON::routes);

+ 8 - 1
lib/Trog/DataModule.pm

@@ -119,7 +119,14 @@ sub filter ($self, $query, @filtered) {
 
     # If an ID is passed, just get that (and all it's prior versions)
     if ($query->{id}) {
-        @filtered = grep { $_->{id} eq $query->{id} } @filtered   if $query->{id};
+        @filtered = grep { $_->{id} eq $query->{id} } @filtered;
+        @filtered = _dedup_versions($query->{version}, @filtered);
+        return @filtered;
+    }
+
+    # XXX aclname and id are essentially serving the same purpose, should unify
+    if ($query->{aclname}) {
+        @filtered = grep { ($_->{aclname} || '') eq $query->{aclname} } @filtered;
         @filtered = _dedup_versions($query->{version}, @filtered);
         return @filtered;
     }

+ 18 - 10
lib/Trog/Routes/HTML.pm

@@ -183,11 +183,7 @@ our %routes = (
     },
 );
 
-# Build aliases for /posts and /post with extra data
-my @post_aliases = qw{news blog image video audio about files series};
-@routes{map { "/$_" } @post_aliases} = map { my %copy = %{$routes{'/posts'}}; $copy{data}{tag} = [$_]; \%copy } @post_aliases;
-
-$routes{'/series'}{data}{exclude_tags} = ['topbar'];
+my @post_aliases = qw{news blog video images audio files series about};
 
 #TODO clean this up so we don't need _build_post_type
 @routes{map { "/post/$_" } qw{image video audio files}} = map { my %copy = %{$routes{'/post'}}; $copy{data}{tag} = [$_]; $copy{data}{type} = 'file'; \%copy } qw{image video audio files};
@@ -196,12 +192,9 @@ $routes{'/post/blog'}    = { method => 'GET', auth => 1, callback => \&Trog::Rou
 $routes{'/post/about'}   = { method => 'GET', auth => 1, callback => \&Trog::Routes::HTML::post, data => { tag => ['about'],   type => 'profile'   } };
 $routes{'/post/series'}  = { method => 'GET', auth => 1, callback => \&Trog::Routes::HTML::post, data => { tag => ['series'],  type => 'series'    } };
 
-# Build aliases for /posts/(.*) and /post/(.*) with extra data
+# Build aliases for /post/(.*) with extra data
 @routes{map { "/post/$_/(.*)" } @post_aliases} = map { my %copy = %{$routes{'/post/(.*)'}}; \%copy } @post_aliases;
 
-# /series/$ID is a bit of a special case, it's actuallly gonna need special processing
-$routes{'/series/(.*)'} = { method => 'GET', auth => 1, callback => \&Trog::Routes::HTML::series, captures => ['id'] };
-
 # Grab theme routes
 my $themed = 0;
 if ($theme_dir) {
@@ -331,7 +324,7 @@ sub _build_social_meta ($query,$title) {
     $meta_tags =~ s/content="video"/content="video:other"/mg if $meta_tags;
     $meta_tags .= $extra_tags if $extra_tags;
 
-    print STDERR "WARNING: Theme misconfigured, social media tags will not be included\n$@\n" unless $meta_tags;
+    print STDERR "WARNING: Theme misconfigured, social media tags will not be included\n$@\n" if $theme_dir && !$meta_tags;
     return ($default_tags, $meta_desc, $meta_tags);
 }
 
@@ -718,14 +711,28 @@ Displays identified series, not all series.
 =cut
 
 sub series ($query, $render_cb) {
+    $query->{exclude_tags} = ['topbar'];
+
+    #we are either viewed one of two ways, /series/$id or /$aclname
+    my (undef,$aclname) = split(/\//,$query->{route});
+    $query->{aclname} = $aclname if $aclname;
+
+    #XXX I'd prefer to overload id to actually *be* the aclname...
+    # but this way, accomodates things like the flat file time-indexing hack.
+    # TODO I should probably have it for all posts, and make *everything* a series.
+    # WE can then do threaded comments/posts.
+    # That will essentially necessitate it *becoming* the ID for real.
+
     #Grab the relevant tag (aclname), then pass that to posts
     my @posts = _post_helper($query, [], $query->{acls});
     delete $query->{id};
+    delete $query->{aclname};
 
     $query->{subhead} = $posts[0]->{data};
     $query->{title} = $posts[0]->{title};
     $query->{tag} = $posts[0]->{aclname};
     $query->{primary_post} = $posts[0];
+
     return posts($query,$render_cb);
 }
 
@@ -888,6 +895,7 @@ sub _post_helper ($query, $tags, $acls) {
         tags    => $tags,
         exclude_tags => $query->{exclude_tags},
         acls    => $acls,
+        aclname => $query->{aclname},
         like    => $query->{like},
         author  => $query->{author},
         id      => $query->{id},