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

View file

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