Quellcode durchsuchen

fix some things about sitemap

George S. Baugh vor 4 Jahren
Ursprung
Commit
94132f263c
4 geänderte Dateien mit 31 neuen und 19 gelöschten Zeilen
  1. 20 10
      lib/Trog/DataModule.pm
  2. 8 8
      lib/Trog/Routes/HTML.pm
  3. 2 0
      www/templates/posts.tx
  4. 1 1
      www/templates/sitemap.tx

+ 20 - 10
lib/Trog/DataModule.pm

@@ -96,17 +96,26 @@ sub _fixup ($self, @filtered) {
 
     # urlencode spaces in filenames
     @filtered = map {
+        my $subj = $_;
         foreach my $param (qw{href preview video_href audio_href local_href wallpaper}) {
-            next unless exists $_->{$param};
-            $_->{$param} =~ s/ /%20/g;
+            next unless exists $subj->{$param};
+            $subj->{$param} =~ s/ /%20/g;
         }
 
-        #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});
+        #XXX Add dynamic routing data for posts which don't have them (/posts/$id) and (/users/$user)
+        my $is_user_page = grep { $_ eq 'about' } @{$subj->{tags}};
+        if (!exists $subj->{local_href}) {
+            $subj->{local_href} = "/posts/$subj->{id}";
+            $subj->{local_href} = "/users/$subj->{title}" if $is_user_page;
+        }
+        if (!exists $subj->{callback}) {
+            $subj->{callback} = "Trog::Routes::HTML::posts";
+            $subj->{callback} = "Trog::Routes::HTML::users" if $is_user_page;
+        }
+
+        $subj->{method} = 'GET' unless exists($subj->{method});
 
-        $_
+        $subj
     } @filtered;
 
     return @filtered;
@@ -271,13 +280,14 @@ sub add ($self, @posts) {
 # Not actually a subprocess, kek
 sub _process ($post) {
 
-    $post->{href}      = _handle_upload($post->{file}, $post->{id})         if $post->{file};
-    $post->{preview}   = _handle_upload($post->{preview_file}, $post->{id}) if $post->{preview_file};
-    $post->{wallpaper} = _handle_upload($post->{wallpaper_file}, $post->{id})    if $post->{wallpaper_file};
+    $post->{href}      = _handle_upload($post->{file}, $post->{id})             if $post->{file};
+    $post->{preview}   = _handle_upload($post->{preview_file}, $post->{id})     if $post->{preview_file};
+    $post->{wallpaper} = _handle_upload($post->{wallpaper_file}, $post->{id})   if $post->{wallpaper_file};
     $post->{preview} = $post->{href} if $post->{app} eq 'image';
     delete $post->{app};
     delete $post->{file};
     delete $post->{preview_file};
+    delete $post->{wallpaper_file};
 
     delete $post->{scheme};
     delete $post->{route};

+ 8 - 8
lib/Trog/Routes/HTML.pm

@@ -100,7 +100,7 @@ our %routes = (
         callback => \&Trog::Routes::HTML::manual,
     },
 
-    #TODO transform intoposts
+    #TODO transform into posts?
     '/sitemap', => {
         method   => 'GET',
         callback => \&Trog::Routes::HTML::sitemap,
@@ -151,12 +151,6 @@ our %routes = (
         callback => \&Trog::Routes::HTML::avatars,
         data     => { tag => ['about'] },
     },
-
-    '/users/(.*)' => {
-        method => 'GET',
-        callback => \&Trog::Routes::HTML::users,
-        captures => ['username'],
-    },
 );
 
 #XXX these need to be fetched dynamically from all the header categories?
@@ -975,7 +969,13 @@ sub sitemap ($query, $render_cb) {
             my $changefreq = $query->{map} eq 'static' ? 'monthly' : 'daily';
             foreach my $url (@to_map) {
                 my $true_uri = "http://$query->{domain}$url";
-                $true_uri = "http://$query->{domain}/posts/$url->{id}" if ref $url eq 'HASH';
+                if (ref $url eq 'HASH') {
+                    my $is_user_page = grep { $_ eq 'about' } @{$url->{tags}};
+                    use Data::Dumper;
+                    print Dumper($url);
+                    $true_uri = "http://$query->{domain}/posts/$url->{id}";
+                    $true_uri = "http://$query->{domain}/users/$url->{title}" if $is_user_page;
+                }
                 my %data = (
                     loc        => $true_uri,
                     lastmod    => $xml_date,

+ 2 - 0
www/templates/posts.tx

@@ -1,7 +1,9 @@
 : if ( $can_edit ) {
     <script type="text/javascript" src="/scripts/post.js"></script>
     : if (!$direct) {
+        : if ($to) {
         : include "jsalert.tx";
+        : }
         <a style="cursor:pointer" onclick="switchMenu('submissions')">[Add Post]</a><hr />
         <div id="submissions" style="display:none">
           : include $edittype ~ ".tx";

+ 1 - 1
www/templates/sitemap.tx

@@ -25,7 +25,7 @@
             <a href="<: $map :>">
             <: $map :>
         : } else {
-            <a href="/posts/<: $map.id :>">
+            <a href="<: $map.local_href :>">
             <: $map.title :>
         : }
         </a><br />