From: Oleg Broytman Date: Mon, 10 Apr 2017 03:19:48 +0000 (+0300) Subject: Проставить в блоге ссылки на пред./след. посты по времени X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=6a2b39f98da72d1cead6e4604494884ec46a3bd9;p=phdru.name%2Fphdru.name.git Проставить в блоге ссылки на пред./след. посты по времени --- 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)