core.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:pipesicle 作者: anqurvanillapy 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号