def update_files(cls): filepaths = glob.glob( os.path.join(app.config['MARKLOG_POST_DIR'], '*.md')) filenames = list(map(os.path.basename, filepaths)) files = zip(filenames, filepaths) # 1. Prune Posts that are missing from posts folder for post in cls.query.all(): if post.filename not in filenames: db.session.delete(post) db.session.commit() # 2. Add new Post for unregistered files from posts folder # and update those that exist for f in files: post = cls.query.filter_by(filename=f[0]).first() if post: file_mod_date = dt.datetime.fromtimestamp( os.path.getmtime(f[1])) if post.filedate < file_mod_date: db.session.delete(post) db.session.commit() else: continue post, html = cls.new_post(f[0], f[1]) if post: cache.set(post.slug, html) db.session.add(post) db.session.commit()
def update_files(cls): filepaths = glob.glob(os.path.join(app.config['MARKLOG_POST_DIR'], '*.md')) filenames = list(map(os.path.basename, filepaths)) files = zip(filenames, filepaths) # 1. Prune Posts that are missing from posts folder for post in cls.query.all(): if post.filename not in filenames: db.session.delete(post) db.session.commit() # 2. Add new Post for unregistered files from posts folder # and update those that exist for f in files: post = cls.query.filter_by(filename = f[0]).first() if post: file_mod_date = dt.datetime.fromtimestamp(os.path.getmtime(f[1])) if post.filedate < file_mod_date: db.session.delete(post) db.session.commit() else: continue post, html = cls.new_post(f[0], f[1]) if post: cache.set(post.slug, html) db.session.add(post) db.session.commit()
def render_html(self): filepath = os.path.join(app.config['MARKLOG_POST_DIR'], self.filename) html = cache.get(self.slug) if html: return html html, meta = markdown_convert(filepath) cache.set(self.slug, html) return html