From a76d5a1552327ab2580dfe3a46a3502bf7015587 Mon Sep 17 00:00:00 2001 From: my Date: Sun, 1 Feb 2026 22:22:58 +0100 Subject: [PATCH] impose + single page checkboxes --- octomode.py | 29 +++++++++++--- static/main.css | 18 ++++++++- static/pagedjs.css | 32 ++++++++++++++- templates/base.html | 97 ++++++++++++++++++++++++++++++++++++++++++++- templates/pdf.html | 18 +++++++-- 5 files changed, 182 insertions(+), 12 deletions(-) diff --git a/octomode.py b/octomode.py index a62fe84..73f15de 100755 --- a/octomode.py +++ b/octomode.py @@ -26,6 +26,7 @@ APP.config.from_pyfile('settings.py') # --- + # My attempt as showing helpful error messages. # the class holds an error string to show in the error.html tempalte # for now mostly for when the space in the yaml meta is missing. @@ -224,8 +225,17 @@ def html(name): @APP.route('//pdf/') def pdf(name): app_root = get_app_root() - url = f"{ app_root }/{name}/pagedjs.html" - return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) + pagedjs_base = f"{ app_root }/{name}/pagedjs.html" + impose = request.args.get("impose") == "1" + single_page = request.args.get("single") == "1" + params = {} + if impose: + params["impose"] = "1" + if single_page: + params["single"] = "1" + query = f"?{ urlencode(params) }" if params else "" + url = f"{ pagedjs_base }{ query }" + return render_template('pdf.html', url=url, pagedjs_base=pagedjs_base, name=name.strip(), pad_url=APP.config['PAD_URL']) # @APP.route('//impose/') # def impose(name): @@ -272,9 +282,18 @@ def pagedjs(name): title = get_meta(metadata, 'title', 'Untitled') cover = get_meta(metadata, 'cover', None) - print("impose?" + str(request.args.get("impose"))) - impose = False #request.args.get("impose") == "true" - return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title, cover=cover, impose=impose) + impose = request.args.get("impose") == "1" + single_page = request.args.get("single") == "1" + return render_template( + 'pagedjs.html', + name=name.strip(), + pad_content=html, + lang=lang, + title=title, + cover=cover, + impose=impose, + single_page=single_page + ) # @APP.route('//imposed.html') # def imposed(name): diff --git a/static/main.css b/static/main.css index c7293ba..d953b80 100644 --- a/static/main.css +++ b/static/main.css @@ -45,9 +45,25 @@ div#nav{ right: 1.5em; margin-top: 8px; } - div#nav input{ + div#nav input[type="text"]{ min-width: 300px; } + div#nav .layout-options { + display: inline-flex; + align-items: center; + gap: 0.5em; + margin-left: 0.5em; + font-size: 0.9em; + } + div#nav .layout-options label { + display: inline-flex; + align-items: center; + gap: 0.25em; + cursor: pointer; + } + div#nav .layout-options input[type="checkbox"] { + margin: 0; + } /* click logic (CSS only) */ span#click_md { cursor: pointer; diff --git a/static/pagedjs.css b/static/pagedjs.css index 5c9d09a..4efcd28 100644 --- a/static/pagedjs.css +++ b/static/pagedjs.css @@ -66,6 +66,36 @@ left: calc(var(--pagedjs-bleed-left)*-1); } + body.single-pages .pagedjs_pages { + flex-direction: column; + width: 100%; + } + + body.single-pages .pagedjs_first_page { + margin-left: 0; + } + + body.single-pages .pagedjs_page { + margin: 0 auto; + margin-top: 10mm; + } + + body.single-pages .pagedjs_left_page{ + width: calc(var(--pagedjs-bleed-left) + var(--pagedjs-pagebox-width) + var(--pagedjs-bleed-left))!important; + } + + body.single-pages .pagedjs_left_page .pagedjs_bleed-right .pagedjs_marks-crop{ + border-color: var(--pagedjs-crop-color); + } + + body.single-pages .pagedjs_left_page .pagedjs_bleed-right .pagedjs_marks-middle{ + width: var(--pagedjs-cross-size)!important; + } + + body.single-pages .pagedjs_right_page{ + left: 0; + } + /* show the margin-box */ .pagedjs_margin-top-left-corner-holder, @@ -177,4 +207,4 @@ .pagedjs_bleed-left .pagedjs_marks-crop:last-child, .pagedjs_bleed-right .pagedjs_marks-crop:last-child{ box-shadow: 0px -1px 0px 0px var(--pagedjs-crop-shadow); -} \ No newline at end of file +} diff --git a/templates/base.html b/templates/base.html index abd4a7c..b73bed8 100644 --- a/templates/base.html +++ b/templates/base.html @@ -22,7 +22,11 @@ - + + + + + @@ -31,6 +35,97 @@ {% block content %} {% endblock %} + diff --git a/templates/pdf.html b/templates/pdf.html index f57dee7..1fc9358 100644 --- a/templates/pdf.html +++ b/templates/pdf.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block content %} - + {% endblock %} {% block footer %} @@ -22,9 +22,19 @@ window.addEventListener('load', function () { const nav = document.getElementById('buttons'); - // Insert the SAVE button - const save = ''; - nav.innerHTML = nav.innerHTML + save; + // Insert the SAVE button without replacing existing nodes. + const saveLink = document.createElement('a'); + saveLink.href = '#'; + const saveButton = document.createElement('button'); + saveButton.id = 'save'; + saveButton.textContent = 'save'; + saveButton.style.backgroundColor = '#66ee66'; + saveButton.addEventListener('click', function (event) { + event.preventDefault(); + printPage(); + }); + saveLink.appendChild(saveButton); + nav.appendChild(saveLink); })