generating index.html

andre
Castro0o 4 years ago
parent 391b85041d
commit 3f2b6c7473

@ -63,14 +63,17 @@ with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd
site.login(username=user, password=pwd) # login to wiki
# read template files
with open(os.path.join(wd, 'templates/document.html')) as pub_html:
pub_template = Template(pub_html.read())
with open(os.path.join(wd, 'templates/index.html')) as document_html:
index_template = Template(document_html.read())
with open(os.path.join(wd, 'templates/document_part.html')) as pub_html:
pub_part_template = Template(pub_html.read())
with open(os.path.join(wd, 'templates/document.html')) as document_html:
document_template = Template(document_html.read())
all_document_parts = '' # to append all content
with open(os.path.join(wd, 'templates/document_part.html')) as document_html:
document_part_template = Template(document_html.read())
all_document_parts = '' # to append all content
documentslist = []
for answer in site.ask(query):
publication_title = ''
# print(answer, answer.keys())
@ -87,19 +90,32 @@ for answer in site.ask(query):
pagetext_html = pandoc(pwd=wd, content=pagetext, format_in='mediawiki', format_out='html')
img_local = os.path.join(imgdir, img_info.get('filename'))
# render html for that part of the document
document_part_html = pub_part_template.render(
document_part_html = document_part_template.render(
printout_dict=printout_dict,
imgsrc=os.path.join(imgdir, img_info.get('filename')),
text=pagetext_html,
fullurl=fullurl,)
all_document_parts += document_part_html # append resulting html from document part to the previous parts
if printout_dict['Part'] == printout_dict['Partof']: # when Part == Partof
# pass all_document_parts html to pub_template content
pub_html = pub_template.render(title=printout_dict.get('Title'),
# pass all_document_parts html to document_template content
document_html = document_template.render(title=printout_dict.get('Title'),
date=printout_dict.get('Date'),
content=all_document_parts) # render document template
htmlpage_fn = "{}.html".format(printout_dict.get('Title').replace(" ", ""))
documentslist.append({'file': htmlpage_fn,
'title': printout_dict.get('Title'),
'date': printout_dict.get('Date')
})
# print(documentslist)
with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile:
htmlfile.write(pub_html)
htmlfile.write(document_html)
all_document_parts = '' # Reset all_document_parts
index_html = index_template.render(index='Index',
documentslist=documentslist)
with open(os.path.join(static_html, 'index.html'), 'w') as htmlfile:
htmlfile.write(index_html)

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{title}}</title>
</head>
<body>
<ul>
{% for doc in documentslist %}
<li><a href="./{{ doc['file'] }}">{{ doc['title'] }}</a>
{{ doc['date'].year }}.{{ doc['date'].month }}.{{ doc['date'].day }}
</li>
{% endfor %}
</ul>
</body>
</html>
Loading…
Cancel
Save