1 #! /usr/bin/env python3
3 __author__ = "Oleg Broytman <phd@phdru.name>"
4 __copyright__ = "Copyright (C) 2020-2024 PhiloSoft Design"
7 from blog_db import blog_root, load_blog
10 # Run a loop over the blog posts:
11 # for every post note its previous and next posts
12 # and compare timestamps of previous and next HTML
13 # with the timestamp of the current template;
14 # if HTMLs are older - remove them,
15 # they will be regenerated with the corrected back/forth links.
18 def fullpath(key, post):
19 return os.path.join(*(blog_root,) + key + (post[0],))
23 return tmpl[:-len('tmpl')] + 'html'
26 prev_key = prev_blog_post = current_key = current_blog_post = \
27 next_key = next_blog_post = None
28 for key in sorted(blog):
29 for blog_post in sorted(blog[key]):
31 prev_key = current_key
32 prev_blog_post = current_blog_post
34 current_key = next_key
35 current_blog_post = next_blog_post
37 next_blog_post = blog_post
40 current_tmpl = fullpath(current_key, current_blog_post)
42 current_mtime = os.path.getmtime(current_tmpl)
47 prev_html = html(fullpath(prev_key, prev_blog_post))
49 prev_mtime = os.path.getmtime(prev_html)
53 if current_mtime is not None and (prev_mtime < current_mtime):
55 if current_key and next_key:
56 next_html = html(fullpath(next_key, next_blog_post))
58 next_mtime = os.path.getmtime(next_html)
62 if current_mtime is not None and (next_mtime < current_mtime):
66 current_tmpl = fullpath(key, blog_post)
68 current_mtime = os.path.getmtime(current_tmpl)
74 prev_html = html(fullpath(current_key, current_blog_post))
76 prev_mtime = os.path.getmtime(prev_html)
80 if current_mtime is not None and (prev_mtime < current_mtime):