George S. Baugh %!s(int64=5) %!d(string=hai) anos
pai
achega
8f3fbe670f
Modificáronse 3 ficheiros con 30 adicións e 10 borrados
  1. 5 2
      lib/Trog/Routes/HTML.pm
  2. 15 0
      www/server.psgi
  3. 10 8
      www/templates/header.tx

+ 5 - 2
lib/Trog/Routes/HTML.pm

@@ -250,7 +250,7 @@ sub index ($query,$render_cb, $content = '', $i_styles = []) {
 
     #Header SEO stuff
     my $default_tags = $Theme::tags;
-    $default_tags .= ','.$query->{primary_post}->{tags} if $default_tags && $query->{primary_post}->{tags};
+    $default_tags .= ','.join(',',$query->{primary_post}->{tags}) if $default_tags && $query->{primary_post}->{tags};
 
     #TODO truncate this and filter out to innerHTML
     my $meta_desc  = $query->{primary_post}->{data} // $Theme::description // "tCMS Site";
@@ -721,6 +721,10 @@ sub posts ($query, $render_cb) {
         @posts = _post_helper($query, $tags, $query->{acls});
     }
 
+    if ($query->{id}) {
+        $query->{primary_post} = $posts[0] if @posts;
+    }
+
     #OK, so if we have a user as the ID we found, go grab the rest of their posts
     if ($query->{id} && @posts && grep { $_ eq 'about'} @{$posts[0]->{tags}} ) {
         my $user = shift(@posts);
@@ -728,7 +732,6 @@ sub posts ($query, $render_cb) {
         $query->{author} = $user->{user};
         @posts = _post_helper($query, [], $query->{acls});
         @posts = grep { $_->{id} ne $id } @posts;
-        $query->{primary_post} = $posts[0];
         unshift @posts, $user;
     }
 

+ 15 - 0
www/server.psgi

@@ -72,7 +72,10 @@ my $app = sub {
 
     my $query = {};
     $query = URL::Encode::url_params_mixed($env->{QUERY_STRING}) if $env->{QUERY_STRING};
+
     my $path = $env->{PATH_INFO};
+    # Collapse multiple slashes in the path
+    $path =~ s/[\/]+/\//g;
 
     # Let's open up our default route before we bother to see if users even exist
     return $routes{default}{callback}->($query,\&_render) unless -f "config/setup";
@@ -194,6 +197,18 @@ sub _render ($template, $vars, @headers) {
         path   => 'www/templates',
         header => ['header.tx'],
         footer => ['footer.tx'],
+        function => {
+            iso8601 => sub {
+                my $t = shift;
+                my $dt  = DateTime->from_epoch( epoch => $t );
+                return $dt->iso8601;
+            },
+            strip_and_trunc => sub {
+                my $s = shift;
+                $s =~ s/<[^>]*>//g;
+                return substr $s, 0, 280;
+            },
+        },
     );
 
     #XXX default vars that need to be pulled from config

+ 10 - 8
www/templates/header.tx

@@ -4,27 +4,29 @@
         <title><: $title :></title>
         <meta charset="utf-8" />
         <link rel="icon" type="image/vnd.microsoft.icon" href="<: $theme_dir :>/img/icon/favicon.ico" />
-        <meta name="description" content="<: $meta_desc :>"/>
+        <meta name="description" content="<: $meta_desc | strip_and_trunc :>"/>
         : if ($default_tags) {
         <meta name="tags" content="<: $default_tags :>" />
         : }
 
+        <meta property="postid" content="<: $primary_post.id :>" />
+
         <!-- Open Graph / Facebook -->
         <meta property="og:type" content="<: $og_type :>" />
         <meta property="og:url" content="https://<: $domain :>/<: $route :>" />
         <meta property="og:title" content="<: $title :>" />
-        : if ($primary_post.tags) {
-        <meta property="og:article:tags" content="<: $primary_post.tags :>" />
+        : if ($default_tags) {
+        <meta property="og:article:tags" content="<: $default_tags :>" />
         : }
         : if ($primary_post.is_image) {
         <meta property="og:image" content="https://<: $domain :>/<: $primary_post.href :>" />
-        <meta property="og:image:type" content="<: $primary_post.type :>" />
+        <meta property="og:image:type" content="<: $primary_post.content_type :>" />
         <meta property="og:image:width" content="1280" />
         <meta property="og:image:height" content=720 />
         : }
         : elsif ($primary_post.is_video) {
         <meta property="og:video" content="https://<: $domain :>/<: $primary_post.href :>" />
-        <meta property="og:video:type"  content="<: $primary_post.type :>" />
+        <meta property="og:video:type"  content="<: $primary_post.content_type :>" />
         <meta property="og:video:width" content="1280" />
         <meta property="og:video:height" content="720" />
         <meta property="og:video:image"  content="https://<: $domain :>/<: $primary_post.preview :>" />
@@ -33,8 +35,8 @@
         <meta property="og:article:author" content="<: $primary_post.user :>" />
         : }
         : if ($primary_post.created) {
-        <meta property="og:article:published_time" content="<: $primary_post.created :>" />
-        <meta property="og:article:modified_time" content="<: $primary_post.created :>" />
+        <meta property="og:article:published_time" content="<: $primary_post.created | iso8601 :>" />
+        <meta property="og:article:modified_time" content="<: $primary_post.created | iso8601 :>" />
         : }
         : if ($fb_app_id) {
         <meta property="fb:app_id" content="<: $fb_app_id :>" />
@@ -57,7 +59,7 @@
         <meta property="twitter:player" content="https://<: $domain :>/<: $route :>?embed=1" />
         : }
         <meta property="twitter:title" content="<: $title :>" />
-        <meta property="twitter:description" content="<: $meta_desc :>" />
+        <meta property="twitter:description" content="<: $meta_desc | strip_and_trunc :>" />
 
         <meta name="viewport" content="width=device-width">
         <link rel="stylesheet" type="text/css" href="/styles/structure.css" />