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/]"
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 />
#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%"><-- <a href="$prev_href">$prev_title</a></td>
+#else
+ <td style="text-align: left" width="50%"> </td>
+#end if
+#if $next_blog_post
+ <td style="text-align: right" width="50%"><a href="$next_href">$next_title</a> --></td>
+#else
+ <td style="text-align: right" width="50%"> </td>
+#end if
+ </tr>
+</table>
+#end if
</p>
$body
#def link_tag($tag)