Răsfoiți Sursa

add more flexibility for embedding posts within others

George S. Baugh 4 ani în urmă
părinte
comite
5d3676ddb8
3 a modificat fișierele cu 28 adăugiri și 3 ștergeri
  1. 17 0
      Readme.md
  2. 1 0
      lib/Trog/Routes/HTML.pm
  3. 10 3
      www/templates/posts.tx

+ 17 - 0
Readme.md

@@ -41,6 +41,23 @@ Planned development:
 * Presentations
 * Test Plans / Issues (crossover with App::Prove::Elasticsearch)
 
+Embedding Posts within other Posts
+==================================
+
+If you know a Post's ID (see the numbers at the end of it's URI when viewing it's permalink denoted by the chain emoji)
+You can embed template logic into your posts like so:
+
+```
+<: embed(12345, 'embed') :>
+```
+
+The first parameter is the ID number of the post.
+The second parameter is the formatting style:
+
+* embed : default, shows the post with a recessed border as an excerpt.
+* media : only show media portion of the post, if any.
+* inline : show everything about the post, save for the title.
+
 Data Models
 ===========
 * DUMMY - A JSON blob.  Used for testing mostly, but could be handy for very small sites.

+ 1 - 0
lib/Trog/Routes/HTML.pm

@@ -832,6 +832,7 @@ sub posts ($query, $render_cb, $direct=0) {
                         embed => sub {
                             my ($this_id, $style) = @_;
                             $style //= 'embed';
+                            # If instead the style is 'content', then we will only show the content w/ no formatting, and no title.
                             return Text::Xslate::mark_raw(Trog::Routes::HTML::posts(
                                 { route => "/post/$this_id", style => $style },
                                 sub {},

+ 10 - 3
www/templates/posts.tx

@@ -47,8 +47,10 @@
         <div class="post <: $style :>">
             : if (!$post.is_profile) {
             <h3 class='blogtitles'>
-                <a ><a href='<: $post.href :>' ><: $post.title :></a>
-                <a class="undecorated" href='/posts/<: $post.id :>'>🔗</a>
+                : if (!$style || $style == 'embed') {
+                    <a ><a href='<: $post.href :>' ><: $post.title :></a>
+                    <a class="undecorated" href='/posts/<: $post.id :>'>🔗</a>
+                : }
                 : if (!$style) {
                     : if ( $post.version_max && !$rss ) {
                     <form method="GET" action="/posts/<: $post.id :>" style="float:right;">
@@ -107,7 +109,9 @@
                     : if ( $post.is_profile ) {
                     <h3><: $post.title :></h3>
                     : }
-                    <: render_it($post.data) | mark_raw  :>
+                    : if ( $style != 'media' ) {
+                        <: render_it($post.data) | mark_raw  :>
+                    : }
                 </div>
             : }
             : if( $post.is_profile ) {
@@ -131,6 +135,9 @@
 
                     // Fix post dates to be localized
                     var e = document.getElementById("<: $post.id :>-<: $post.version :>-time");
+                    if (!e) {
+                        return;
+                    }
                     var d = new Date(0);
                     d.setUTCSeconds(e.innerText);
                     e.innerHTML = "&nbsp;" + d.toDateString();