Load V1 layout as initial GrapesJS content — no more blank canvas

This commit is contained in:
Richard Sauer 2026-04-08 17:53:54 +10:00
parent e544da537a
commit 4af8f488cd
2 changed files with 19 additions and 4 deletions

8
app.py
View File

@ -71,6 +71,14 @@ def logout():
resp.delete_cookie("bfa_user") resp.delete_cookie("bfa_user")
return resp 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"]) @app.route("/api/layout", methods=["GET"])
def api_get_layout(): def api_get_layout():
return jsonify(get_layout()) return jsonify(get_layout())

View File

@ -254,12 +254,19 @@ function exportProject() {
try { try {
const resp = await fetch('api/layout'); const resp = await fetch('api/layout');
const data = await resp.json(); const data = await resp.json();
// Check if it's V2 (GrapesJS) or V1 (old format) if (data.assets || data.styles || (data.pages && data.pages.length && data.pages[0].frames)) {
if (data.assets || data.styles || data.pages) { // V2 GrapesJS project — load it
editor.loadProjectData(data); editor.loadProjectData(data);
} else { } else {
// V1 layout — start fresh with default canvas content // No V2 yet — try loading converted V1 HTML
console.log('V1 layout detected — starting fresh GrapesJS project'); 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'); } } catch(e) { console.log('No saved layout, starting fresh'); }
})(); })();