Skip to content

Commit 8929459

Browse files
committed
Refactor: og-preview use img tag instead of div
1 parent 864e250 commit 8929459

File tree

2 files changed

+48
-52
lines changed

2 files changed

+48
-52
lines changed

assets/scss/components/_og-preview.scss

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
}
2222

2323
.dark .og-preview-container {
24-
box-shadow: 0 4px 12px rgba(0,0,0, 0.4), 0 0 0 1px theme('colors.darkmode.border'), 0 0 20px rgba(188, 251, 255, 0.4);
25-
&:hover {
26-
box-shadow: 0 6px 25px rgba(0,0,0, 0.3), 0 0 0 1px theme('colors.darkmode.primary'), 0 0 30px rgba(188, 251, 255, 0.6);
27-
}
24+
box-shadow: 0 4px 12px rgba(0,0,0, 0.4), 0 0 0 1px theme('colors.darkmode.border'), 0 0 20px rgba(188, 251, 255, 0.4);
25+
&:hover {
26+
box-shadow: 0 6px 25px rgba(0,0,0, 0.3), 0 0 0 1px theme('colors.darkmode.primary'), 0 0 30px rgba(188, 251, 255, 0.6);
27+
}
2828
}
2929

30-
.og-preview-image {
31-
@apply w-full h-full bg-cover bg-center bg-no-repeat relative;
32-
background-color: theme('colors.body');
30+
.og-preview-image-tag {
31+
@apply absolute inset-0 w-full h-full object-cover z-0;
3332
}
3433

3534
.image-dark-overlay {
@@ -88,15 +87,12 @@
8887

8988
@media (max-width: 1023.98px) {
9089
.og-preview-container:hover {
91-
transform: none;
90+
transform: none;
9291
}
93-
.og-preview-image {
94-
background-size: contain;
95-
}
9692
.social-share-overlay {
97-
opacity: 1;
93+
opacity: 1;
9894
}
9995
.sharing-runner {
100-
@apply opacity-0;
96+
@apply opacity-0;
10197
}
102-
}
98+
}

layouts/partials/components/og-preview.html

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,60 @@
22

33
{{/* 1. Try to find the auto-generated OG image: [slug]-og.jpg */}}
44
{{ if .File }}
5-
{{ $pageSlug := path.Base .File.Dir }}
6-
{{ $generatedOgImageName := printf "%s-og.jpg" $pageSlug }}
7-
{{ $ogImageResource = .Resources.GetMatch $generatedOgImageName }}
5+
{{ $pageSlug := path.Base .File.Dir }}
6+
{{ $generatedOgImageName := printf "%s-og.jpg" $pageSlug }}
7+
{{ $ogImageResource = .Resources.GetMatch $generatedOgImageName }}
88
{{ end }}
99

1010
{{/* 2. If not found, fall back to the `image` param in front matter */}}
1111
{{ if not $ogImageResource }}
12-
{{ with .Params.image }}
13-
{{ $fmImage := . }}
14-
{{ $ogImageResource = $.Page.Resources.GetMatch $fmImage }}
15-
{{ if not $ogImageResource }}
16-
{{ $ogImageResource = resources.Get $fmImage }}
17-
{{ end }}
18-
{{ end }}
12+
{{ with .Params.image }}
13+
{{ $fmImage := . }}
14+
{{ $ogImageResource = $.Page.Resources.GetMatch $fmImage }}
15+
{{ if not $ogImageResource }}
16+
{{ $ogImageResource = resources.Get $fmImage }}
17+
{{ end }}
18+
{{ end }}
1919
{{ end }}
2020

2121
{{/* 3. If still not found, use a site-wide default */}}
2222
{{ if not $ogImageResource }}
23-
{{ with site.Params.metadata.image }}
24-
{{ $ogImageResource = resources.Get . }}
25-
{{ end }}
23+
{{ with site.Params.metadata.image }}
24+
{{ $ogImageResource = resources.Get . }}
25+
{{ end }}
2626
{{ end }}
2727

2828

2929
{{ if $ogImageResource }}
30-
{{ $resizedOg := $ogImageResource.Fill "600x315 Lanczos q85" }}
31-
{{ $ogImageDisplay := $resizedOg.RelPermalink }}
30+
{{ $resizedOg := $ogImageResource.Resize "600x Lanczos q85" }}
31+
{{ $ogImageDisplay := $resizedOg.RelPermalink }}
3232

33-
<div class="og-preview-wrapper">
34-
<div class="og-preview-container">
35-
<div class="og-preview-image" style="background-image: url('{{ $ogImageDisplay }}')">
36-
<div class="image-dark-overlay"></div>
37-
<div class="social-share-overlay">
38-
<div class="social-icons-container">
39-
<a href="https://twitter.com/intent/tweet/?text={{ .Title | urlquery }}&url={{ .Permalink | absURL }}" target="_blank" rel="noopener" class="social-icon" title="Share on X/Twitter">
40-
{{ partial "icon.html" (dict "style" "brands" "name" "x-twitter") }}
41-
</a>
42-
<a href="https://www.facebook.com/sharer/sharer.php?u={{ .Permalink | absURL }}" target="_blank" rel="noopener" class="social-icon" title="Share on Facebook">
43-
{{ partial "icon.html" (dict "style" "brands" "name" "facebook") }}
44-
</a>
45-
<a href="https://www.linkedin.com/shareArticle?mini=true&url={{ .Permalink | absURL }}&title={{ .Title | urlquery }}" target="_blank" rel="noopener" class="social-icon" title="Share on LinkedIn">
46-
{{ partial "icon.html" (dict "style" "brands" "name" "linkedin") }}
47-
</a>
48-
</div>
49-
</div>
50-
</div>
51-
<div class="sharing-runner">
52-
<span>Share this post</span>
53-
<div class="runner-icons">
33+
<div class="og-preview-wrapper">
34+
<div class="og-preview-container">
35+
<img src="{{ $ogImageDisplay }}" alt="Social share preview for {{ .Title }}" class="og-preview-image-tag" />
36+
37+
<div class="image-dark-overlay"></div>
38+
<div class="social-share-overlay">
39+
<div class="social-icons-container">
40+
<a href="https://twitter.com/intent/tweet/?text={{ .Title | urlquery }}&url={{ .Permalink | absURL }}" target="_blank" rel="noopener" class="social-icon" title="Share on X/Twitter">
5441
{{ partial "icon.html" (dict "style" "brands" "name" "x-twitter") }}
42+
</a>
43+
<a href="https://www.facebook.com/sharer/sharer.php?u={{ .Permalink | absURL }}" target="_blank" rel="noopener" class="social-icon" title="Share on Facebook">
5544
{{ partial "icon.html" (dict "style" "brands" "name" "facebook") }}
45+
</a>
46+
<a href="https://www.linkedin.com/shareArticle?mini=true&url={{ .Permalink | absURL }}&title={{ .Title | urlquery }}" target="_blank" rel="noopener" class="social-icon" title="Share on LinkedIn">
5647
{{ partial "icon.html" (dict "style" "brands" "name" "linkedin") }}
57-
</div>
48+
</a>
49+
</div>
50+
</div>
51+
<div class="sharing-runner">
52+
<span>Share this post</span>
53+
<div class="runner-icons">
54+
{{ partial "icon.html" (dict "style" "brands" "name" "x-twitter") }}
55+
{{ partial "icon.html" (dict "style" "brands" "name" "facebook") }}
56+
{{ partial "icon.html" (dict "style" "brands" "name" "linkedin") }}
5857
</div>
5958
</div>
6059
</div>
61-
{{ end }}
60+
</div>
61+
{{ end }}

0 commit comments

Comments
 (0)