summaryrefslogtreecommitdiff
path: root/cli/app/site/export.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-03-17 18:11:26 +0100
committerJules Laplace <julescarbon@gmail.com>2021-03-17 18:11:26 +0100
commitd165a0727e42349d935ab3ee287242f1e5029742 (patch)
treeb4fa68209127efdd4eb46c82eaef280535692611 /cli/app/site/export.py
parent92566ba17f5e921d5bff1f3fb4e4b0d92ca4fd39 (diff)
frontend. export/view button. interactivity sanity check
Diffstat (limited to 'cli/app/site/export.py')
-rw-r--r--cli/app/site/export.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/cli/app/site/export.py b/cli/app/site/export.py
index d513286..c301a60 100644
--- a/cli/app/site/export.py
+++ b/cli/app/site/export.py
@@ -8,7 +8,7 @@ import os
from app.sql.common import db, Session, Graph, Page, Tile
from distutils.dir_util import copy_tree
-def export_site(ctx, opt_graph_path, opt_output_dir):
+def export_site(opt_graph_path, opt_output_dir=app_cfg.DIR_EXPORTS, opt_build_js=False):
"""Export a graph"""
# ------------------------------------------------
@@ -42,6 +42,7 @@ def export_site(ctx, opt_graph_path, opt_output_dir):
home_page = site_data['graph']['home_page']
if home_page is None:
print("Homepage not set! Shift-click a page on the graph to make it the homepage.")
+ session.close()
return
write_text(f'<meta http-equiv="refresh" content="0; url={home_page}">', join(graph_dir, 'index.html'))
@@ -55,8 +56,10 @@ def export_site(ctx, opt_graph_path, opt_output_dir):
print(f'/{page_path}')
write_index(graph, page, index_html, join(graph_dir, page.path, 'index.html'))
- build_javascript(graph_dir)
+ if opt_build_js or not os.path.exists(f"{graph_dir}/bundle.js"):
+ build_javascript(graph_dir)
+ session.close()
print("Site export complete!")
print(f"Graph exported to: {graph_dir}")
@@ -86,22 +89,34 @@ def sanitize_graph(graph):
page_path_lookup[page['id']] = page_path
for page in graph['pages']:
sanitize_page(page)
- if page['id'] == 12:
- print(page)
for tile in page['tiles']:
if tile['target_page_id']:
if tile['target_page_id'] == -1:
tile['href'] = tile['settings']['external_link_url']
elif tile['target_page_id'] > 0:
tile['href'] = page_path_lookup[tile['target_page_id']]
+ if 'url' in tile['settings'] and tile['settings']['url'].startswith('/static'):
+ tile['settings']['url'] = '/' + graph['path'] + tile['settings']['url']
sanitize_tile(tile)
page_path = page_path_lookup[page['id']]
page_lookup[page_path] = page
+ for upload in graph['uploads']:
+ sanitize_upload(upload)
+ if upload['url'].startswith('/static'):
+ upload['url'] = '/' + graph['path'] + upload['url']
# print(page_lookup['/asdf/testttt'])
graph['pages'] = page_lookup
graph['home_page'] = page_path_lookup[graph['home_page_id']]
return graph
+def sanitize_upload(data):
+ if 'created_at' in data:
+ del data['created_at']
+ if 'username' in data:
+ del data['username']
+ if 'graph_id' in data:
+ del data['graph_id']
+
def sanitize_page(data):
if 'created_at' in data:
del data['created_at']