When viewing single posts the next/previous links are given
authorNot Zed <notzed@gmail.com>
Sun, 14 Jul 2019 03:08:22 +0000 (12:38 +0930)
committerNot Zed <notzed@gmail.com>
Sun, 14 Jul 2019 03:08:22 +0000 (12:38 +0930)
the title of the post rather than older/newer.

blog.c
makeindex.pl
posts.c
posts.h

diff --git a/blog.c b/blog.c
index e6f724c..701ae75 100644 (file)
--- a/blog.c
+++ b/blog.c
@@ -169,6 +169,30 @@ static void print_url(const char *p) {
        }
 }
 
+// basic ascii text to html, not complete.  ideally utf8
+static void print_ascii(const char *p) {
+       int c;
+
+       while ((c = *p++)) {
+               switch (c) {
+               case '&':
+                       send("&amp;");
+                       break;
+               case '<':
+                       send("&lt;");
+                       break;
+               case '>':
+                       send("&gt;");
+                       break;
+               case '"':
+                       send("&quot;");
+                       break;
+               default:
+                       sendc(c);
+               }
+       }
+}
+
 /*( ********************************************************************** )*/
 /* Blog code proper */
 
@@ -429,12 +453,28 @@ static void dopost(const char *path, const char *query) {
        // TODO: Once I have a proper index this should output the post name
        if (newer || older) {
                send("<div>\n");
-               if (newer)
-                       sendf("<a href='" POST_SCRIPT "/%012lx'>Newer Post</a>", newer);
+               if (newer) {
+                       const char *title = blog_title(newer);
+                       
+                       sendf("<a href='" POST_SCRIPT "/%012lx'>", newer);
+                       if (title)
+                               print_ascii(title);
+                       else
+                               send("Newer Post");
+                       send("</a>");
+               }
                if (older) {
+                       const char *title = blog_title(older);
+                       
                        if (newer)
                                send(" | ");
-                       sendf("<a href='" POST_SCRIPT "/%012lx'>Older Post</a>", older);
+
+                       sendf("<a href='" POST_SCRIPT "/%012lx'>", older);
+                       if (title)
+                               print_ascii(title);
+                       else
+                               send("Older Post");
+                       send("</a>");
                }
                send("</div>\n");
        }
index 2efda9b..a8688cb 100755 (executable)
@@ -27,9 +27,11 @@ $index = 0;
 
 @allids = ();
 @allfiles = ();
+@alltitles = ();
 
 open IN,"ls -1 ${db} | grep -v meta | grep -v '~' | sort|" || die "Unable to find posts";
 while (<IN>) {
+    my $title = "";
     chop;
     $id = $_;
     $name = $db."/".$id.".meta";
@@ -39,6 +41,10 @@ while (<IN>) {
        if (m@^original=http.*\.com/(\d{4}/\d{2})/(.*)@) {
            $part = $1;
            $file = $2;
+       } elsif (m@^title=(.*)@) {
+           $title = $1;
+           # remove java property file escape
+           $title =~ s@\\(.)@\1@g;
        }
     }
     $byid{$id} = $file;
@@ -49,6 +55,7 @@ while (<IN>) {
 
     push @allfiles, $file;
     push @allids, $id;
+    push @alltitles, $title;
     
     $index += 1;
 }
@@ -72,6 +79,13 @@ foreach $k (@allfiles) {
 }
 print "\n};\n";
 
+print "static const char *post_title[] = {\n";
+foreach $k (@alltitles) {
+    $k =~ s/"/\\"/g;
+    print "\"$k\",\n";
+}
+print "\n};\n";
+
 print "static const struct post_index post_index[] = {\n";
 
 foreach $k (sort keys %bymonth) {
diff --git a/posts.c b/posts.c
index 32fc6dc..f3a917f 100644 (file)
--- a/posts.c
+++ b/posts.c
@@ -163,6 +163,12 @@ time_t blog_time(postid_t id) {
        return id / 1000;
 }
 
+const char *blog_title(postid_t id) {
+       int i = blog_postid(id);
+
+       return i >= 0 ? post_title[i] : NULL;
+}
+
 static int cmp_month(const void *ap, const void *bp) {
        const char *a = ap;
        const struct post_index *b = bp;
diff --git a/posts.h b/posts.h
index 2d8884e..b1717c2 100644 (file)
--- a/posts.h
+++ b/posts.h
@@ -43,6 +43,7 @@ int blog_tags(postid_t id, const char **tags, int max);
 postid_t blog_latest(void);
 postid_t blog_latest_tag(int tagid);
 time_t blog_time(postid_t id);
+const char *blog_title(postid_t id);
 
 int blog_tag_list(const struct post_tag **tags);
 const char *blog_tag_name(unsigned int tagid);