Skip to content

Commit a320341

Browse files
committed
feat(seo): add default fallback image for BlogPosting schema
1 parent cc9648c commit a320341

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

src/assets/default_img.png

295 KB
Loading

src/components/BaseHead.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// all pages through the use of the <BaseHead /> component.
44
import '../styles/global.css';
55
import type { ImageMetadata } from 'astro';
6-
import FallbackImage from '../assets/blog-placeholder-1.jpg';
6+
import FallbackImage from '../assets/default_img.png';
77
import { SITE_TITLE } from '../consts';
88
99
interface Props {

src/layouts/BlogPost.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import Footer from '../components/Footer.astro';
55
import FormattedDate from '../components/FormattedDate.astro';
66
import Giscus from '../components/Giscus.astro';
77
import Header from '../components/Header.astro';
8+
import FallbackImage from '../assets/default_img.png';
89
910
type Props = CollectionEntry<'blog'>['data'] & { slug?: string };
1011
1112
const { title, description, pubDate, updatedDate, heroImage, tags, slug } = Astro.props;
13+
const imageUrl = heroImage ? new URL(heroImage, Astro.site).href : new URL(FallbackImage.src, Astro.site).href;
1214
---
1315

1416
<html lang="ko">
@@ -20,7 +22,7 @@ const { title, description, pubDate, updatedDate, heroImage, tags, slug } = Astr
2022
"@type": "BlogPosting",
2123
"headline": title,
2224
"description": description || title,
23-
"image": heroImage ? new URL(heroImage, Astro.site).href : undefined,
25+
"image": imageUrl,
2426
"datePublished": pubDate.toISOString(),
2527
"dateModified": updatedDate ? updatedDate.toISOString() : pubDate.toISOString(),
2628
"author": {

src/layouts/BlogPostEn.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import Footer from '../components/Footer.astro';
55
import FormattedDate from '../components/FormattedDate.astro';
66
import Giscus from '../components/Giscus.astro';
77
import HeaderEn from '../components/HeaderEn.astro';
8+
import FallbackImage from '../assets/default_img.png';
89
910
type Props = CollectionEntry<'blog-en'>['data'] & { slug?: string };
1011
1112
const { title, description, pubDate, updatedDate, heroImage, tags, slug } = Astro.props;
13+
const imageUrl = heroImage ? new URL(heroImage, Astro.site).href : new URL(FallbackImage.src, Astro.site).href;
1214
---
1315

1416
<html lang="en">
@@ -20,7 +22,7 @@ const { title, description, pubDate, updatedDate, heroImage, tags, slug } = Astr
2022
"@type": "BlogPosting",
2123
"headline": title,
2224
"description": description || title,
23-
"image": heroImage ? new URL(heroImage, Astro.site).href : undefined,
25+
"image": imageUrl,
2426
"datePublished": pubDate.toISOString(),
2527
"dateModified": updatedDate ? updatedDate.toISOString() : pubDate.toISOString(),
2628
"author": {

0 commit comments

Comments
 (0)