replace to work with Hugo before 0.43 #40

This commit is contained in:
Huy Tran 2018-09-23 09:55:37 +10:00
parent 1bd94c5f7a
commit 49c9ca6ffe
2 changed files with 17 additions and 18 deletions

View file

@ -1,18 +1,18 @@
{{ if .Site.Params.highlightjs }} {{ if or ((not (isset .Params "highlight")) and ((isset .Params "highlight") .Params.highlight)) }}
{{ if or (not (isset .Params "highlight")) (.Params.highlight) }} {{ $.Scratch.Set "hl_languages" (union (.Site.Params.highlightjslanguages) (.Params.highlightjslanguages)) }}
{{ $hl := newScratch }} {{ if (.Site.Params.highlightjs) }}
{{ $hl.Set "languages" (union (.Site.Params.highlightjslanguages) (.Params.highlightjslanguages)) }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
{{ with $hl.Get "languages" }} {{ with $.Scratch.Get "hl_languages" }}
{{ range . }} {{ range . }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/{{.}}.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/{{.}}.min.js"></script>
{{ end }} {{ end }}
{{ end }} {{ end }}
<script type="text/javascript"> {{ end }}
hljs.configure({languages: []}); <script type="text/javascript">
hljs.initHighlightingOnLoad(); {{ with $.Scratch.Get "hl_languages" }}
</script> hljs.configure({languages: [{{(delimit . ", ")}}]});
{{ $hl.Delete "languages" }} {{ end }}
{{ end }} hljs.initHighlightingOnLoad();
</script>
{{ $.Scratch.Delete "hl_languages" }}
{{ end }} {{ end }}

View file

@ -1,8 +1,7 @@
{{ $fig := newScratch }}
{{ if .Get "caption" }} {{ if .Get "caption" }}
{{ $fig.Set "caption" (.Get "caption") }} {{ $.Scratch.Set "caption" (.Get "caption") }}
{{ else if .Get "alt" }} {{ else if .Get "alt" }}
{{ $fig.Set "caption" (.Get "alt") }} {{ $.Scratch.Set "caption" (.Get "alt") }}
{{ end }} {{ end }}
<!-- resolve absolute image path --> <!-- resolve absolute image path -->
{{ $permalink := $.Page.Permalink }} {{ $permalink := $.Page.Permalink }}
@ -29,10 +28,10 @@
/> />
{{ if .Get "link"}}</a>{{ end }} {{ if .Get "link"}}</a>{{ end }}
<!-- caption and attr--> <!-- caption and attr-->
{{ if ($fig.Get "caption") }} {{ if ($.Scratch.Get "caption") }}
<figcaption> <figcaption>
<span class="img--caption"> <span class="img--caption">
Figure {{ $.Page.Scratch.Get "fig" }}. {{ $fig.Get "caption" | markdownify | plainify }} Figure {{ $.Page.Scratch.Get "fig" }}. {{ $.Scratch.Get "caption" | markdownify | plainify }}
{{ if .Get "attr" }} {{ if .Get "attr" }}
[{{- with .Get "attrlink"}}<a href="{{ . }}">{{ end }}{{ .Get "attr" | markdownify }}{{ if .Get "attrlink"}}</a>{{ end -}}] [{{- with .Get "attrlink"}}<a href="{{ . }}">{{ end }}{{ .Get "attr" | markdownify }}{{ if .Get "attrlink"}}</a>{{ end -}}]
{{ end }} {{ end }}
@ -41,4 +40,4 @@
{{ end }} {{ end }}
</figure> </figure>
{{ .Page.Scratch.Add "fig" 1 }} {{ .Page.Scratch.Add "fig" 1 }}
{{ $fig.Delete "caption"}} {{ $.Scratch.Delete "caption"}}