def _fix_dates_for_article(repofile): abs_article_file = os.path.join(current_app.yawt_root_dir, repofile) post = frontmatter.load(abs_article_file) now = _now() if 'create_time' not in post.metadata: post['create_time'] = now post['modified_time'] = now save_file(abs_article_file, frontmatter.dumps(post, Dumper=ExplicitDumper))
def test_make_article_fills_basic_info(self): save_file('/tmp/stuff/article_file.txt', 'blah') article = make_article('stuff/article_file', '/tmp/stuff/article_file.txt') self.assertEquals('stuff/article_file', article.info.fullname) self.assertEquals('stuff', article.info.category) self.assertEquals('article_file', article.info.slug) self.assertEquals('txt', article.info.extension) self.assertEquals('blah', article.content)
def test_make_article_has_no_content_when_file_is_empty(self): save_file('/tmp/stuff/article_file.txt', '') article = make_article('stuff/article_file', '/tmp/stuff/article_file.txt') self.assertEquals('stuff/article_file', article.info.fullname) self.assertEquals('stuff', article.info.category) self.assertEquals('article_file', article.info.slug) self.assertEquals('txt', article.info.extension) self.assertEquals('', article.content)
def _add_tags_for_article(repofile, searcher): abs_article_file = os.path.join(current_app.yawt_root_dir, repofile) post = frontmatter.load(abs_article_file) if 'tags' not in post.metadata: keywords = [keyword for keyword, _ in searcher.key_terms_from_text("content", post.content, numterms=3)] keyword_str = ",".join(keywords) usertags = input('Enter tags (default '+keyword_str+'): ') tags = usertags or keyword_str post['tags'] = tags save_file(abs_article_file, frontmatter.dumps(post))
def test_make_article_loads_date_types_as_int(self): article_text = """--- date: 2015-05-16 01:52:57.906737 --- blah """ save_file('/tmp/stuff/article_file.txt', article_text) article = make_article('stuff/article_file', '/tmp/stuff/article_file.txt', meta_types={'date': 'iso8601'}) self.assertTrue(isinstance(article.info.date, int))
def test_make_article_loads_list_typed_metadata(self): article_text = """--- tags: tag1,tag2,tag3 --- blah """ save_file('/tmp/stuff/article_file.txt', article_text) article = make_article('stuff/article_file', '/tmp/stuff/article_file.txt', meta_types={'tags': 'list'}) self.assertTrue(article.info.tags, ['tag1', 'tag2', 'tag3'])
def initialize(self): self.site_root = tempfile.mkdtemp() for folder in self.folders: os.makedirs(os.path.join(self.site_root, folder)) for the_file in self.files.keys(): abs_filename = os.path.join(self.site_root, the_file) content = self.files[the_file] if isinstance(content, tuple): save_file(abs_filename, dump_post(content[0], content[1])) else: save_file(abs_filename, content)
def test_make_article_loads_simple_metadata(self): article_text = """--- title: this is a title count: 76 foo: [5, 'dd'] --- blah """ save_file('/tmp/stuff/article_file.txt', article_text) article = make_article('stuff/article_file', '/tmp/stuff/article_file.txt') self.assertTrue(article.info.title, 'this is a title') self.assertTrue(article.info.count, 76) self.assertTrue(article.info.foo, [5, 'dd'])
def initialize(self): """Set up an empty blog folder""" if os.path.exists(self.root_dir): raise SiteExistsError(self.root_dir) ensure_path(self._content_root()) ensure_path(self._draft_root()) ensure_path(self._template_root()) config_content = '# put configuration here' save_file(os.path.join(self.root_dir, 'config.py'), config_content) template_contents = yawt.default_templates.default_article_template self._save_template('article', 'html', template_contents) template_404_contents = yawt.default_templates.default_404_template self._save_template('404', 'html', template_404_contents) files = ['config.py', 'article.html', '404.html'] return call_plugins_arg('on_new_site', files)
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 setUp(self): self.old_facebook = yawtext.facebook.facepy yawtext.facebook.facepy = fake_facebook fake_facebook.clear() save_file('/tmp/fbtoken', access_token)
def setUp(self): self.old_tweepy = yawtext.twitter.tweepy yawtext.twitter.tweepy = fake_tweepy fake_tweepy.clear() save_file('/tmp/twittercred.yml', twittercred)
def save_state_file(self, rel_filename, content=''): abs_state_file = os.path.join(self.state_root, rel_filename) save_file(abs_state_file, content)
def save_template(self, rel_filename, template=''): abs_template_file = os.path.join(self.abs_template_root(), rel_filename) save_file(abs_template_file, template)
def save_content(self, rel_filename, content=''): abs_content_file = os.path.join(self.abs_content_root(), rel_filename) save_file(abs_content_file, content)
def _save_summary(self): save_file(self._abs_summary_file(), jsonpickle.encode(self.summary))
def on_new_site(self, files): """When a new site is created, we'll save a gitignore file so we can ignore the _state directory """ filename = os.path.join(current_app.yawt_root_dir, vc_ignore_file()) save_file(filename, '_state')
def test_make_article_loads_file_metadata(self): save_file('/tmp/stuff/article_file.txt', 'blah') article = make_article('stuff/article_file', '/tmp/stuff/article_file.txt') self.assertTrue(isinstance(article.info.create_time, float)) self.assertTrue(isinstance(article.info.modified_time, float))
def save_file(self, repofile, contents): save_file(os.path.join(self.site_root, repofile), contents)
def _save_template(self, name, flavour, contents): save_file(self._template_ext2file(name, flavour), contents)