diff options
Diffstat (limited to 'templates')
| -rw-r--r-- | templates/page.html | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/templates/page.html b/templates/page.html index ec3116d..f795876 100644 --- a/templates/page.html +++ b/templates/page.html @@ -50,4 +50,28 @@ {% endif %} {% endblock %} </div> + +{% if page.extra.enable_img_caption %} +<script> + const images = document.querySelectorAll(".post-content img"); + images.forEach((img) => { + if (img.alt && img.alt.trim() !== "") { + const caption = document.createElement("div"); + caption.className = "img-caption"; + caption.textContent = img.alt; + + let insertionPoint = img; + if (img.parentElement.tagName === "A") { + insertionPoint = img.parentElement; + } + + insertionPoint.parentNode.insertBefore( + caption, + insertionPoint.nextSibling, + ); + } + }); +</script> +{% endif %} + {% endblock %} |
