rename page
This commit is contained in:
@@ -7,6 +7,13 @@ OUT = BASE / "templates" / "editor.html"
|
||||
|
||||
content = SRC.read_text(encoding="utf-8")
|
||||
|
||||
# ── Normalize line endings to LF to avoid CRLF mismatch on Windows ──
|
||||
content = content.replace("\r\n", "\n")
|
||||
|
||||
# ── Correct themeBaseUrl and mediaPath in editor.html ──
|
||||
content = content.replace("Vvveb.themeBaseUrl = 'demo/landing/';", "Vvveb.themeBaseUrl = '/static/Vvvebjs/demo/landing/';")
|
||||
content = content.replace("window.mediaPath = '../../media';", "window.mediaPath = '/static/Vvvebjs/media/';")
|
||||
|
||||
# ── 1. Fix static asset paths ────────────────────────────────────
|
||||
VBASE = "/static/Vvvebjs/"
|
||||
replacements = [
|
||||
@@ -41,6 +48,20 @@ JS_VARS = [
|
||||
for old, new in JS_VARS:
|
||||
content = content.replace(old, new)
|
||||
|
||||
# ── Make editor load requested page from query parameter ──
|
||||
old_init = 'let firstPage = Object.keys(pages)[0];\nVvveb.Builder.init(pages[firstPage]["url"], function () {'
|
||||
new_init = """let firstPage = Object.keys(pages)[0];
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const requestedPage = urlParams.get('page');
|
||||
if (requestedPage) {
|
||||
\tlet pageKey = requestedPage.replace(".html", "");
|
||||
\tif (pages[pageKey]) {
|
||||
\t\tfirstPage = pageKey;
|
||||
\t}
|
||||
}
|
||||
Vvveb.Builder.init(pages[firstPage]["url"], function () {"""
|
||||
content = content.replace(old_init, new_init)
|
||||
|
||||
# ── 4. Wrap everything in {% raw %} ... {% endraw %} to avoid Jinja2 parsing conflicts ──
|
||||
# We do this first so Jinja2 ignores VvvebJS's frontend micro-templates ({%= %}, {% %}).
|
||||
# Then we selectively exit the {% raw %} block using {% endraw %} ... {% raw %} for our dynamic values.
|
||||
@@ -94,7 +115,7 @@ BACK_BTN = """
|
||||
// Inject project slug for save bridge
|
||||
window.VVVEB_PROJECT_SLUG = "{% endraw %}{{ slug | safe }}{% raw %}";
|
||||
</script>
|
||||
<script src="/static/js/my-editor.js"></script>
|
||||
<script src="/static/js/my-editor.js?v={% endraw %}{{ range(1, 100000) | random }}{% raw %}"></script>
|
||||
"""
|
||||
content = content.replace("</body>", BACK_BTN + "\n</body>")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user