def on_files_changed(self, changed): split_map = {} for root in self._roots(): path = os.path.join(content_folder(), root) split_map[root] = changed.filter(path) for root in split_map.keys(): processor = self.processor_factory(root) processor.on_files_changed(split_map[root])
def notify_new_files(changed): """Sends out a notification about new blog files to social networks""" if cfg('YAWT_NOTIFY_HOSTS') and \ socket.gethostname() not in cfg('YAWT_NOTIFY_HOSTS'): return cat_paths = [] for cat in cfg('YAWT_NOTIFY_CATEGORIES'): cat_paths.append(os.path.join(content_folder(), cat)) for added in changed.content_changes().added: for cpath in cat_paths: if added.startswith(cpath): _post_notification(added)
def _add_tags_for_indexed_article(indexed_file, edit): root_dir = current_app.yawt_root_dir if not indexed_file.startswith(content_folder()): print("file must be in content folder") return searcher = _whoosh().searcher docnums = searcher.document_numbers(fullname=fullname(indexed_file)) keywords = [keyword for keyword, _ in searcher.key_terms(docnums, "content", numterms=3)] keyword_str = ",".join(keywords) print("Tags: "+keyword_str) if edit: abs_article_file = os.path.join(root_dir, indexed_file) post = frontmatter.load(abs_article_file) post['tags'] = keyword_str save_file(abs_article_file, frontmatter.dumps(post))
def _post_and_save(post, networks, link): metadata = post_social(post, networks, link) now = datetime.datetime.utcnow() metadata.update({'create_time': now.isoformat(), 'modified_time': now.isoformat()}) tags = _extract_tags(post) if tags: metadata['tags'] = ','.join(tags) root_dir = g.site.root_dir repo_category = os.path.join(content_folder(), cfg('YAWT_MICROPOST_CATEGORY')) ensure_path(os.path.join(root_dir, repo_category)) slug = "{0:02d}{1:02d}{2:02d}{3:02d}{4:02d}{5:02d}" slug = slug.format(now.year, now.month, now.day, now.hour, now.minute, now.second) repo_file = os.path.join(repo_category, slug) repo_file += "." + cfg('YAWT_MICROPOST_EXTENSION') write_post(metadata, post, os.path.join(root_dir, repo_file)) return repo_file