#!/usr/bin/env python
import argparse, json, sys, markdown, shutil, json, re, pathlib, shutil
import utils.imgconv
input_dir = None
output_dir = None
style = None
(W, H, FMT) = (None, None, None)
codebase = pathlib.Path(__file__).parent.absolute()
def translate_index_header(txt, dirname):
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('- - -')
text_md = markdown.markdown(text)
link_info = json.loads(link)
dirpath = pathlib.Path(dirname)
img_name = pathlib.Path(link_info['img']).name
img_path = dirpath / img_name
img_resize_path = dirpath / "img-resize" / img_name
picture_el = emit_picture(str(img_path), str(img_resize_path))
table = codebase / "templates/
"
with table.open(encoding="utf-8") as fp:
out = fp.read()
out = out.replace('[[text_md]]', text_md);
out = out.replace('[[link_md]]', picture_el);
if link_info['href']:
if link_info['href'] == "data":
href = dirname + "/"
else:
href = link_info['href']
out = "" + out + "";
return out
def escape_date(dirname):
return re.sub('^20\d{2}?.', '', dirname)
def emit_picture(src_full, src_resize):
return f'''
'''
def emit_img(file: pathlib.Path, data_dir: pathlib.Path):
## this is where LOD can be applied
resize_dir = data_dir / "img-resize"
resize_dir.mkdir(parents=True, exist_ok=True)
filepath = data_dir / file
resize_file = utils.imgconv.convert(filepath, (W, H, FMT), resize_dir)
return f'' + emit_picture(str(file), "img-resize/" + resize_file.name) + ''
def emit_video_mp4(file: pathlib.Path, data_dir: pathlib.Path):
return f'