aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhiming Wang <zmwangx@gmail.com>2015-05-13 15:01:31 -0700
committerZhiming Wang <zmwangx@gmail.com>2015-05-13 15:06:24 -0700
commitb6d0d727c5be9a5180fb9baf9565fc1768c0ddfe (patch)
treed0c1efd7d672cc2def8c5f91efb76fef9da87831
parent4e9325b194f069030c5c192bc3f11c24f1295fd2 (diff)
downloadmy_new_personal_website-b6d0d727c5be9a5180fb9baf9565fc1768c0ddfe.tar.xz
my_new_personal_website-b6d0d727c5be9a5180fb9baf9565fc1768c0ddfe.zip
pyblog: smarter autotouch in gen_deploy
Diffstat (limited to '')
-rwxr-xr-xpyblog16
1 files changed, 13 insertions, 3 deletions
diff --git a/pyblog b/pyblog
index e563660f..42694cba 100755
--- a/pyblog
+++ b/pyblog
@@ -744,13 +744,23 @@ def gen_deploy(args):
latest_post = None
latest_mtime = 0
for name in os.listdir(POSTSDIR):
- if not name.endswith(".md"):
+ matchobj = re.match(r"^([0-9]{4})-([0-9]{2})-([0-9]{2})-.*\.md", name)
+ if not matchobj:
continue
fullpath = os.path.join(POSTSDIR, name)
ctime = os.path.getctime(fullpath)
mtime = os.path.getmtime(fullpath)
- # skip the post if it was created more than three days ago
- if current_time - ctime > 3 * 24 * 3600:
+ # get date registered in the filename, which has the format
+ # xxxx-xx-xx-blah-blah.md
+ cdate = datetime.datetime(year=int(matchobj[1]),
+ month=int(matchobj[2]),
+ day=int(matchobj[3]),
+ hour=23, minute=59, second=59,
+ tzinfo=dateutil.tz.tzlocal()).timestamp()
+ # skip the post if its source file was created more than three
+ # days ago, or the date registered in its filename is more than
+ # three days ago
+ if max(current_time - ctime, current_time - cdate) > 3 * 24 * 3600:
continue
if mtime > latest_mtime:
latest_post = name