Fix book page returning empty body due to malformed onclick attribute
Some checks failed
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

html/template's context-aware parser was treating the backslash-escaped
quote in the inline onclick regex literal as an HTML attribute terminator,
causing template execution to produce an empty/broken output.

Move the summary paragraph-splitting logic into a named window.openSummary
function in the script block, and call it via a clean onclick=openSummary(this)
attribute with no inline regex literals.
This commit is contained in:
Admin
2026-03-01 23:45:08 +05:00
parent db59d55f42
commit dfb3f61812

View File

@@ -1474,11 +1474,11 @@ const bookTmpl = `
{{if .Meta.TotalChapters}}<span class="text-xs px-2 py-0.5 rounded-full bg-zinc-800 text-zinc-300">{{.Meta.TotalChapters}} ch total</span>{{end}}
<span class="text-xs px-2 py-0.5 rounded-full bg-amber-900 text-amber-300">{{.TotalDownloaded}} downloaded</span>
</div>
{{if .Meta.Summary}}
<p class="text-zinc-400 text-sm mt-3 line-clamp-3 cursor-zoom-in hover:text-zinc-300 transition-colors"
onclick="(function(t){var o=document.getElementById('summary-zoom-overlay');var c=document.getElementById('summary-zoom-text');c.innerHTML='';var paras=t.split(/\n+/).filter(function(s){return s.trim().length>0;});if(paras.length<=1){paras=t.split(/(?<=[.!?])\s{2,}|(?<=[.!?][\"'\u201d])\s+/).filter(function(s){return s.trim().length>0;});}paras.forEach(function(p){var el=document.createElement('p');el.textContent=p.trim();c.appendChild(el);});o.classList.remove('hidden');o.classList.add('flex');})(this.dataset.full)"
data-full="{{.Meta.Summary}}">{{.Meta.Summary}}</p>
{{end}}
{{if .Meta.Summary}}
<p class="text-zinc-400 text-sm mt-3 line-clamp-3 cursor-zoom-in hover:text-zinc-300 transition-colors"
onclick="openSummary(this)"
data-full="{{.Meta.Summary}}">{{.Meta.Summary}}</p>
{{end}}
</div>
</div>
@@ -1566,6 +1566,25 @@ const bookTmpl = `
</div>
<script>
window.openSummary = function(el) {
var t = el.dataset.full || '';
var o = document.getElementById('summary-zoom-overlay');
var c = document.getElementById('summary-zoom-text');
c.innerHTML = '';
var paras = t.split(/\n+/).filter(function(s) { return s.trim().length > 0; });
if (paras.length <= 1) {
paras = t.split(/(?<=[.!?][\u201d\u2019"']?)\s{2,}/).filter(function(s) { return s.trim().length > 0; });
}
if (paras.length <= 1) { paras = [t]; }
paras.forEach(function(p) {
var el = document.createElement('p');
el.textContent = p.trim();
c.appendChild(el);
});
o.classList.remove('hidden');
o.classList.add('flex');
};
(function () {
var SLUG = '{{.Slug}}';
var LS_KEY = 'reading_progress';