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():
|
def test_get_topics_from_cli():
|
||||||
header._get_topics_from_cli()
|
header._get_topics_from_cli()
|
||||||
assert False
|
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:
|
if article.authors:
|
||||||
header['authors'] = article.authors
|
header['authors'] = article.authors
|
||||||
if article.keywords:
|
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']:
|
if not header['topics']:
|
||||||
header['topics'] = ['to_categorise']
|
header['topics'] = ['to_categorise']
|
||||||
return header
|
return header
|
||||||
|
|
||||||
|
|
||||||
def build_header(header):
|
def _build_header_string(raw_header):
|
||||||
yaml = ""
|
header = "- meta:\n"
|
||||||
return yaml
|
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