#!/usr/bin/python # -*- coding: utf-8 -*- # @Author: Bachir Soussi Chiadmi # @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 = '
\n' output_md += "# OLA5 Algolittéraire Publication\n\n" output_md += '
\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 += '
\n' output_md += '
\n' output_md += '
\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
\n' output_md += '
\n' output_md += "\n\n*"+pres+"*" output_md += '\n\n
\n' output_md += '\n\n
\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
\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 = "\n \ \t\n \ \t\t\n" index_html += "" with open('css/main.css', 'r', encoding="utf8") as css_f: index_html += "\n\n"+css_f.read() index_html += "\t\n \ \t\n \ \t\t
" index_html += output_html index_html += "\n
\n\n \ " with open('index.html', 'w') as html_f: html_f.write(index_html)