def load_posts(self, fpath=None):
"""\
- Load valid posts from source directory
- Convert the text to extract the HTML data, metas and filenames
- Returns a list of tuples that store the above information
"""
if fpath == None:
fpath = self.ifpath
if path.exists(fpath):
posts = []
for f in [fpath] if path.isfile(fpath) \
else list(map(lambda x: path.join(fpath, x),
listdir(fpath))):
if path.splitext(f)[1] in self._md_exts:
with codecs.open(f, 'r', encoding='utf-8') as fh:
md = Markdown(extensions=self.pymd_exts)
html = BeautifulSoup(md.convert(fh.read()), 'lxml')
if html.html:
# Remove html and body tags
html.html.hidden = True
html.body.hidden = True
meta = md.Meta
if not meta.get('type'):
meta['type'] = [self.default_post_type]
posts.append((html, meta, f))
if not posts:
print('warning: Nothing to publish')
return posts
else:
raise OSError(errno.ENOENT, strerror(errno.ENOENT), fpath)
评论列表
文章目录