diff --git a/app.py b/app.py index de3ae9b..dba077d 100644 --- a/app.py +++ b/app.py @@ -71,6 +71,14 @@ def logout(): resp.delete_cookie("bfa_user") return resp +@app.route("/api/v1html", methods=["GET"]) +def api_v1html(): + html_path = os.path.join(LAYOUT_DIR, "v1_converted.html") + if os.path.exists(html_path): + with open(html_path) as f: + return f.read(), 200, {'Content-Type': 'text/html'} + return "", 404 + @app.route("/api/layout", methods=["GET"]) def api_get_layout(): return jsonify(get_layout()) diff --git a/templates/editor.html b/templates/editor.html index 45201c5..5d14685 100644 --- a/templates/editor.html +++ b/templates/editor.html @@ -254,12 +254,19 @@ function exportProject() { try { const resp = await fetch('api/layout'); const data = await resp.json(); - // Check if it's V2 (GrapesJS) or V1 (old format) - if (data.assets || data.styles || data.pages) { + if (data.assets || data.styles || (data.pages && data.pages.length && data.pages[0].frames)) { + // V2 GrapesJS project — load it editor.loadProjectData(data); } else { - // V1 layout — start fresh with default canvas content - console.log('V1 layout detected — starting fresh GrapesJS project'); + // No V2 yet — try loading converted V1 HTML + try { + const htmlResp = await fetch('api/v1html'); + const html = await htmlResp.text(); + if (html && html.length > 10) { + editor.setComponents(html); + console.log('Loaded V1 converted layout'); + } + } catch(e2) { console.log('No V1 HTML either, starting blank'); } } } catch(e) { console.log('No saved layout, starting fresh'); } })();