Skip to content

Commit

Permalink
fix: the bug when share chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Coooder-Crypto committed Jan 28, 2025
1 parent f3ec122 commit 2426087
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/app/learn/[type]/[id]/[chapter_id]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,31 @@
*/

import { get } from '@/utils/request';

import { Steper } from './Steper';
import { Content } from './Content';
import { PostTime } from './PostTime';

export async function generateMetadata({ params }) {
// fetch data
const { data } = await get(`v1/learn/course/${params.type === 'courses' ? 'opencourse' : 'challenges'}/${params.id}`, {isServer: true});
const previousImages = data?.base?.course_series_img ? `https://file-cdn.openbuild.xyz${data.base.course_series_img}` : '';
const chapter = data.courses.find(course => String(course?.base?.course_single_id) === params.chapter_id);

return {
title: data?.base?.course_series_title,
description: data?.base?.course_series_summary,
openGraph: {
title: chapter?.base?.course_single_name || data?.base?.course_series_title,
images: [previousImages],
},
twitter: {
card: 'summary_large_image',
title: chapter?.base?.course_single_name || data?.base?.course_series_title,
images: [previousImages],
},
};
}

export default async function ChapterPage({ params }) {
const datas = await Promise.all([
get(`v1/learn/course/${params.type === 'courses' ? 'opencourse' : 'challenges'}/${params.id}`, {isServer: true}),
Expand Down
2 changes: 1 addition & 1 deletion src/app/learn/[type]/[id]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { GrowPath } from './GrowPath';
export async function generateMetadata({ params }) {
// fetch data
const { data } = await get(`v1/learn/course/${params.type === 'courses' ? 'opencourse' : 'challenges'}/${params.id}`, {isServer: true});
const previousImages = `https://file-cdn.openbuild.xyz${data?.base?.course_series_img}` || '';
const previousImages = data?.base?.course_series_img ? `https://file-cdn.openbuild.xyz${data.base.course_series_img}` : '';
return {
title: data?.base?.course_series_title,
description: data?.base?.course_series_summary,
Expand Down

0 comments on commit 2426087

Please sign in to comment.