45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
from pprint import pp
|
|
from pathlib import Path
|
|
import re
|
|
|
|
src = Path('src')
|
|
views = src.joinpath('views')
|
|
template = views.joinpath('template')
|
|
module = views.joinpath('module')
|
|
|
|
static = Path('src', 'static')
|
|
|
|
dist = Path('dist')
|
|
dist.mkdir(exist_ok=True)
|
|
|
|
for x in dist.rglob('*'):
|
|
if x.is_file() or x.is_symlink(): x.unlink()
|
|
for x in dist.rglob('*/'): x.rmdir()
|
|
|
|
def read(file_path):
|
|
with file_path.open() as html_file:
|
|
return (file_path.stem, html_file.read())
|
|
|
|
templates = dict(map(read, template.glob('*.html')))
|
|
modules = dict(map(read, module.glob('*.html')))
|
|
|
|
def format(item, modules):
|
|
name, content = item
|
|
|
|
return (name, re.sub('\n\s*', '', content.format(**modules)))
|
|
|
|
dist_html = dict(map(lambda item: format(item, modules), templates.items()))
|
|
|
|
def mk_dist(dist, item):
|
|
key, content = item
|
|
path = dist
|
|
if key != 'index':
|
|
path = dist.joinpath(key)
|
|
path.mkdir(exist_ok=True)
|
|
with path.joinpath('index.html').open('w') as index:
|
|
index.write(content)
|
|
|
|
for item in dist_html.items():
|
|
mk_dist(dist, item)
|
|
|
|
dist.joinpath('static').symlink_to(static.resolve(strict=True), target_is_directory=True)
|