Files
ola5doc/publi/publi.py
T
2018-03-16 14:15:04 +01:00

120 lines
3.2 KiB
Python
Executable File

#!/usr/bin/python
# -*- coding: utf-8 -*-
# @Author: Bachir Soussi Chiadmi <bach>
# @Date: 11-04-2017
# @Email: bachir@figureslibres.io
# @Last modified by: bach
# @Last modified time: 18-04-2017
# @License: GPL-V3
import sys, os, getopt
import markdown
import re
import markdown
import pypandoc
print("OLA#5 publication generator")
output_md = '<div class="page">\n'
output_md += "# OLA5 Algolittéraire Publication\n\n"
output_md += '</div>\n'
content_dir = '../content'
for d in os.listdir(content_dir):
if not d.startswith('.') and d != 'model':
pres_path = os.path.join(content_dir, d, "publi.textile")
if os.path.isfile(pres_path):
print('\n**',d,'**')
pres_f = open(pres_path)
pres_txt = pres_f.read()
pres_f.close()
# print(pres_txt)
meta_match = re.match(r'---(.*)---', pres_txt, re.DOTALL)
# meta = meta_match.group(0)
if meta_match:
output_md += '<div class="page">\n'
output_md += '<div class="info">\n'
output_md += '<div class="info_left">\n'
meta = meta_match.group(0)
author_match = re.search(r'Author: (.+)', meta)
author = author_match.group(1) if author_match else "missing"
# print('author:', author)
title_match = re.search(r'Title: (.+)', meta)
title = title_match.group(1) if title_match else "missing"
# print('title:', title)
src_match = re.search(r'Src: (.+)', meta)
src = src_match.group(1) if src_match else "missing"
print('src:', src)
pres = pres_txt.replace(meta_match.group(0), '').strip()
# print('pres:',pres)
output_md += "\n\n## "+title
output_md += "\n\n### "+author
output_md += '\n\n</div>\n'
output_md += '<div class="info_right">\n'
output_md += "\n\n*"+pres+"*"
output_md += '\n\n</div>\n'
output_md += '\n\n</div>\n'
export_path = os.path.join(content_dir,d, src)
print('export_path:', export_path)
if os.path.isfile(export_path):
with open(export_path, 'r', encoding="utf8") as export_f:
output_md += "\n\n"+export_f.read()
output_md += '\n\n</div>\n'
# print('output_md:\n', output_md)
with open('publi.md', 'w') as md_f:
md_f.write(output_md)
pdoc_args = ['--mathjax']
pdoc_filters = []
output_html = pypandoc.convert('publi.md',
to='html5',
format='markdown+header_attributes+link_attributes+bracketed_spans',
extra_args=pdoc_args,
filters=pdoc_filters)
# outputfile=out_f)
# print(output_html)
index_html = "<html>\n \
\t<head>\n \
\t\t<meta charset='utf-8'>\n"
index_html += "<link rel='stylesheet' href='/fonts/cmu-Serif/cmun-serif.css'>"
with open('css/main.css', 'r', encoding="utf8") as css_f:
index_html += "\n\n"+css_f.read()
index_html += "\t</head>\n \
\t<body>\n \
\t\t<div id='root'>"
index_html += output_html
index_html += "\n</div>\n</body>\n \
</html>"
with open('index.html', 'w') as html_f:
html_f.write(index_html)