From c44e1dfe759cc56df8b0bfe855d14d073ba41c74 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 8 Mar 2024 18:01:44 +0200 Subject: [PATCH] docs: preload page thumbnail if set Note that it expects the normal non-2x image in the front matter and a 2x image must be present too. --- site/content/docs/5.3/getting-started/parcel.md | 2 +- site/content/docs/5.3/getting-started/vite.md | 2 +- site/content/docs/5.3/getting-started/webpack.md | 2 +- .../layouts/partials/header-preload-thumbnail.html | 14 ++++++++++++++ site/layouts/partials/header.html | 2 ++ 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 site/layouts/partials/header-preload-thumbnail.html diff --git a/site/content/docs/5.3/getting-started/parcel.md b/site/content/docs/5.3/getting-started/parcel.md index a987b4587b..c781fef4ee 100644 --- a/site/content/docs/5.3/getting-started/parcel.md +++ b/site/content/docs/5.3/getting-started/parcel.md @@ -4,7 +4,7 @@ title: Bootstrap and Parcel description: The official guide for how to include and bundle Bootstrap's CSS and JavaScript in your project using Parcel. group: getting-started toc: true -thumbnail: guides/bootstrap-parcel@2x.png +thumbnail: guides/bootstrap-parcel.png --- diff --git a/site/content/docs/5.3/getting-started/vite.md b/site/content/docs/5.3/getting-started/vite.md index 653d7a9c5a..bd5dd637c2 100644 --- a/site/content/docs/5.3/getting-started/vite.md +++ b/site/content/docs/5.3/getting-started/vite.md @@ -4,7 +4,7 @@ title: Bootstrap and Vite description: The official guide for how to include and bundle Bootstrap's CSS and JavaScript in your project using Vite. group: getting-started toc: true -thumbnail: guides/bootstrap-vite@2x.png +thumbnail: guides/bootstrap-vite.png added: show_badge: false version: "5.2" diff --git a/site/content/docs/5.3/getting-started/webpack.md b/site/content/docs/5.3/getting-started/webpack.md index 39adaf61a2..a4eeedc3f3 100644 --- a/site/content/docs/5.3/getting-started/webpack.md +++ b/site/content/docs/5.3/getting-started/webpack.md @@ -4,7 +4,7 @@ title: Bootstrap and Webpack description: The official guide for how to include and bundle Bootstrap's CSS and JavaScript in your project using Webpack. group: getting-started toc: true -thumbnail: guides/bootstrap-webpack@2x.png +thumbnail: guides/bootstrap-webpack.png --- diff --git a/site/layouts/partials/header-preload-thumbnail.html b/site/layouts/partials/header-preload-thumbnail.html new file mode 100644 index 0000000000..6f4e29b16d --- /dev/null +++ b/site/layouts/partials/header-preload-thumbnail.html @@ -0,0 +1,14 @@ +{{- with $.Page.Params.thumbnail -}} + {{- $imgExt := path.Ext $.Page.Params.thumbnail -}} + {{- $imgDir := path.Dir $.Page.Params.thumbnail -}} + {{- $imgBasePath := path.Join "/docs" $.Site.Params.docs_version "assets/img" $imgDir -}} + {{- $imgFilename := urls.JoinPath $imgBasePath (printf "%s%s" (path.BaseName $.Page.Params.thumbnail) $imgExt) -}} + {{- $imgFilename2x := urls.JoinPath $imgBasePath (printf "%s@2x%s" (path.BaseName $.Page.Params.thumbnail) $imgExt) -}} + {{- $localImgPath := path.Join "/site/static" $imgFilename -}} + {{- $localImgPath2x := path.Join "/site/static" $imgFilename2x -}} + {{- if (not (and (fileExists $localImgPath) (fileExists $localImgPath2x))) -}} + {{- errorf "File does not exist! %s or %s" $localImgPath $localImgPath2x -}} + {{- else -}} + + {{- end -}} +{{- end -}} diff --git a/site/layouts/partials/header.html b/site/layouts/partials/header.html index ba58893286..df05a2e268 100644 --- a/site/layouts/partials/header.html +++ b/site/layouts/partials/header.html @@ -7,6 +7,8 @@ +{{ partial "header-preload-thumbnail" . }} + {{ if .IsHome }}{{ .Site.Title | markdownify }} · {{ .Site.Params.subtitle | markdownify }}{{ else }}{{ .Title | markdownify }} · {{ .Site.Title | markdownify }} v{{ .Site.Params.docs_version }}{{ end }}