feat: implement open graph (#5340)
* chore: add open graph images * fix: open graph function * fix: open graph query params * fix: remove guide id * fix: generate images on build time * fix: external author image * fix: special character issue --------- Co-authored-by: Kamran Ahmed <kamranahmed.se@gmail.com>
This commit is contained in:
1 parent
ec9d2d4c74
commit
d0bd4d6faf
104 files changed
+981
-19
No files matched your search
@@ -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() {
|
||||
@@ -55,14 +56,20 @@ if (roadmapData.schema) {
|
||||
if (roadmapFAQs.length) {
|
||||
jsonLdSchema.push(generateFAQSchema(roadmapFAQs));
|
||||
}
|
||||
|
||||
const ogImageUrl =
|
||||
roadmapData?.seo?.ogImageUrl ||
|
||||
getOpenGraphImageUrl({
|
||||
group: 'roadmaps',
|
||||
resourceId: roadmapId,
|
||||
});
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
permalink={`/${roadmapId}`}
|
||||
title={roadmapData?.seo?.title}
|
||||
briefTitle={roadmapData.briefTitle}
|
||||
ogImageUrl={roadmapData?.seo?.ogImageUrl ||
|
||||
'https://roadmap.sh/images/og-img.png'}
|
||||
ogImageUrl={ogImageUrl}
|
||||
description={roadmapData.seo.description}
|
||||
keywords={roadmapData.seo.keywords}
|
||||
noIndex={roadmapData.isUpcoming}
|
||||
|
||||
@@ -30,7 +30,7 @@ const videos = await getVideosByAuthor(authorId);
|
||||
permalink={`/author/${author.id}`}
|
||||
title={`${author.frontmatter.name} - Author at roadmap.sh`}
|
||||
briefTitle={author.frontmatter.name}
|
||||
ogImageUrl={`https://roadmap.sh/${author.frontmatter.imageUrl}`}
|
||||
ogImageUrl={`https://roadmap.sh/${authorFrontmatter.imageUrl}`}
|
||||
description={`${author.frontmatter.name} has written ${guides.length} articles on roadmap.sh on a variety of topics.`}
|
||||
noIndex={false}
|
||||
jsonLd={[
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { getAuthorById, getAuthorIds } from '../../lib/author';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const authorIds = await getAuthorIds();
|
||||
|
||||
return await Promise.all(
|
||||
authorIds.map(async (authorId) => {
|
||||
const authorDetails = await getAuthorById(authorId);
|
||||
|
||||
return {
|
||||
params: { authorId },
|
||||
props: {
|
||||
authorDetails: authorDetails?.frontmatter || {},
|
||||
},
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export const GET: APIRoute = async function ({ params, request, props }) {
|
||||
return new Response(JSON.stringify(props.authorDetails), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -3,18 +3,25 @@ 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 } = guide;
|
||||
const { frontmatter: guideData } = guide!;
|
||||
|
||||
const ogImageUrl = getOpenGraphImageUrl({
|
||||
group: 'guides',
|
||||
resourceId: guideId,
|
||||
});
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
title={guideData.seo.title}
|
||||
description={guideData.seo.description}
|
||||
permalink={`/backend/${guideId}`}
|
||||
canonicalUrl={guideData.canonicalUrl}
|
||||
title={guideData.seo.title}
|
||||
description={guideData.seo.description}
|
||||
permalink={`/backend/${guideId}`}
|
||||
canonicalUrl={guideData.canonicalUrl}
|
||||
ogImageUrl={ogImageUrl}
|
||||
>
|
||||
<GuideHeader guide={guide} />
|
||||
|
||||
|
||||
@@ -3,11 +3,17 @@ 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 } = guide;
|
||||
const { frontmatter: guideData } = guide!;
|
||||
|
||||
const ogImageUrl = getOpenGraphImageUrl({
|
||||
group: 'guides',
|
||||
resourceId: guideId,
|
||||
});
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
@@ -15,8 +21,9 @@ const { frontmatter: guideData } = guide;
|
||||
description={guideData.seo.description}
|
||||
permalink={`/backend/${guideId}`}
|
||||
canonicalUrl={guideData.canonicalUrl}
|
||||
ogImageUrl={ogImageUrl}
|
||||
>
|
||||
<GuideHeader guide={guide} />
|
||||
<GuideHeader guide={guide!} />
|
||||
|
||||
<div class='mx-auto max-w-[700px] py-5 sm:py-10'>
|
||||
<MarkdownFile>
|
||||
|
||||
@@ -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();
|
||||
@@ -52,12 +53,18 @@ if (bestPracticeData.schema) {
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const ogImageUrl = getOpenGraphImageUrl({
|
||||
group: 'best-practices',
|
||||
resourceId: bestPracticeId,
|
||||
});
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
permalink={`/best-practices/${bestPracticeId}`}
|
||||
title={bestPracticeData?.seo?.title}
|
||||
briefTitle={bestPracticeData?.briefTitle}
|
||||
ogImageUrl={ogImageUrl}
|
||||
description={bestPracticeData.seo.description}
|
||||
keywords={bestPracticeData.seo.keywords}
|
||||
noIndex={bestPracticeData.isUpcoming}
|
||||
|
||||
@@ -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;
|
||||
@@ -21,7 +22,12 @@ export async function getStaticPaths() {
|
||||
|
||||
const { guideId } = Astro.params;
|
||||
const { guide } = Astro.props;
|
||||
const { frontmatter: guideData } = guide;
|
||||
const { frontmatter: guideData, author } = guide;
|
||||
|
||||
const ogImageUrl = getOpenGraphImageUrl({
|
||||
group: 'guides',
|
||||
resourceId: guideId,
|
||||
});
|
||||
---
|
||||
|
||||
<BaseLayout
|
||||
@@ -29,6 +35,7 @@ const { frontmatter: guideData } = guide;
|
||||
description={guideData.seo.description}
|
||||
permalink={`/guides/${guideId}`}
|
||||
canonicalUrl={guideData.canonicalUrl}
|
||||
ogImageUrl={ogImageUrl}
|
||||
>
|
||||
<GuideHeader guide={guide} />
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ export async function GET() {
|
||||
id: roadmap.id,
|
||||
url: `/${roadmap.id}`,
|
||||
title: roadmap.frontmatter.briefTitle,
|
||||
description: roadmap.frontmatter.briefDescription,
|
||||
group: 'Roadmaps',
|
||||
metadata: {
|
||||
tags: roadmap.frontmatter.tags,
|
||||
@@ -26,6 +27,7 @@ export async function GET() {
|
||||
id: bestPractice.id,
|
||||
url: `/best-practices/${bestPractice.id}`,
|
||||
title: bestPractice.frontmatter.briefTitle,
|
||||
description: bestPractice.frontmatter.briefDescription,
|
||||
group: 'Best Practices',
|
||||
})),
|
||||
...questionGroups.map((questionGroup) => ({
|
||||
@@ -40,12 +42,14 @@ export async function GET() {
|
||||
? guide.frontmatter.excludedBySlug
|
||||
: `/guides/${guide.id}`,
|
||||
title: guide.frontmatter.title,
|
||||
description: guide.frontmatter.description,
|
||||
authorId: guide.frontmatter.authorId,
|
||||
group: 'Guides',
|
||||
})),
|
||||
...videos.map((guide) => ({
|
||||
id: guide.id,
|
||||
url: `/videos/${guide.id}`,
|
||||
title: guide.frontmatter.title,
|
||||
...videos.map((video) => ({
|
||||
id: video.id,
|
||||
url: `/videos/${video.id}`,
|
||||
title: video.frontmatter.title,
|
||||
group: 'Videos',
|
||||
})),
|
||||
]),
|
||||
|
||||
Reference in new issue
Block a user