|
1 | | -import { ArticleJsonLd, NextSeo } from "next-seo"; |
| 1 | +import { NextSeo } from "next-seo"; |
2 | 2 | import { TypeSectionBlogTheme } from "@/src/types"; |
3 | 3 | import { Next_URL } from "@/utility/NextURL"; |
4 | 4 | import { useContent } from "@/utility/useContent"; |
5 | 5 | import { PageOpts } from "nextra"; |
| 6 | +import { OpenGraphMedia } from "next-seo/lib/types"; |
6 | 7 |
|
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) |
8 | 11 |
|
9 | 12 | const { frontMatter } = useContent(pageOpts); |
| 13 | + |
10 | 14 | const getDate = frontMatter.date |
11 | | - const getImages:string[] = frontMatter.image !== undefined && typeof frontMatter.image === "string" ? [frontMatter?.image] : frontMatter?.image |
12 | 15 |
|
13 | 16 | 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 | + |
17 | 20 | const keyword = frontMatter.tags && typeof frontMatter.tags !== "object" ? frontMatter?.tags?.split(',') : frontMatter?.tags |
18 | 21 |
|
| 22 | + const getImages: OpenGraphMedia[] = frontMatter.image !== undefined && typeof frontMatter.image === "string" ? [{ url: frontMatter?.image }] : [{ url: frontMatter?.image }] |
| 23 | + |
19 | 24 | 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, |
36 | 39 | } |
37 | 40 | } |
38 | | - twitter={{ cardType: "summary_large_image" }} |
39 | | - /> |
40 | | - |
41 | | - </>) |
| 41 | + } |
| 42 | + twitter={{ cardType: "summary_large_image" }} |
| 43 | + />) |
42 | 44 | } |
43 | 45 |
|
44 | 46 | return ( |
45 | 47 | <NextSeo |
46 | 48 | title={frontMatter.title} |
47 | 49 | description={frontMatter.description} |
48 | 50 | openGraph={{ |
49 | | - url: Next_URL(themeConfig?.settings?.SiteURL), |
50 | | - title: frontMatter.title, |
| 51 | + url: getSiteURL, |
| 52 | + title: "frontMatter is title", |
51 | 53 | description: frontMatter.description, |
52 | 54 | }} |
| 55 | + twitter={{ cardType: "summary" }} |
53 | 56 | /> |
54 | 57 | ); |
55 | 58 | } |
0 commit comments