summaryrefslogtreecommitdiff
path: root/layouts
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-05-09 09:39:17 +0800
committerEltrac <hi@guhub.cn>2025-05-09 09:39:17 +0800
commitf225fbaedec3d93fa0c5b725bb416c7819d23d77 (patch)
tree10605fcddc223a1df8a0433ad30266bca696e474 /layouts
parentc5d15542f5826dcd530c50afe6716923a886c7c3 (diff)
feat: render markdown image with necessary context
By context I mean necessary attributes, parents and brothers. Now I can use bare ![]() instead of img shortcode to insert images with fancybox, lazyloading and caption. Recommended format: ```markdown ![alt text](image_source "caption text") ``` Former-commit-id: d6219f997cab144905ce07b0a3b61b36b24495fa
Diffstat (limited to 'layouts')
-rw-r--r--layouts/_default/_markup/render-image.html16
1 files changed, 16 insertions, 0 deletions
diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html
new file mode 100644
index 00000000..697c33c2
--- /dev/null
+++ b/layouts/_default/_markup/render-image.html
@@ -0,0 +1,16 @@
+{{- $src := .Destination -}}
+{{- $alt := .Text | default "" -}}
+{{- $caption := .Title | default "" -}}
+<figure>
+ <a href="{{ $src }}" data-fancybox data-caption="{{ $alt }}">
+ <img
+ class="lazy" loading="lazy"
+ src="{{ $src }}" alt="{{ $alt }}"
+ />
+ </a>
+ {{- if $caption }}
+ <figcaption>
+ <h4>{{ $caption | markdownify }}</h4>
+ </figcaption>
+ {{- end }}
+</figure>