Browse Source

figure shortcode: Support i18n and unnumbered captions

- Figures are now unnumbered by default
- To number a figure, use the form:
  - `{{< figure src="image.jpg" title="Caption" numbered="true" >}}`
- Add i18n translation for "Figure" in captions
- Update English and Chinese language packs

Close #328 and #513
George Cushen 7 years ago
parent
commit
f23526e55d
4 changed files with 38 additions and 6 deletions
  1. 3 0
      i18n/en.yaml
  2. 9 0
      i18n/zh.yaml
  3. 9 6
      layouts/partials/css/academic.css
  4. 17 0
      layouts/shortcodes/figure.html

+ 3 - 0
i18n/en.yaml

@@ -20,6 +20,9 @@
 - id: next
   translation: Next
 
+- id: figure
+  translation: "Figure %d:"
+
 # Buttons
 
 - id: btn_preprint

+ 9 - 0
i18n/zh.yaml

@@ -14,6 +14,15 @@
 - id: minute_read
   translation: 分钟阅读时间
 
+- id: previous
+  translation: 上一页
+
+- id: next
+  translation: 下一页
+
+- id: figure
+  translation: "图%d:"
+
 # Buttons
 
 - id: btn_preprint

+ 9 - 6
layouts/partials/css/academic.css

@@ -139,12 +139,6 @@ video {
   margin: 0 auto;
 }
 
-figcaption:before {
-  font-weight: 700;
-  text-transform: uppercase;
-  content: "Figure " counter(captions) ": ";
-}
-
 figcaption {
   display: block;
   margin-top: 0.75em;
@@ -152,6 +146,15 @@ figcaption {
   font-size: 1rem;
   margin-bottom: 1.65rem;
   font-family: '{{ .Get "heading_font" }}', sans-serif;
+}
+
+figcaption.numbered:before {
+  font-weight: 700;
+  text-transform: uppercase;
+  content: attr(data-pre) counter(captions) attr(data-post);
+}
+
+figcaption.numbered {
   counter-increment: captions;
 }
 

+ 17 - 0
layouts/shortcodes/figure.html

@@ -0,0 +1,17 @@
+<figure{{ with .Get "class" }} class="{{.}}"{{ end }}>
+{{ if .Get "link"}}<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>{{ end }}
+<img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}" {{ end }}{{ with .Get "width" }}width="{{.}}" {{ end }}{{ with .Get "height" }}height="{{.}}" {{ end }}/>
+{{ if .Get "link"}}</a>{{ end }}
+{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
+{{ $figure := split (i18n "figure" | default "Figure %d:") "%d" }}
+<figcaption data-pre="{{ index $figure 0 }}" data-post="{{ index $figure 1 }}" {{ if eq (.Get "numbered") "true" }}class="numbered"{{ end }}>{{ if isset .Params "title" }}
+  <h4>{{ .Get "title" }}</h4>{{ end }}
+  {{ if or (.Get "caption") (.Get "attr")}}<p>
+    {{ .Get "caption" }}
+    {{ with .Get "attrlink"}}<a href="{{.}}"> {{ end }}
+    {{ .Get "attr" }}
+    {{ if .Get "attrlink"}}</a> {{ end }}
+  </p> {{ end }}
+</figcaption>
+{{ end }}
+</figure>