diff options
| author | Mole Shang <135e2@135e2.dev> | 2026-02-09 23:19:16 +0800 |
|---|---|---|
| committer | Mole Shang <135e2@135e2.dev> | 2026-02-09 23:19:16 +0800 |
| commit | a582b6ef76bfb79744716f5cdfafff8c41861ec9 (patch) | |
| tree | 8d73094eb53507b09ed91f14b22df75ddbd85dab | |
| parent | 119356da0f77ec711e694811ab5e3bc82e762624 (diff) | |
| download | Seje2-a582b6ef76bfb79744716f5cdfafff8c41861ec9.tar.gz Seje2-a582b6ef76bfb79744716f5cdfafff8c41861ec9.tar.bz2 Seje2-a582b6ef76bfb79744716f5cdfafff8c41861ec9.zip | |
templates/page: support img caption displaymain
| -rw-r--r-- | sass/_partial/_post.scss | 7 | ||||
| -rw-r--r-- | templates/page.html | 24 |
2 files changed, 31 insertions, 0 deletions
diff --git a/sass/_partial/_post.scss b/sass/_partial/_post.scss index ed556af..3ce5ef9 100644 --- a/sass/_partial/_post.scss +++ b/sass/_partial/_post.scss @@ -74,6 +74,13 @@ box-sizing: content-box; width: 100%; } + .img-caption { + display: block; + text-align: center; + margin: 0.5em 0 1em 0; + font-size: 0.9em; + opacity: 0.8; + } .shk { margin: 1em 0; } 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 %} |
