fix: open graph function

feat/open-graph
Arik Chakma 9 months ago
parent d1b27854ea
commit 4f9917bc5c
  1. 19
      src/lib/open-graph.ts
  2. 13
      src/pages/[roadmapId]/index.astro
  3. 17
      src/pages/backend/developer-skills.astro
  4. 17
      src/pages/backend/languages.astro
  5. 13
      src/pages/best-practices/[bestPracticeId]/index.astro
  6. 17
      src/pages/guides/[guideId].astro

@ -0,0 +1,19 @@
type GuideOpenGraphParams = {
type: 'guide';
authorName: string;
authorAvatar?: string;
title: string;
description: string;
};
type RoadmapOpenGraphParams = {
type: 'roadmap';
title: string;
description: string;
};
export function getOpenGraphImageUrl(
params: GuideOpenGraphParams | RoadmapOpenGraphParams,
) {
return `${import.meta.env.PUBLIC_API_URL}/v1-open-graph?${new URLSearchParams(params)}`;
}

@ -13,6 +13,7 @@ import {
generateArticleSchema,
generateFAQSchema,
} from '../../lib/jsonld-schema';
import { getOpenGraphImageUrl } from '../../lib/open-graph';
import { type RoadmapFrontmatter, getRoadmapIds } from '../../lib/roadmap';
export async function getStaticPaths() {
@ -56,13 +57,11 @@ if (roadmapFAQs.length) {
jsonLdSchema.push(generateFAQSchema(roadmapFAQs));
}
const ogImageUrl =
roadmapData?.seo?.ogImageUrl ||
`${import.meta.env.PUBLIC_API_URL}/v1-open-graph?${new URLSearchParams({
type: 'roadmap',
title: roadmapData.title,
description: roadmapData.description,
})}`;
const ogImageUrl = getOpenGraphImageUrl({
type: 'roadmap',
title: roadmapData.title,
description: roadmapData.description,
});
---
<BaseLayout

@ -3,21 +3,20 @@ import GuideHeader from '../../components/GuideHeader.astro';
import MarkdownFile from '../../components/MarkdownFile.astro';
import BaseLayout from '../../layouts/BaseLayout.astro';
import { getGuideById } from '../../lib/guide';
import { getOpenGraphImageUrl } from '../../lib/open-graph';
const guideId = 'backend-developer-skills';
const guide = await getGuideById(guideId);
const { frontmatter: guideData, author } = guide!;
const ogImageUrl = `${import.meta.env.PUBLIC_API_URL}/v1-open-graph?${new URLSearchParams(
{
type: 'guide',
title: guideData.title,
description: guideData.description,
authorName: author.frontmatter?.name,
authorAvatar: author.frontmatter?.imageUrl || '',
},
)}`;
const ogImageUrl = getOpenGraphImageUrl({
type: 'guide',
title: guideData.title,
description: guideData.description,
authorName: author.frontmatter?.name,
authorAvatar: author.frontmatter?.imageUrl || '',
});
---
<BaseLayout

@ -3,21 +3,20 @@ import GuideHeader from '../../components/GuideHeader.astro';
import MarkdownFile from '../../components/MarkdownFile.astro';
import BaseLayout from '../../layouts/BaseLayout.astro';
import { getGuideById } from '../../lib/guide';
import { getOpenGraphImageUrl } from '../../lib/open-graph';
const guideId = 'backend-languages';
const guide = await getGuideById('backend-languages');
const { frontmatter: guideData, author } = guide!;
const ogImageUrl = `${import.meta.env.PUBLIC_API_URL}/v1-open-graph?${new URLSearchParams(
{
type: 'guide',
title: guideData.title,
description: guideData.description,
authorName: author.frontmatter?.name,
authorAvatar: author.frontmatter?.imageUrl || '',
},
)}`;
const ogImageUrl = getOpenGraphImageUrl({
type: 'guide',
title: guideData.title,
description: guideData.description,
authorName: author.frontmatter?.name,
authorAvatar: author.frontmatter?.imageUrl || '',
});
---
<BaseLayout

@ -13,6 +13,7 @@ import {
getAllBestPractices,
} from '../../../lib/best-pratice';
import { generateArticleSchema } from '../../../lib/jsonld-schema';
import { getOpenGraphImageUrl } from '../../../lib/open-graph';
export async function getStaticPaths() {
const bestPractices = await getAllBestPractices();
@ -53,13 +54,11 @@ if (bestPracticeData.schema) {
);
}
const ogImageUrl = `${import.meta.env.PUBLIC_API_URL}/v1-open-graph?${new URLSearchParams(
{
type: 'roadmap',
title: bestPracticeData.title,
description: bestPracticeData.description,
},
)}`;
const ogImageUrl = getOpenGraphImageUrl({
type: 'roadmap',
title: bestPracticeData.title,
description: bestPracticeData.description,
});
---
<BaseLayout

@ -3,6 +3,7 @@ import GuideHeader from '../../components/GuideHeader.astro';
import MarkdownFile from '../../components/MarkdownFile.astro';
import BaseLayout from '../../layouts/BaseLayout.astro';
import { getAllGuides, type GuideFileType } from '../../lib/guide';
import { getOpenGraphImageUrl } from '../../lib/open-graph';
export interface Props {
guide: GuideFileType;
@ -23,15 +24,13 @@ const { guideId } = Astro.params;
const { guide } = Astro.props;
const { frontmatter: guideData, author } = guide;
const ogImageUrl = `${import.meta.env.PUBLIC_API_URL}/v1-open-graph?${new URLSearchParams(
{
type: 'guide',
title: guideData.title,
description: guideData.description,
authorName: author.frontmatter?.name,
authorAvatar: author.frontmatter?.imageUrl || '',
},
)}`;
const ogImageUrl = getOpenGraphImageUrl({
type: 'guide',
title: guideData.title,
description: guideData.description,
authorName: author.frontmatter?.name,
authorAvatar: author.frontmatter?.imageUrl || '',
});
---
<BaseLayout

Loading…
Cancel
Save