From: Not Zed Date: Sun, 14 Jul 2019 03:08:22 +0000 (+0930) Subject: When viewing single posts the next/previous links are given X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=184193d218fa3381d99523ca376ea82c6e3bf1fa;p=blogz When viewing single posts the next/previous links are given the title of the post rather than older/newer. --- diff --git a/blog.c b/blog.c index e6f724c..701ae75 100644 --- 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("&"); + break; + case '<': + send("<"); + break; + case '>': + send(">"); + break; + case '"': + send("""); + 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("
\n"); - if (newer) - sendf("Newer Post", newer); + if (newer) { + const char *title = blog_title(newer); + + sendf("", newer); + if (title) + print_ascii(title); + else + send("Newer Post"); + send(""); + } if (older) { + const char *title = blog_title(older); + if (newer) send(" | "); - sendf("Older Post", older); + + sendf("", older); + if (title) + print_ascii(title); + else + send("Older Post"); + send(""); } send("
\n"); } diff --git a/makeindex.pl b/makeindex.pl index 2efda9b..a8688cb 100755 --- a/makeindex.pl +++ b/makeindex.pl @@ -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 () { + my $title = ""; chop; $id = $_; $name = $db."/".$id.".meta"; @@ -39,6 +41,10 @@ while () { 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 () { 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 --- 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 --- 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);