add indexing in compile_all

master
subnixr 2018-07-21 02:01:36 +02:00
parent 4c7839728d
commit 18c77e71f2
2 changed files with 26 additions and 17 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.egg-info *.egg-info
*.pyc *.pyc
test_site/

View File

@ -39,29 +39,30 @@ def compile(template, data):
def compile_all(root_path): def compile_all(root_path):
print('Compiling', root_path)
md_path = os.path.join(root_path, 'markdown') md_path = os.path.join(root_path, 'markdown')
files = [f template_path = os.path.join(root_path, 'templates')
for f in os.listdir(md_path) target_path = os.path.join(root_path, 'target')
if f.endswith('.md')]
data = {'pages': {}} data = {'pages': {}}
for fname in files: templates = {}
full_path = os.path.join(md_path, fname)
name, _ = os.path.splitext(fname) md_files = [f
for f in os.listdir(md_path)
if f.endswith('.md')]
template_files = [f
for f in os.listdir(template_path)
if f.endswith('.html')]
for md_fname in md_files:
full_path = os.path.join(md_path, md_fname)
name, _ = os.path.splitext(md_fname)
data['pages'][name] = parse_file(full_path) data['pages'][name] = parse_file(full_path)
template_path = os.path.join(root_path, 'templates') for file_name in template_files:
templates = {} full_path = os.path.join(template_path, file_name)
name, _ = os.path.splitext(file_name)
for file_name in os.listdir(template_path): templates[name] = full_path
name, ext = os.path.splitext(file_name)
if ext == '.html':
templates[name] = os.path.join(template_path, file_name)
target_path = os.path.join(root_path, 'target')
for page_name, page in data['pages'].items(): for page_name, page in data['pages'].items():
t_name = page.get('template', 'default') t_name = page.get('template', 'default')
@ -74,3 +75,10 @@ def compile_all(root_path):
with open(out_path, 'w') as f: with open(out_path, 'w') as f:
f.write(out) f.write(out)
with open(templates['index']) as fh:
index_template = jinja2.Template(fh.read())
out = index_template.render(**data)
out_path = os.path.join(target_path, 'index.html')
with open(out_path, "w") as f:
f.write(out)