Skip to content

Commit

Permalink
fix: fix og:image url not include CDN url (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaiJi authored Jan 6, 2024
1 parent 8a587b7 commit 7107a5e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/eventCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function EventCard({
const finalEventCoverImage =
event.coverUrl ||
event.posterUrl?.[0] ||
`https://cdn.furryeventchina.com/fec-event-default-cover.png`;
`https://images.furryeventchina.com/fec-event-default-cover.png`;
const isDefaultCover = finalEventCoverImage.includes(
"fec-event-default-cover"
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function Layout({
<meta
property="og:image"
content={
headMetas?.cover || "https://cdn.furryeventchina.com/banner.png"
headMetas?.cover || "https://images.furryeventchina.com/banner.png"
}
key="image"
/>
Expand All @@ -75,7 +75,7 @@ export default function Layout({
<meta
name="twitter:image"
content={
headMetas?.cover || "https://cdn.furryeventchina.com/banner.png"
headMetas?.cover || "https://images.furryeventchina.com/banner.png"
}
/>
<link rel="icon" href="/favicon.ico" />
Expand Down
14 changes: 12 additions & 2 deletions src/pages/[organization]/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,11 @@ export async function getStaticProps(context: GetStaticPropsContext) {
event?.address
}”举办,喜欢的朋友记得关注开始售票时间~`,
url: `https://www.furryeventchina.com/${context.params?.organization}/${event?.slug}`,
cover: event?.coverUrl || event?.posterUrl?.[0],
cover: imageUrl(
event?.coverUrl ||
event?.posterUrl?.[0] ||
"https://images.furryeventchina.com/fec-event-default-cover.png"
),
},
structuredData: {
breadcrumb: {
Expand Down Expand Up @@ -598,7 +602,13 @@ export async function getStaticProps(context: GetStaticPropsContext) {
addressCountry: "CN",
},
},
image: [event?.coverUrl || event?.posterUrl?.[0]],
image: [
imageUrl(
event?.coverUrl ||
event?.posterUrl?.[0] ||
"https://images.furryeventchina.com/fec-event-default-cover.png"
),
],
description: event?.detail,
// offers: {
// "@type": "Offer",
Expand Down
10 changes: 6 additions & 4 deletions src/utils/imageLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,34 @@ export const getEventCoverUrl = (event: Partial<EventRecord>) => {
return imageUrl(
event.coverUrl ||
event.posterUrl?.[0] ||
`https://cdn.furryeventchina.com/fec-event-default-cover.png`,
`https://images.furryeventchina.com/fec-event-default-cover.png`,
true
);
};

export const imageUrl = (src: string, needAutoCDN: boolean = false) => {
const withoutDefaultHostSrc = src
.replace("https://cdn.furryeventchina.com/", "")
.replace("https://images.furryeventchina.com/", "")
.replace("https://images.furrycons.cn/", "")
.trim();

const isEnableCNCalc = isEnableCN();

if (!needAutoCDN)
return `https://cdn.furryeventchina.com/${withoutDefaultHostSrc}`;
return `https://images.furryeventchina.com/${withoutDefaultHostSrc}`;

if (isEnableCNCalc) {
return `https://${CN_IMAGE_URL}/${withoutDefaultHostSrc}`;
} else {
return `https://cdn.furryeventchina.com/${withoutDefaultHostSrc}`;
return `https://images.furryeventchina.com/${withoutDefaultHostSrc}`;
}
};

const imageLoader = ({ src, width, quality }: ImageLoaderProps) => {
const withoutDefaultHostSrc = src
.replace("https://cdn.furryeventchina.com/", "")
.replace("https://images.furryeventchina.com/", "")
.replace("https://images.furrycons.cn/", "")
.trim();

Expand All @@ -55,7 +57,7 @@ const imageLoader = ({ src, width, quality }: ImageLoaderProps) => {
quality || 75
}`;
} else {
return `https://cdn.furryeventchina.com/${withoutDefaultHostSrc}?w=${width}&q=${
return `https://images.furryeventchina.com/${withoutDefaultHostSrc}?w=${width}&q=${
quality || 75
}`;
}
Expand Down

0 comments on commit 7107a5e

Please sign in to comment.