From 6a2b39f98da72d1cead6e4604494884ec46a3bd9 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 10 Apr 2017 06:19:48 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=B8?= =?utf8?q?=D1=82=D1=8C=20=D0=B2=20=D0=B1=D0=BB=D0=BE=D0=B3=D0=B5=20=D1=81?= =?utf8?q?=D1=81=D1=8B=D0=BB=D0=BA=D0=B8=20=D0=BD=D0=B0=20=D0=BF=D1=80?= =?utf8?q?=D0=B5=D0=B4./=D1=81=D0=BB=D0=B5=D0=B4.=20=D0=BF=D0=BE=D1=81?= =?utf8?q?=D1=82=D1=8B=20=D0=BF=D0=BE=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5?= =?utf8?q?=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- TODO | 3 --- phd.py | 29 +++++++++++++++++++++++++++++ phd_site.tmpl | 26 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index c4712eb..6c0e868 100644 --- 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 4e13617..6b67c20 100644 --- 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_name)s-thumbnail.jpg
diff --git a/phd_site.tmpl b/phd_site.tmpl index 0388f0b..9f3bc64 100644 --- a/phd_site.tmpl +++ b/phd_site.tmpl @@ -113,6 +113,32 @@ $style #silent $breadcrumbs.append('' + $path_components[i]+ '') #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 +
+ + +#if $prev_blog_post + +#else + +#end if +#if $next_blog_post + +#else + +#end if + +
<-- $prev_title $next_title --> 
+#end if

$body #def link_tag($tag) -- 2.39.5