0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-26 23:54:23 +01:00

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.
This commit is contained in:
XhmikosR 2024-03-08 18:01:44 +02:00
parent 930740afbc
commit c44e1dfe75
5 changed files with 19 additions and 3 deletions

View File

@ -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
---
<img class="mb-4 img-fluid rounded-3" srcset="/docs/{{< param docs_version >}}/assets/img/guides/bootstrap-parcel.png, /docs/{{< param docs_version >}}/assets/img/guides/bootstrap-parcel@2x.png 2x" src="/docs/{{< param docs_version >}}/assets/img/guides/bootstrap-parcel.png" width="2000" height="1000" alt="">

View File

@ -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"

View File

@ -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
---
<img class="mb-4 img-fluid rounded-3" srcset="/docs/{{< param docs_version >}}/assets/img/guides/bootstrap-webpack.png, /docs/{{< param docs_version >}}/assets/img/guides/bootstrap-webpack@2x.png 2x" src="/docs/{{< param docs_version >}}/assets/img/guides/bootstrap-webpack.png" width="2000" height="1000" alt="">

View File

@ -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 -}}
<link rel="preload" href="{{ $imgFilename }}" imagesrcset="{{ $imgFilename }}, {{ $imgFilename2x }} 2x" as="image">
{{- end -}}
{{- end -}}

View File

@ -7,6 +7,8 @@
<meta name="docsearch:language" content="en">
<meta name="docsearch:version" content="{{ .Site.Params.docs_version }}">
{{ partial "header-preload-thumbnail" . }}
<title>{{ if .IsHome }}{{ .Site.Title | markdownify }} · {{ .Site.Params.subtitle | markdownify }}{{ else }}{{ .Title | markdownify }} · {{ .Site.Title | markdownify }} v{{ .Site.Params.docs_version }}{{ end }}</title>
<link rel="canonical" href="{{ .Permalink }}">