Fix book page returning empty body due to malformed onclick attribute
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:
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user