Skip to content

Commit

Permalink
Add 'align' option to figure shortcode (adityatelange#256)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kdkasad authored Feb 22, 2021
1 parent 5b1591b commit 6ec1cd8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions assets/css/post-single.css
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@
margin: auto
}

.post-content figure.align-center {
text-align: center;
}

.post-content figure > figcaption {
color: var(--primary);
font-size: 16px;
Expand Down
7 changes: 5 additions & 2 deletions layouts/shortcodes/figure.html
Original file line number Diff line number Diff line change
@@ -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 -}}
Expand Down

0 comments on commit 6ec1cd8

Please sign in to comment.