def save_to_bloom(article: Article, doc: MarkdownDoc) -> None: if article.path.exists(): print(f'Error: article path already exists: {article.path}', file=sys.stderr) return article.save_meta() article.save_doc(doc) print(f'Saved article {article.path}')
def publish(article: Article, platform: Optional[str] = None, to: Optional[str] = None): print('publishing', article.path) assert platform is not None or to is not None platform: str = platform if platform is not None else to try: platform: Platform = Platform(platform) except ValueError as e: eprint(f'Error: {str(e)}') exit(1) doc = article.read_doc() if platform not in platform_processes: eprint(f"Error: no process defined for platform '{platform.value}'") exit(1) process = platform_processes[platform] for t in process.transfers: doc = t(article, doc) process.save(article, doc)
def publish(self, article_path: str, platform: Optional[str] = None, to: Optional[str] = None): article_path: Path = Path(article_path) article = Article.open(article_path) publish(article, platform, to)
def upload(self, directory: str = '.', to: str = 'none', all=False): article = Article.open(Path(directory)) upload(article, to, all)
def status(self, directory: str = '.'): article = Article.open(Path(directory)) article.status()
def publish(article: Article, platform: Optional[str] = None, to: Optional[str] = None): print('publishing', article.path) assert platform is not None or to is not None platform: str = platform if platform is not None else to try: platform: Platform = Platform(platform) except ValueError as e: eprint(f'Error: {str(e)}') exit(1) doc = article.read_doc() if platform not in platform_processes: eprint(f"Error: no process defined for platform '{platform.value}'") exit(1) process = platform_processes[platform] for t in process.transfers: doc = t(article, doc) process.save(article, doc) if __name__ == '__main__': article_path = get_bloomstore() / 'LeetCode 例题精讲/03-从二叉树遍历到回溯算法' publish(Article.open(article_path), platform='xzl')
def construct_article(dest: Path, meta: MetaInfo) -> Article: article_path = dest / meta.base.titleCn return Article(path=article_path, meta=meta)