From df0455d16fcec4da0556e3e86992bd1f48a408fc Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Mon, 4 Mar 2024 12:49:44 +0100 Subject: [PATCH] hugo: improve build performance use cached partials for repeat templates and icons Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- content/scout/integrations/registry/acr.md | 4 ++- .../_default/_markup/render-codeblock.html | 4 +-- layouts/_default/_markup/render-image.html | 2 +- layouts/_default/_markup/render-link.html | 2 +- layouts/_default/cli.html | 26 +++++++++---------- layouts/index.html | 2 +- layouts/partials/components/accordion.html | 4 +-- layouts/partials/github-links.html | 8 +++--- layouts/partials/head.html | 4 +-- layouts/partials/header.html | 6 ++--- layouts/partials/sidebar.html | 4 +-- layouts/partials/tooltip.html | 2 +- 12 files changed, 35 insertions(+), 33 deletions(-) diff --git a/content/scout/integrations/registry/acr.md b/content/scout/integrations/registry/acr.md index adb24c6bf9..13e464d936 100644 --- a/content/scout/integrations/registry/acr.md +++ b/content/scout/integrations/registry/acr.md @@ -54,12 +54,14 @@ the Azure resources. {{< accordion title="JSON template" >}} {{< acr-template.inline >}} -{{ $data := data.GetJSON "https://prod-scout-integration-templates.s3.amazonaws.com/latest/acr_token_template.json" }} +{{ with resources.GetRemote "https://prod-scout-integration-templates.s3.amazonaws.com/latest/acr_token_template.json" }} +{{ $data := .Content | transform.Unmarshal }} ```json {{ transform.Remarshal "json" $data }} ``` +{{ end }} {{< /acr-template.inline >}} {{< /accordion >}} diff --git a/layouts/_default/_markup/render-codeblock.html b/layouts/_default/_markup/render-codeblock.html index 09dc6afcf4..59e59f45f9 100644 --- a/layouts/_default/_markup/render-codeblock.html +++ b/layouts/_default/_markup/render-codeblock.html @@ -7,8 +7,8 @@ copying = true; setTimeout(() => copying = false, 2000);" > - - + + {{ $result := transform.HighlightCodeBlock . }}
diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 47d9fd60a0..8ca7d7576b 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -37,7 +37,7 @@ {{- .Text | safeHTML -}} - {{- partial "icon" "open_in_new" -}} + {{- partialCached "icon" "open_in_new" "open_in_new" -}} {{- else if (strings.HasPrefix $url "/") -}} {{/* absolute link, use url as-is */}} diff --git a/layouts/_default/cli.html b/layouts/_default/cli.html index cf989b2367..f955e7c9f4 100644 --- a/layouts/_default/cli.html +++ b/layouts/_default/cli.html @@ -33,7 +33,7 @@ Aliases - {{ partial "tooltip.html" "An alias is a short or memorable alternative for a longer command." }} + {{ partialCached "tooltip.html" "An alias is a short or memorable alternative for a longer command." "cli-alias" }}
@@ -71,19 +71,19 @@ {{ end }} {{ with $data.kubernetes }}

- {{ partial "components/badge.html" (dict "color" "blue" "content" "Kubernetes") }} + {{ partialCached "components/badge.html" (dict "color" "blue" "content" "Kubernetes") "k8s" }} This command works with the Kubernetes orchestrator.

{{ end }} {{ with $data.swarm }}

- {{ partial "components/badge.html" (dict "color" "blue" "content" "Swarm") }} + {{ partialCached "components/badge.html" (dict "color" "blue" "content" "Swarm") "swarm" }} This command works with the Swarm orchestrator.

{{ end }} {{ with $data.long }} {{ $heading := dict "level" 2 "text" "Description" }} - {{ partial "heading.html" $heading }} + {{ partialCached "heading.html" $heading "cli-description" }} {{ $subHeadings := (strings.FindRE `(?m:#{3,4} .*)` .) }} {{ $.Scratch.Add "headings" $heading }} {{ range $subHeadings }} @@ -97,7 +97,7 @@ {{ $opts := where . "hidden" false }} {{ with $opts }} {{ $heading := dict "level" 2 "text" "Options" }} - {{ partial "heading.html" $heading }} + {{ partialCached "heading.html" $heading "cli-options" }} {{ $.Scratch.Add "headings" $heading }} @@ -129,22 +129,22 @@
{{ with .min_api_version }} - {{ partial "components/badge.html" (dict "color" "blue" "content" (printf "API %s+" .)) }} + {{ partialCached "components/badge.html" (dict "color" "blue" "content" (printf "API %s+" .)) "api" . }} {{ end }} {{ with .deprecated }} - {{ partial "components/badge.html" (dict "color" "red" "content" "Deprecated") }} + {{ partialCached "components/badge.html" (dict "color" "red" "content" "Deprecated") "deprecated" }} {{ end }} {{ with .experimental }} - {{ partial "components/badge.html" (dict "color" "amber" "content" "experimental (daemon)") }} + {{ partialCached "components/badge.html" (dict "color" "amber" "content" "experimental (daemon)") "exp" }} {{ end }} {{ with .experimentalcli }} - {{ partial "components/badge.html" (dict "color" "amber" "content" "experimental (CLI)") }} + {{ partialCached "components/badge.html" (dict "color" "amber" "content" "experimental (CLI)") "exp-cli" }} {{ end }} {{ with .kubernetes }} - {{ partial "components/badge.html" (dict "color" "blue" "content" "Kubernetes") }} + {{ partialCached "components/badge.html" (dict "color" "blue" "content" "Kubernetes") "k8s" }} {{ end }} {{ with .swarm }} - {{ partial "components/badge.html" (dict "color" "blue" "content" "Swarm") }} + {{ partialCached "components/badge.html" (dict "color" "blue" "content" "Swarm") "swarm" }} {{ end }} {{ if .description }} {{/* replace newlines in long desc with break tags */}} @@ -159,7 +159,7 @@ {{ end }} {{ with $data.examples }} {{ $heading := dict "level" 2 "text" "Examples" }} - {{ partial "heading.html" $heading }} + {{ partialCached "heading.html" $heading "cli-examples" }} {{ $subHeadings := (strings.FindRE `(?m:#{3,4} .*)` .) }} {{ $.Scratch.Add "headings" $heading }} {{ range $subHeadings }} @@ -171,7 +171,7 @@ {{ end }} {{ if eq .Kind "section" }} {{ $heading := dict "level" 2 "text" "Subcommands" }} - {{ partial "heading.html" $heading }} + {{ partialCached "heading.html" $heading "cli-subcommands" }} {{ $.Scratch.Add "headings" $heading }} diff --git a/layouts/index.html b/layouts/index.html index 51608c184f..b7b7b36ba9 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -281,7 +281,7 @@ -
{{ partial "footer.html" . }}
+
{{ partialCached "footer.html" . }}
diff --git a/layouts/partials/components/accordion.html b/layouts/partials/components/accordion.html index bddf790473..843adaae62 100644 --- a/layouts/partials/components/accordion.html +++ b/layouts/partials/components/accordion.html @@ -1,8 +1,8 @@
diff --git a/layouts/partials/github-links.html b/layouts/partials/github-links.html index 9476d84b35..cd913d2514 100644 --- a/layouts/partials/github-links.html +++ b/layouts/partials/github-links.html @@ -2,21 +2,21 @@ {{ with .File }} {{ if not (in .Filename "/_vendor/") }}

- {{ partial "icon" "edit" }} + {{ partialCached "icon" "edit" "edit" }} {{- T "editPage" -}} - {{ partial "icon" "open_in_new" }} + {{ partialCached "icon" "open_in_new" "open_in_new" }}

{{ end }} {{ end }}

- {{ partial "icon" "done" }} + {{ partialCached "icon" "done" "done" }} {{- T "requestChanges" -}} - {{ partial "icon" "open_in_new" }} + {{ partialCached "icon" "open_in_new" "open_in_new" }}

diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 2e0418dd54..27cc2eda02 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -38,7 +38,7 @@ {{ end }} {{/* preload Roboto Flex as it's a critical font: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload */}} -{{ partial "utils/css.html" . }} +{{ partialCached "utils/css.html" "-" }} {{ $theme := resources.Get "js/theme.js" | js.Build (dict "minify" true) }} {{ $js := resources.Match "js/src/**.js" @@ -55,4 +55,4 @@ }} -{{ partialCached "utils/resources.html" . }} +{{ partialCached "utils/resources.html" "-" }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 00ac424df7..965cbf6bb7 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -11,7 +11,7 @@ sidebar.classList.replace('md:block', 'md:hidden'); } }" class="icon-svg hidden px-4 md:block" aria-label="Menu"> - {{ partial "icon" "menu" }} + {{ partialCached "icon" "menu" "menu" }} {{ end }}
@@ -31,8 +31,8 @@ localStorage.setItem('theme-preference', value); document.firstElementChild.className = value; })" @click="theme = (theme === 'dark' ? 'light' : 'dark')"> - {{ partial "icon" "light_mode"}} - + {{ partialCached "icon" "light_mode" "light_mode"}} +
diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 0a45f38f09..1e74b054aa 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -49,10 +49,10 @@ {{ markdownify .entry.sectiontitle }} - {{ partial "icon" "expand_more" }} + {{ partialCached "icon" "expand_more" "expand_more" }} - {{ partial "icon" "expand_less" }} + {{ partialCached "icon" "expand_less" "expand_less" }}
    diff --git a/layouts/partials/tooltip.html b/layouts/partials/tooltip.html index bebaa4a2ed..b20cc3e2c6 100644 --- a/layouts/partials/tooltip.html +++ b/layouts/partials/tooltip.html @@ -1,6 +1,6 @@
    - {{ partial "icon" "help" }} + {{ partialCached "icon" "help" "help" }}