]> git.phdru.name Git - phdru.name/phdru.name.git/commitdiff
Проставить в блоге ссылки на пред./след. посты по времени
authorOleg Broytman <phd@phdru.name>
Mon, 10 Apr 2017 03:19:48 +0000 (06:19 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 10 Apr 2017 03:55:32 +0000 (06:55 +0300)
TODO
phd.py
phd_site.tmpl

diff --git a/TODO b/TODO
index c4712eb2dcc406881b608e27e8faef6dc1761d44..6c0e868f0939c56e56d1192ba1377141709c95c7 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,3 @@
-Проставить в блоге ссылки на пред./след. посты, по времени и по тегам.
-
-
 Проставить на всех страницах ссылки на валидаторы
 http://validator.w3.org/check/referer и
 http://jigsaw.w3.org/css-validator/check/referer
diff --git a/phd.py b/phd.py
index 4e13617540eeb09967a2aff01209cc2be9b9ae82..6b67c20c900567eb31d9ceb72bf6001ff5b86586 100644 (file)
--- a/phd.py
+++ b/phd.py
@@ -5,6 +5,7 @@ except ImportError:
     from urllib.parse import quote as url_quote
 from Cheetah.Template import Template
 from Cheetah.compat import PY2
+from blog_db import load_blog
 
 
 url_re = r"(((https?|ftp|gopher|telnet)://|(mailto|file|news|about|ed2k|irc|sip|magnet):)[^' \t<>\"]+|(www|web|w3)[A-Za-z0-9_-]*\.[A-Za-z0-9._-]+\.[^' \t<>\"]+)[A-Za-z0-9/]"
@@ -100,6 +101,34 @@ class phd(Template):
         from markdown import markdown
         return markdown(self.body_mkd(), output_format="html")
 
+
+    def find_near_blog_posts(self):
+        if not self.path.startswith("/Russian/blog/"):
+            return None, None, None, None
+        dirs = self.path.split('/')
+        # blog post is ['', 'Russian', 'blog', year, month, day, filename]
+        if len(dirs) != 7:  # Not a blog post
+            return None, None, None, None
+        ymd = tuple(dirs[3:-1])
+        filename = self._fileBaseName
+
+        prev_key = prev_blog_post = current_key = current_blog_post = \
+                next_key = next_blog_post = None
+        old_blog = load_blog()
+        for key in sorted(old_blog):
+            for blog_post in sorted(old_blog[key]):
+                if current_blog_post:
+                    prev_key, prev_blog_post = current_key, current_blog_post
+                if next_blog_post:
+                    current_key, current_blog_post = next_key, next_blog_post
+                next_key = key
+                next_blog_post = blog_post
+                if current_blog_post and (current_key == ymd) and \
+                        (current_blog_post[0] == filename):  # Found!
+                    return prev_key, prev_blog_post, next_key, next_blog_post
+        return current_key, current_blog_post, None, None
+
+
     def img_thumbnail_800_1024(self, img_name):
         return """\
 <img src="%(img_name)s-thumbnail.jpg" alt="%(img_name)s-thumbnail.jpg" /><br />
index 0388f0bf8b86c863e4e7b22e6daa9bf982fee006..9f3bc64bbbf963cdf8d9de32a8f4fbacab9bfb09 100644 (file)
@@ -113,6 +113,32 @@ $style
 #silent $breadcrumbs.append('<a href="' + $root + $subpath + '/">' + $path_components[i]+ '</a>')
 #end for
 #echo " / ".join($breadcrumbs)
+#if $path.startswith("/Russian/blog/")
+#set $prev_key, $prev_blog_post, $next_key, $next_blog_post = $find_near_blog_posts()
+#if $prev_blog_post
+#set $prev_href = $root + "Russian/blog/" + '/'.join($prev_key + ($prev_blog_post[0].replace('.tmpl', '.html'),))
+#set $prev_title = $prev_blog_post[1].decode('koi8-r')
+#end if
+#if $next_blog_post
+#set $next_href = $root + "Russian/blog/" + '/'.join($next_key + ($next_blog_post[0].replace('.tmpl', '.html'),))
+#set $next_title = $next_blog_post[1].decode('koi8-r')
+#end if
+<br>
+<table width="100%">
+  <tr>
+#if $prev_blog_post
+    <td style="text-align: left" width="50%">&lt;-- <a href="$prev_href">$prev_title</a></td>
+#else
+    <td style="text-align: left" width="50%">&nbsp;</td>
+#end if
+#if $next_blog_post
+    <td style="text-align: right" width="50%"><a href="$next_href">$next_title</a> --&gt;</td>
+#else
+    <td style="text-align: right" width="50%">&nbsp;</td>
+#end if
+  </tr>
+</table>
+#end if
 </p>
 $body
 #def link_tag($tag)