Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit 1d5a1bd

Browse files
Fix the image in SEO
1 parent 3e5f27d commit 1d5a1bd

File tree

1 file changed

+31
-28
lines changed
  • packages/section-blog-theme/components/Seo

1 file changed

+31
-28
lines changed
Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,58 @@
1-
import { ArticleJsonLd, NextSeo } from "next-seo";
1+
import { NextSeo } from "next-seo";
22
import { TypeSectionBlogTheme } from "@/src/types";
33
import { Next_URL } from "@/utility/NextURL";
44
import { useContent } from "@/utility/useContent";
55
import { PageOpts } from "nextra";
6+
import { OpenGraphMedia } from "next-seo/lib/types";
67

7-
export function Seo({ pageOpts, themeConfig }: {pageOpts: PageOpts; themeConfig?: TypeSectionBlogTheme; }) {
8+
export function Seo({ pageOpts, themeConfig }: { pageOpts: PageOpts; themeConfig?: TypeSectionBlogTheme; }) {
9+
10+
let getSiteURL = Next_URL(themeConfig?.settings?.SiteURL)
811

912
const { frontMatter } = useContent(pageOpts);
13+
1014
const getDate = frontMatter.date
11-
const getImages:string[] = frontMatter.image !== undefined && typeof frontMatter.image === "string" ? [frontMatter?.image] : frontMatter?.image
1215

1316
if ((frontMatter.image !== undefined) || (frontMatter.tags !== undefined) || (getDate !== undefined) || (frontMatter.author !== undefined)) {
14-
15-
const getAuthor: string[] = typeof frontMatter.author === "object" ? [frontMatter?.author?.url] : [Next_URL(themeConfig?.settings?.SiteURL)]
16-
17+
18+
const getAuthor: string[] = typeof frontMatter.author === "object" ? [frontMatter?.author?.url] : [getSiteURL]
19+
1720
const keyword = frontMatter.tags && typeof frontMatter.tags !== "object" ? frontMatter?.tags?.split(',') : frontMatter?.tags
1821

22+
const getImages: OpenGraphMedia[] = frontMatter.image !== undefined && typeof frontMatter.image === "string" ? [{ url: frontMatter?.image }] : [{ url: frontMatter?.image }]
23+
1924
return (
20-
<>
21-
<NextSeo
22-
title={frontMatter.title}
23-
description={frontMatter.description}
24-
openGraph={
25-
{
26-
27-
title: frontMatter.title,
28-
description: frontMatter.description,
29-
images:getImages,
30-
type: 'article',
31-
article: {
32-
publishedTime: getDate,
33-
authors: getAuthor,
34-
tags: keyword,
35-
}
25+
<NextSeo
26+
title={frontMatter.title}
27+
description={frontMatter.description}
28+
openGraph={
29+
{
30+
31+
title: frontMatter.title,
32+
description: frontMatter.description,
33+
images: getImages,
34+
type: 'article',
35+
article: {
36+
publishedTime: getDate,
37+
authors: getAuthor,
38+
tags: keyword,
3639
}
3740
}
38-
twitter={{ cardType: "summary_large_image" }}
39-
/>
40-
41-
</>)
41+
}
42+
twitter={{ cardType: "summary_large_image" }}
43+
/>)
4244
}
4345

4446
return (
4547
<NextSeo
4648
title={frontMatter.title}
4749
description={frontMatter.description}
4850
openGraph={{
49-
url: Next_URL(themeConfig?.settings?.SiteURL),
50-
title: frontMatter.title,
51+
url: getSiteURL,
52+
title: "frontMatter is title",
5153
description: frontMatter.description,
5254
}}
55+
twitter={{ cardType: "summary" }}
5356
/>
5457
);
5558
}

0 commit comments

Comments
 (0)