add function to create the header
This commit is contained in:
parent
1b1cc27c27
commit
ccda71858e
|
@ -10,3 +10,11 @@ def test_undefined_topics(create_article):
|
|||
def test_get_topics_from_cli():
|
||||
header._get_topics_from_cli()
|
||||
assert False
|
||||
|
||||
|
||||
def test_dict_to_string(create_article):
|
||||
article = create_article()
|
||||
article.keywords = ['foo', 'bar', 'baz']
|
||||
raw_header = header._build_header_dict(article)
|
||||
string = header._build_header_string(raw_header)
|
||||
assert string =='- meta:\n - topics: [[foo]] [[bar]] [[baz]]\n - authors: [[Daniel Waldmeier]] [[Kei Zuefall]]\n'
|
||||
|
|
|
@ -8,12 +8,27 @@ def _build_header_dict(article):
|
|||
if article.authors:
|
||||
header['authors'] = article.authors
|
||||
if article.keywords:
|
||||
header['topics'].append(article.keywords)
|
||||
if header['topics']:
|
||||
header['topics'].append(article.keywords)
|
||||
else:
|
||||
header['topics'] = article.keywords
|
||||
if not header['topics']:
|
||||
header['topics'] = ['to_categorise']
|
||||
return header
|
||||
|
||||
|
||||
def build_header(header):
|
||||
yaml = ""
|
||||
return yaml
|
||||
def _build_header_string(raw_header):
|
||||
header = "- meta:\n"
|
||||
for key, value in raw_header.items():
|
||||
if key:
|
||||
content = ""
|
||||
for child in value:
|
||||
content += " [[" + child + "]]"
|
||||
header += " - {0}:".format(key) + content + "\n"
|
||||
return header
|
||||
|
||||
|
||||
def build_header(article):
|
||||
raw_header = _build_header_dict(article)
|
||||
header = _build_header_string(raw_header)
|
||||
return header
|
||||
|
|
Loading…
Reference in New Issue