mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-11 05:48:31 +02:00
Blog image cms (#483)
* fallback logic for social preview images * fallback logic for preview images
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
{{ $default_file_name := .default_file_name }}
|
||||
{{ $preview_file := .preview_file }}
|
||||
|
||||
<!--
|
||||
Image render priority:
|
||||
|
||||
1. If `preview_file` explicitly set .md file, use it
|
||||
2. If custom preview image in `default_file_name` exists, use it
|
||||
3. Fall back to default `preview_image`
|
||||
|
||||
-->
|
||||
|
||||
{{ $preview_image := .context.Params.preview_image }}
|
||||
|
||||
{{ $content_dir := or .context.Params.slug .context.File.ContentBaseName }}
|
||||
|
||||
{{ $preview_image_path := path.Join "static" .context.File.Dir $content_dir "preview" $default_file_name }}
|
||||
{{ $preview_image_exists := fileExists $preview_image_path }}
|
||||
|
||||
{{ if $preview_image_exists }}
|
||||
{{ $preview_image_path = strings.TrimPrefix "static/" $preview_image_path }}
|
||||
{{ $preview_image_path = strings.TrimPrefix "/static" $preview_image_path }}
|
||||
{{ $preview_image = $preview_image_path }}
|
||||
{{ end }}
|
||||
|
||||
{{ if $preview_file }}
|
||||
{{ $preview_image = $preview_file }}
|
||||
{{ end }}
|
||||
|
||||
{{ $preview_image = $preview_image | safeHTML | absURL }}
|
||||
|
||||
<img src="{{ $preview_image }}" alt="{{ .context.Params.title }}" loading="lazy">
|
||||
Reference in New Issue
Block a user