def _build_tags(self, tags): """ :type tags: list[(str, list[Post])] """ output_dir = os.path.join(self._site_dir, "tag") ensure_dir_exists(output_dir) template = self._jinja.get_template("tag.html") tq = tqdm.tqdm(total=len(tags)) for tag, posts in tags: posts.sort(key=lambda p: p.published, reverse=True) html = template.render(name=tag, posts=posts) filepath = os.path.join(output_dir, "%s.html" % tag) write_file(filepath, html) tq.update(1) tq.close() # taglist taglist = [(tag, len(posts)) for tag, posts in tags] taglist.sort(key=lambda item: (item[1], item[0]), reverse=True) template = self._jinja.get_template("taglist.html") html = template.render(tags=taglist) filepath = os.path.join(self._page_dir, "tags.html") write_file(filepath, html)
def _build_tags(self, tags): """ :type tags: dict[unicode, list[Post]] """ output_dir = os.path.join(self._site_dir, "tag") ensure_dir_exists(output_dir) template = self._jinja.get_template("tag.html") taglist = {} tq = tqdm.tqdm(total=len(tags)) for tag, posts in tags.items(): taglist[tag] = len(posts) posts.sort(key=lambda p: p.published, reverse=True) html = template.render(name=tag, posts=posts) filepath = os.path.join(output_dir, "%s.html" % tag) write_file(filepath, html) tq.update(1) tq.close() # taglist taglist = sorted(taglist.items(), key=lambda item: (item[1], item[0]), reverse=True) template = self._jinja.get_template("taglist.html") html = template.render(tags=taglist) filepath = os.path.join(self._page_dir, "tags.html") write_file(filepath, html)
def _build_pickys(self, pickys): output_dir = os.path.join(self._site_dir, "picky") ensure_dir_exists(output_dir) template = self._jinja.get_template("picky.html") for picky in tqdm.tqdm(pickys): html = template.render(picky=picky) filepath = os.path.join(output_dir, "%s.html" % picky.slug) write_file(filepath, html)
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()