Refactor, move HLJS code from footer to head;

already defered.
This commit is contained in:
Aditya Telange 2021-04-09 19:36:09 +05:30
parent 9d7576bd04
commit bb7b6f0076
No known key found for this signature in database
GPG Key ID: 82E844EF3DA99E77
3 changed files with 16 additions and 14 deletions

View File

@ -17,7 +17,7 @@
<main class="main"> <main class="main">
{{- block "main" . }}{{ end }} {{- block "main" . }}{{ end }}
</main> </main>
{{ partialCached "footer.html" . .Type .Layout .Params -}} {{ partialCached "footer.html" . -}}
</body> </body>
</html> </html>

View File

@ -20,19 +20,7 @@
</a> </a>
{{- end }} {{- end }}
{{- partial "extend_footer.html" . -}} {{- partial "extend_footer.html" . }}
{{- $isHLJSdisabled := (.Site.Params.assets.disableHLJS | default .Params.disableHLJS ) }}
{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (not $isHLJSdisabled)) }}
{{- if not .Site.Params.assets.disableFingerprinting }}
{{- $highlight := slice (resources.Get "js/highlight.min.js") | resources.Concat "assets/js/highlight.js" | minify | fingerprint }}
<script defer src="{{ $highlight.RelPermalink }}" integrity="{{ $highlight.Data.Integrity }}"
onload="hljs.initHighlightingOnLoad();"></script>
{{- else }}
{{- $highlight := slice (resources.Get "js/highlight.min.js") | resources.Concat "assets/js/highlight.js" | minify }}
<script defer src="{{ $highlight.RelPermalink }}" onload="hljs.initHighlightingOnLoad();"></script>
{{- end }}
{{- end }}
<script> <script>
window.onload = function () { window.onload = function () {

View File

@ -72,6 +72,20 @@
{{- end }} {{- end }}
{{- end -}} {{- end -}}
{{- /* Highlight.js */}}
{{- $isHLJSdisabled := (.Site.Params.assets.disableHLJS | default .Params.disableHLJS ) }}
{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (not $isHLJSdisabled)) }}
{{- if not .Site.Params.assets.disableFingerprinting }}
{{- $highlight := slice (resources.Get "js/highlight.min.js") | resources.Concat "assets/js/highlight.js" | minify |
fingerprint }}
<script defer src="{{ $highlight.RelPermalink }}" integrity="{{ $highlight.Data.Integrity }}"
onload="hljs.initHighlightingOnLoad();"></script>
{{- else }}
{{- $highlight := slice (resources.Get "js/highlight.min.js") | resources.Concat "assets/js/highlight.js" | minify }}
<script defer src="{{ $highlight.RelPermalink }}" onload="hljs.initHighlightingOnLoad();"></script>
{{- end }}
{{- end }}
{{- /* Favicons */}} {{- /* Favicons */}}
<link rel="icon" href="{{ .Site.Params.assets.favicon | default "favicon.ico" | absURL }}"> <link rel="icon" href="{{ .Site.Params.assets.favicon | default "favicon.ico" | absURL }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ .Site.Params.assets.favicon16x16 | default "favicon-16x16.png" | absURL }}"> <link rel="icon" type="image/png" sizes="16x16" href="{{ .Site.Params.assets.favicon16x16 | default "favicon-16x16.png" | absURL }}">