X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=phd.py;h=f51df69d8aba61ee1d49b3d856f8c2b9d09114f5;hb=c89b746df98f09e80169480d13ec452c2a919f7e;hp=4e13617540eeb09967a2aff01209cc2be9b9ae82;hpb=331965859222bca39a7fc251cdc93830620c8a4a;p=phdru.name%2Fphdru.name.git
diff --git a/phd.py b/phd.py
index 4e13617..f51df69 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
+ blog = load_blog()
+ for key in sorted(blog):
+ for blog_post in sorted(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 """\