First commit

This commit is contained in:
uid 2017-10-30 20:58:15 +01:00
commit 7b41841dd2
2 changed files with 67 additions and 0 deletions

65
ciclostile.py Executable file
View File

@ -0,0 +1,65 @@
#!/usr/bin/env python3
import os
import markdown
import jinja2
template_file = 'template.html'
md_path = './markdown'
html_path = './html'
def write_page(page, out_name):
out_path = os.path.join(html_path, out_name)
with open(out_path, 'w') as f:
f.write(page)
def render_page(data):
with open(template_file) as f:
template = f.read()
page = jinja2.Template(template).render(**data)
write_page(page, data['file_name'])
def read_md(md_file):
full_name = os.path.join(md_path, md_file)
with open(full_name) as f:
md_text = f.read()
return md_text
def make_page(md_file):
md_text = read_md(md_file)
md = markdown.Markdown(extensions=['meta'], output_format='html5')
html = md.convert(md_text)
# get markdown metadata
data = {key: md.Meta[key][0]
for key in md.Meta.keys()}
out_name = os.path.splitext(md_file)[0] + '.html'
data.update({
'content': html,
'file_name': out_name,
})
return data
def valid_md(md_file):
full_name = os.path.join(md_path, md_file)
return os.path.isfile(full_name) and full_name.endswith('.md')
def main():
for md_file in os.listdir(md_path):
if valid_md(md_file):
page = make_page(md_file)
render_page(page)
if __name__ == '__main__':
main()

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
markdown
jinja2