forked from web/portal
replace hugo by a self provided python script
This commit is contained in:
46
build.py
Executable file
46
build.py
Executable file
@@ -0,0 +1,46 @@
|
||||
import codecs
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from distutils import dir_util
|
||||
from string import Template
|
||||
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
__location__ = os.path.realpath(os.path.dirname(__file__))
|
||||
static_folder = os.path.join(__location__, 'static')
|
||||
content_folder = os.path.join(__location__, 'content')
|
||||
output_folder = os.path.join(__location__, 'public')
|
||||
|
||||
config_file = sys.argv[1]
|
||||
|
||||
yaml = YAML(typ='safe')
|
||||
|
||||
with codecs.open(config_file, 'r', encoding='utf-8') as stream:
|
||||
try:
|
||||
config = yaml.load(stream)
|
||||
except yaml.YAMLError as exc:
|
||||
print(exc)
|
||||
exit(1)
|
||||
|
||||
template_item_text = codecs.open(os.path.join(content_folder, 'item.tmpl.html'), 'r',
|
||||
encoding='utf-8').read()
|
||||
template_item = Template(template_item_text)
|
||||
|
||||
items = ''
|
||||
|
||||
for config_item in config['items']:
|
||||
items += template_item.substitute(config_item)
|
||||
|
||||
template_page_text = codecs.open(os.path.join(content_folder, 'index.tmpl.html'), 'r', encoding='utf-8').read()
|
||||
template_page = Template(template_page_text)
|
||||
outcome = template_page.substitute(items=items)
|
||||
|
||||
os.makedirs(output_folder, exist_ok=True)
|
||||
|
||||
outfile_index = os.path.join(output_folder, 'index.html')
|
||||
|
||||
from distutils.dir_util import copy_tree
|
||||
copy_tree(static_folder, output_folder)
|
||||
|
||||
html = codecs.open(outfile_index, 'w', encoding='utf-8').write(outcome)
|
||||
Reference in New Issue
Block a user