diff options
Diffstat (limited to 'cli/app')
| -rw-r--r-- | cli/app/settings/app_cfg.py | 1 | ||||
| -rw-r--r-- | cli/app/site/export.py | 33 |
2 files changed, 27 insertions, 7 deletions
diff --git a/cli/app/settings/app_cfg.py b/cli/app/settings/app_cfg.py index 4aa4bee..de52311 100644 --- a/cli/app/settings/app_cfg.py +++ b/cli/app/settings/app_cfg.py @@ -51,6 +51,7 @@ DIR_DATA_STORE = join(DIR_APP, 'data_store') DIR_DATABASE = join(DIR_DATA_STORE, 'db') DIR_UPLOADS = join(DIR_DATA_STORE, 'uploads') DIR_EXPORTS = join(DIR_DATA_STORE, 'exports') +DIR_CONTENT = join(DIR_DATA_STORE, 'content') DIR_DOCS = join(DIR_APP, 'docs') diff --git a/cli/app/site/export.py b/cli/app/site/export.py index 354c0a5..d5027e6 100644 --- a/cli/app/site/export.py +++ b/cli/app/site/export.py @@ -24,9 +24,13 @@ def export_site(opt_graph_path, opt_output_dir=app_cfg.DIR_EXPORTS, opt_build_js graph_dir = os.path.abspath(join(opt_output_dir, graph.path)) # load site index + custom_header, custom_content, custom_footer = load_custom_content(graph) index_html = load_text(join(app_cfg.DIR_STATIC, 'site.html'), split=False) - index_html = index_html.replace('CUSTOM_HEADER', graph.settings.get('custom_header', '')) - index_html = index_html.replace('SITE_PATH', '/' + graph.path) + index_html = index_html.replace('{{CUSTOM_HEADER}}', custom_header) + index_html = index_html.replace('{{CUSTOM_FOOTER}}', custom_footer) + index_html = index_html.replace('{{SITE_PATH}}', '/' + graph.path) + site_index_html = index_html.replace('{{CUSTOM_CONTENT}}', custom_content) + page_index_html = index_html.replace('{{CUSTOM_CONTENT}}', "") # write site JSON data site_data = { 'graph': sanitize_graph(graph.toSiteJSON()) } @@ -34,7 +38,7 @@ def export_site(opt_graph_path, opt_output_dir=app_cfg.DIR_EXPORTS, opt_build_js # import custom css site_css = load_text(join(app_cfg.DIR_STATIC, 'site.css'), split=False) - site_css = site_css.replace('SITE_PATH', '/' + graph.path) + site_css = site_css.replace('{{SITE_PATH}}', '/' + graph.path) write_text(site_css, join(graph_dir, 'site.css')) copy_tree(join(app_cfg.DIR_STATIC, 'fonts'), join(graph_dir, 'static/fonts')) copy_tree(join(app_cfg.DIR_STATIC, 'img'), join(graph_dir, 'static/img')) @@ -46,7 +50,7 @@ def export_site(opt_graph_path, opt_output_dir=app_cfg.DIR_EXPORTS, opt_build_js session.close() return # write_text(f'<meta http-equiv="refresh" content="0; url={home_page}">', join(graph_dir, 'index.html')) - write_index(graph=graph, page=None, index_html=index_html, fp_out=join(graph_dir, 'index.html')) + write_index(graph=graph, page=None, index_html=site_index_html, fp_out=join(graph_dir, 'index.html')) index_path = "" for page in graph.pages: @@ -56,7 +60,7 @@ def export_site(opt_graph_path, opt_output_dir=app_cfg.DIR_EXPORTS, opt_build_js print(f'/{page_path} [index]') else: print(f'/{page_path}') - write_index(graph, page, index_html, join(graph_dir, page.path, 'index.html')) + write_index(graph=graph, page=page, index_html=page_index_html, fp_out=join(graph_dir, page.path, 'index.html')) if opt_build_js or not os.path.exists(f"{graph_dir}/bundle.js"): build_javascript(graph_dir) @@ -71,13 +75,28 @@ def build_javascript(graph_dir): os.chdir(app_cfg.DIR_PROJECT_ROOT) os.system(f'NODE_ENV=production node ./node_modules/webpack-cli/bin/cli.js --config ./webpack.config.site.js -o {graph_dir}/bundle.js') +def load_custom_content(graph): + custom_header_path = join(app_cfg.DIR_CONTENT, graph.path, "header.html") + custom_content_path = join(app_cfg.DIR_CONTENT, graph.path, "content.html") + custom_footer_path = join(app_cfg.DIR_CONTENT, graph.path, "footer.html") + custom_header = graph.settings.get('custom_header', '') + custom_content = "" + custom_footer = "" + if os.path.exists(custom_header_path): + custom_header += "".join(load_text(custom_header_path)) + if os.path.exists(custom_content_path): + custom_content += "".join(load_text(custom_content_path)) + if os.path.exists(custom_footer_path): + custom_footer += "".join(load_text(custom_footer_path)) + return custom_header, custom_content, custom_footer + def write_index(graph, page, index_html, fp_out): if page is None: page_title = graph.title else: page_title = page.title - index_html = index_html.replace('BUNDLE_PATH', join('/', graph.path, 'bundle.js')) - index_html = index_html.replace('PAGE_TITLE', page_title) + index_html = index_html.replace('{{BUNDLE_PATH}}', join('/', graph.path, 'bundle.js')) + index_html = index_html.replace('{{PAGE_TITLE}}', page_title) write_text(index_html, fp_out) def sanitize_graph(graph): |
