def _parse_posts(self): index = {} posts = [] tags = {} post_dir = self._config_item_path("posts") for md in tqdm.tqdm(glob.glob(os.path.join(post_dir, "*.md"))): markdown = read_file(md) try: post = Post(markdown) except Exception as e: raise Exception("parse '%s', %s" % (md, e)) from None if post.slug in index: raise Exception("post %s and %s slug duplicate" % (index[post.slug], md)) index[post.slug] = md posts.append(post) # 私密文章不在 tag 列表里面出现 if post.slug in self._privacies: continue for tag in post.tags: tag = tag.lower() if tag in tags: tags[tag].append(post) else: tags[tag] = [post] posts.sort(key=lambda p: p.published, reverse=True) return posts, tags
def _parse_pickys(self): pickys = [] picky_dir = self._config_item_path("pickys") for md in tqdm.tqdm(glob.glob(os.path.join(picky_dir, "*.md"))): basename = os.path.basename(md) slug = basename.split(".")[0] markdown = read_file(md) try: picky = Picky(str(slug), markdown) except Exception as e: raise Exception("parse '%s', %s" % (md, e)) from None pickys.append(picky) return pickys
def __init__(self, config): """ :param config: path of config """ config_path = os.path.abspath(os.path.expanduser(config)) self.basedir = os.path.dirname(config_path) self.config = yaml.safe_load(read_file(config_path)) privacies = self.config.get("privacies") self._privacies = set(privacies) if privacies else {} self._site_dir = self._config_item_path("sites") self._page_dir = os.path.join(self._site_dir, "blog") ensure_dir_exists(self._page_dir) self._jinja = self._init_jinja()
def __init__(self, config): """ :param config: path of config """ config_path = os.path.abspath(os.path.expanduser(config)) self.basedir = os.path.dirname(config_path) self.config = yaml.load(read_file(config_path)) privacies = self.config.get("privacies") self._privacies = set(privacies) if privacies else {} self._site_dir = self._config_item_path("sites") self._page_dir = os.path.join(self._site_dir, "blog") ensure_dir_exists(self._page_dir) self._jinja = self._init_jinja()