George S. Baugh il y a 4 ans
Parent
commit
0e5967c4b1

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

@@ -869,24 +869,18 @@ sub posts ($query, $render_cb, $direct=0) {
     my @post_aliases = map { $_->{local_href} } _get_series();
 
     my ($header,$footer);
-    my $should_header = grep { $_ eq $query->{route} } (@post_aliases,'/humans.txt');
-    if ($should_header) {
-
-        my $route = $query->{route};
-        my %alias = ( '/humans.txt' => '/about');
-        $route = $alias{$route} if exists $alias{$route};
+    my $t_processor;
+    $t_processor = Text::Xslate->new(
+        path =>  "www/$theme_dir/templates",
+    ) if $theme_dir;
 
-        my $t_processor;
-        $t_processor = Text::Xslate->new(
-            path =>  "www/$theme_dir/templates",
-        ) if $theme_dir;
+    $header = _pick_processor('templates/headers/'.$query->{primary_post}{header}, $processor,$t_processor)->render('headers/'.$query->{primary_post}{header}, { theme_dir => $td } ) if $query->{primary_post}{header};
+    $footer = _pick_processor('templates/footers/'.$query->{primary_post}{footer}, $processor,$t_processor)->render('footers/'.$query->{primary_post}{footer}, { theme_dir => $td } ) if $query->{primary_post}{footer};
 
-        my $no_leading_slash = $route;
-        $no_leading_slash =~ tr/\///d;
+    # List the available headers/footers
+    my $headers = _templates_in_dir($theme_dir ? "www/$theme_dir/templates/headers" : "www/templates/headers");
+    my $footers = _templates_in_dir($theme_dir ? "www/$theme_dir/templates/footers" : "www/templates/footers");
 
-        $header = _pick_processor("templates$route\_header.tx"  ,$processor,$t_processor)->render("$no_leading_slash\_header.tx", { theme_dir => $td } );
-        $footer = _pick_processor("templates$route\_header.tx"  ,$processor,$t_processor)->render("$no_leading_slash\_footer.tx", { theme_dir => $td } );
-    }
     my $styles = _build_themed_styles('posts.css');
 
     #Correct page headers
@@ -927,12 +921,7 @@ sub posts ($query, $render_cb, $direct=0) {
         $_
     } _post_helper({}, ['series'], $query->{acls});
 
-    my $forms = [];
-    opendir(my $dh, "$template_dir/forms");
-    while (my $form = readdir($dh)) {
-        push(@$forms, $form) if -f "$template_dir/forms/$form" && $form =~ m/.*\.tx$/;
-    }
-    close($dh);
+    my $forms = _templates_in_dir("$template_dir/forms");
 
     my $edittype = $query->{primary_post} ? $query->{primary_post}->{child_form} : $query->{form};
     my $tiled    = $query->{primary_post} ? !$is_admin && $query->{primary_post}->{tiled} : 0;
@@ -978,6 +967,8 @@ sub posts ($query, $render_cb, $direct=0) {
         subhead   => $query->{subhead},
         header    => $header,
         footer    => $footer,
+        headers   => $headers,
+        footers   => $footers,
         years     => [reverse($oldest_year..$now_year)],
         months    => [0..11],
     });
@@ -985,6 +976,16 @@ sub posts ($query, $render_cb, $direct=0) {
     return Trog::Routes::HTML::index($query, $render_cb, $content, $styles);
 }
 
+sub _templates_in_dir($path) {
+    my $forms = [];
+    opendir(my $dh, $path);
+    while (my $form = readdir($dh)) {
+        push(@$forms, $form) if -f "$path/$form" && $form =~ m/.*\.tx$/;
+    }
+    close($dh);
+    return $forms;
+}
+
 sub _themed_title ($path) {
     return $path unless %Theme::paths;
     return $Theme::paths{$path} ? $Theme::paths{$path} : $path;

+ 0 - 15
www/templates/about_footer.tx

@@ -1,15 +0,0 @@
-<br /><br />
-<h3>FAQ</h3>
-<p>
-* Why does tCMS not support comments?
-</p>
-<p>
-Being the publisher of content from random yahoos is best handled by social media giants, mostly for legal reasons.
-Don't overcomplicate your life with that stuff; instead get an RSS based repost bot like feed2tweet to syndicate for the peanut gallery.
-</p>
-<p>
-Besides, you want to maximize your reach anyways, right?
-You may as well get on the social platforms.
-Comments also don't appear to have an effect on the authority your site has in search engines.
-So you save huge time and headaches, and build yet another audience funnel by not fighting the social media giants.
-</p>

+ 0 - 3
www/templates/about_header.tx

@@ -1,3 +0,0 @@
-<p>
-tCMS is built thanks to viewers like you.  Here's who's to blame:
-</p>

+ 0 - 0
www/templates/audio_footer.tx


+ 0 - 0
www/templates/audio_header.tx


+ 0 - 0
www/templates/blog_footer.tx


+ 0 - 0
www/templates/blog_header.tx


+ 0 - 0
www/templates/files_footer.tx


+ 0 - 0
www/templates/files_header.tx


+ 1 - 0
www/templates/footers/README.md

@@ -0,0 +1 @@
+www/templates/headers/README.md

+ 14 - 0
www/templates/forms/series.tx

@@ -41,6 +41,20 @@
             <option value="<: $form :>" <: if ( $post.child_form == $form ) { :>selected<: } :> ><: $form :></option>
         : }
         </select>
+        Header<br />
+        <select class="cooltext" name="header">
+            <option value="">none</option>
+        : for $headers -> $header {
+            <option value="<: $header :>" <: if ( $post.header == $header ) { :>selected<: } :> ><: $header :></option>
+        : }
+        </select>
+        Footer<br />
+        <select class="cooltext" name="footer">
+            <option value="">none</option>
+        : for $footers -> $footer {
+            <option value="<: $footer :>" <: if ( $post.footer == $footer ) { :>selected<: } :> ><: $footer :></option>
+        : }
+        </select>
         <input type="hidden" name="callback" value="Trog::Routes::HTML::series" />
         : include "preview.tx";
         : include "acls.tx";

+ 8 - 0
www/templates/headers/README.md

@@ -0,0 +1,8 @@
+## Headers and Footers
+
+Per page header/footers can be created by putting a template in here, and then referencing it in the post's metadata.
+They should be automatically picked up by the system, and populate a dropdown on edit/create.
+
+As of this writing, only the series add/edit template support this, but it should be straightforward to add these to custom post types, or every post type.
+
+You can also distribute your header and footer files in the templates directory of your theme by placing them in a headers/ or footers/ directory therein.

+ 0 - 0
www/templates/image_footer.tx


+ 0 - 0
www/templates/image_header.tx


+ 0 - 0
www/templates/news_footer.tx


+ 0 - 0
www/templates/news_header.tx


+ 0 - 0
www/templates/series_footer.tx


+ 0 - 0
www/templates/series_header.tx


+ 0 - 0
www/templates/video_footer.tx


+ 0 - 0
www/templates/video_header.tx