#!/usr/bin/env python
import sys, os, string, markdown, argparse, shutil, json, glob, re
from distutils import dir_util as dirutil
arg_parser = argparse.ArgumentParser(description='Generates html file accroding to directory content');
input_dir = '../content/';
output_dir = '../deploy/';
def parse_args():
global input_dir, output_dir, clean
arg_parser.add_argument('--input', help='input directory');
arg_parser.add_argument('--output', help='output directory');
arg_parser.add_argument('--clean', help='cleans the output directory');
args = arg_parser.parse_args();
if args.input and os.path.isdir(args.input):
input_dir = args.input;
if args.output and os.path.isdir(args.output):
output_dir = args.output;
def translate_index_header(txt, dirname):
try:
table = open(os.path.join('.', '
'), 'r+');
except:
print('error opening file. aborting...');
sys.exit(0);
href = None
sections = txt.count('- - -');
if sections == 0:
# not following the normal template -> direct html
txt = txt.replace('data/', dirname + '/'); #<--- replace reference to data/
return txt
elif sections == 1:
[text, link] = txt.split('- - -');
elif sections == 2:
[text, link, href] = txt.split('- - -');
text_md = markdown.markdown(text);
link_md = markdown.markdown(link);
# revise this - perhaps with a better
link_md = link_md.replace('data/', dirname + '/');
out = table.read().replace('[[text_md]]', text_md);
out = out.replace('[[link_md]]', link_md);
if href:
href = href.replace('data/', dirname + '/');
out = "" + out + "";
return out
def escape_date(dirname):
return re.sub('^20\d{2}?.', '', dirname)
def emit_img(file, data_dir):
return '
'
def emit_video_mp4(file, data_dir):
return '