diff options
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/commands/site/export.py | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/cli/commands/site/export.py b/cli/commands/site/export.py index cf6be7b..d715c6c 100644 --- a/cli/commands/site/export.py +++ b/cli/commands/site/export.py @@ -3,6 +3,7 @@ import click from app.settings import app_cfg from app.utils.file_utils import load_text, write_json, write_text from os.path import join +import os @click.command('info') @click.option('-g', '--graph', 'opt_graph_path', required=True, @@ -17,6 +18,7 @@ def cli(ctx, opt_graph_path, opt_output_dir): # imports from app.sql.common import db, Session, Graph, Page, Tile + from distutils.dir_util import copy_tree # ------------------------------------------------ # generate HTML for index and all pages @@ -27,16 +29,30 @@ def cli(ctx, opt_graph_path, opt_output_dir): print(f"Not a graph: {opt_graph_path}") return - print(f"Output site to {opt_output_dir}") + # build everything here + graph_dir = join(opt_output_dir, graph.path) + # load site index + index_html = load_text(join(app_cfg.DIR_STATIC, 'site.html'), split=False) + index_html = index_html.replace('SITE_PATH', '/' + graph.path) + + # write site JSON data site_data = { 'graph': sanitize_graph(graph.toSiteJSON()) } + write_json(site_data, join(graph_dir, 'index.json'), default=str) - index_html = load_text(join(app_cfg.DIR_STATIC, 'site.html'), split=False) - write_json(site_data, join(opt_output_dir, graph.path, 'index.json'), default=str) - # write_index(graph, None, index_html, join(opt_output_dir, graph.path, 'index.html')) + # 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) + 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')) + # write index file, redirects to homepage home_page = site_data['graph']['home_page'] - write_text(f'<meta http-equiv="refresh" content="0; url={home_page}">', join(opt_output_dir, graph.path, 'index.html')) + if home_page is None: + print("Homepage not set! Shift-click a page on the graph to make it the homepage.") + return + write_text(f'<meta http-equiv="refresh" content="0; url={home_page}">', join(graph_dir, 'index.html')) index_path = "" for page in graph.pages: @@ -46,12 +62,18 @@ def cli(ctx, opt_graph_path, opt_output_dir): print(f'/{page_path} [index]') else: print(f'/{page_path}') - write_index(graph, page, index_html, join(opt_output_dir, graph.path, page.path, 'index.html')) + write_index(graph, page, index_html, join(graph_dir, page.path, 'index.html')) # ------------------------------------------------ - # generate javascript... + # build javascript + + print("Building javascript...") + print(f'NODE_ENV=production webpack --config ./webpack.config.site.js -o {graph_dir}/bundle.js') + os.chdir(app_cfg.DIR_PROJECT_ROOT) + os.system(f'NODE_ENV=production webpack --config ./webpack.config.site.js -o {graph_dir}/bundle.js') - # NODE_ENV=production webpack --config ./webpack.config.site.js -o ./data_store/exports/asdf/bundle.js + print("Site export complete!") + print(f"Graph exported to: {graph_dir}") def write_index(graph, page, index_html, fp_out): if page is None: |
