summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKian Kasad <kian@kasad.com>2021-02-21 21:54:43 -0800
committerGitHub <noreply@github.com>2021-02-22 11:24:43 +0530
commit14ebcdecf31b1480ae997a0ab4d68207d31e083c (patch)
treef6f23c4181fb4c7487ca7bf8152a1ae10b0404f8
parent45c4b48e53ab8b9054b6ed6da2c72b17ef4de690 (diff)
Add 'align' option to figure shortcode (#256)
Usage: {{< figure align=center src="image.jpg" >}} Parameter values: - 'center': align image and captions to center of page - anything else neglected * Appends "#center" to the image's URL in order to utilize existing CSS rules for centering images.
-rw-r--r--assets/css/post-single.css4
-rw-r--r--layouts/shortcodes/figure.html7
2 files changed, 9 insertions, 2 deletions
diff --git a/assets/css/post-single.css b/assets/css/post-single.css
index b7ec47f..16a6c12 100644
--- a/assets/css/post-single.css
+++ b/assets/css/post-single.css
@@ -242,6 +242,10 @@
margin: auto
}
+.post-content figure.align-center {
+ text-align: center;
+}
+
.post-content figure > figcaption {
color: var(--primary);
font-size: 16px;
diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html
index 71aebb1..77f188e 100644
--- a/layouts/shortcodes/figure.html
+++ b/layouts/shortcodes/figure.html
@@ -1,8 +1,11 @@
-<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
+<figure{{ if or (.Get "class") (eq (.Get "align") "center") }} class="
+ {{- if eq (.Get "align") "center" }}align-center {{ end }}
+ {{- with .Get "class" }}{{ . }}{{- end }}"
+{{- end -}}>
{{- if .Get "link" -}}
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
{{- end }}
- <img src="{{ .Get "src" }}"
+ <img src="{{ .Get "src" }}{{- if eq (.Get "align") "center" }}#center{{- end }}"
{{- if or (.Get "alt") (.Get "caption") }}
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
{{- end -}}