theme: cache calls to fileExists #380

This commit is contained in:
Sören Weber 2022-11-12 15:16:53 +01:00
parent f23d4163d8
commit 82a8b2f8c6
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
7 changed files with 13 additions and 8 deletions

View file

@ -11,7 +11,7 @@
{{- end }} {{- end }}
<title>{{ .Scratch.Get "title" }} {{ default "::" .Site.Params.titleSeparator }} {{ .Site.Title }}</title> <title>{{ .Scratch.Get "title" }} {{ default "::" .Site.Params.titleSeparator }} {{ .Site.Title }}</title>
{{- partial "favicon.html" . }} {{- partialCached "favicon.html" . }}
{{- partial "stylesheet.html" . }} {{- partial "stylesheet.html" . }}
<style> <style>
p, li, ul { p, li, ul {

View file

@ -9,7 +9,8 @@
{{- else if $page.IsHome }} {{- else if $page.IsHome }}
{{- $archetype = "deprecated-home" }} {{- $archetype = "deprecated-home" }}
{{- end }} {{- end }}
{{- if not (fileExists (printf "/layouts/partials/archetypes/%s" $archetype)) }} {{- $f := printf "/layouts/partials/archetypes/%s" $archetype }}
{{- if not (partialCached "fileExists.hugo" $f $f) }}
{{- $archetype = "default" }} {{- $archetype = "default" }}
{{- end }} {{- end }}
{{- partial "output-partial.hugo" (dict "base" (printf "archetypes/%s/%s" $archetype $hook) "page" $page "parameter" $parameter) }} {{- partial "output-partial.hugo" (dict "base" (printf "archetypes/%s/%s" $archetype $hook) "page" $page "parameter" $parameter) }}

View file

@ -0,0 +1 @@
{{- return fileExists . }}

View file

@ -29,7 +29,7 @@
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- partial "favicon.html" . }} {{- partialCached "favicon.html" . }}
{{- partial "stylesheet.html" . }} {{- partial "stylesheet.html" . }}
{{- partial "custom-header.html" . }} {{- partial "custom-header.html" . }}
</head> </head>

View file

@ -3,8 +3,10 @@
{{- $parameter := .parameter }} {{- $parameter := .parameter }}
{{- $format := partial "output-format.hugo" $page }} {{- $format := partial "output-format.hugo" $page }}
{{- $suffix := partial "output-suffix.hugo" $page }} {{- $suffix := partial "output-suffix.hugo" $page }}
{{- if or (not $format) (not (fileExists (printf "/layouts/partials/%s.%s.%s" $base $format $suffix))) }} {{- $f := printf "/layouts/partials/%s.%s.%s" $base $format $suffix }}
{{- if (fileExists (printf "/layouts/partials/%s.%s" $base $suffix)) }} {{- if or (not $format) (not (partialCached "fileExists.hugo" $f $f)) }}
{{- $f = printf "/layouts/partials/%s.%s" $base $suffix }}
{{- if partialCached "fileExists.hugo" $f $f }}
{{- partial (printf "%s.%s" $base $suffix) $parameter }} {{- partial (printf "%s.%s" $base $suffix) $parameter }}
{{- end }} {{- end }}
{{- else }} {{- else }}

View file

@ -10,8 +10,8 @@
{{- $quotedcontentlangs := slice }} {{- $quotedcontentlangs := slice }}
{{- $missingcontentlangs := slice }} {{- $missingcontentlangs := slice }}
{{- range $contentlangs }} {{- range $contentlangs }}
{{- $file := (printf "js/lunr.%s.min.js" .) }} {{- $f := printf "/static/js/lunr.%s.min.js" . }}
{{- if fileExists (printf "/static/%s" $file) }} {{- if partialCached "fileExists.hugo" $f $f }}
{{- $quotedcontentlangs = $quotedcontentlangs | append (printf "'%s'" .) }} {{- $quotedcontentlangs = $quotedcontentlangs | append (printf "'%s'" .) }}
{{- else }} {{- else }}
{{- $missingcontentlangs = $missingcontentlangs | append . }} {{- $missingcontentlangs = $missingcontentlangs | append . }}

View file

@ -14,7 +14,8 @@
<link href="{{"css/ie.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet"> <link href="{{"css/ie.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
<link href="{{"css/variant.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet"> <link href="{{"css/variant.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
<link href="{{"css/print.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet" media="print"> <link href="{{"css/print.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet" media="print">
{{- if (fileExists (printf "/static/css/format-%s.css" (partial "output-format.hugo" .))) }} {{- $f := printf "/static/css/format-%s.css" (partial "output-format.hugo" .) }}
{{- if partialCached "fileExists.hugo" $f $f }}
<link href="{{(printf "css/format-%s.css" (partial "output-format.hugo" .)) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet"> <link href="{{(printf "css/format-%s.css" (partial "output-format.hugo" .)) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
{{- end }} {{- end }}
<script src="{{"js/variant.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script> <script src="{{"js/variant.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>