From b6d0d727c5be9a5180fb9baf9565fc1768c0ddfe Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Wed, 13 May 2015 15:01:31 -0700 Subject: pyblog: smarter autotouch in gen_deploy --- pyblog | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'pyblog') 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 -- cgit v1.2.1