Skip to content

Commit 2174a3a

Browse files
committed
update og description for blog posts
1 parent a9e44d6 commit 2174a3a

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ pnpm-debug.log*
2222

2323
# jetbrains setting folder
2424
.idea/
25+
26+
# Local Netlify folder
27+
.netlify

src/content.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { defineCollection, z } from "astro:content";
22
import { glob } from "astro/loaders";
3-
import { has } from "markdown-it/lib/common/utils.mjs";
43

54
const blog = defineCollection({
65
loader: glob({ base: "./src/content/blog", pattern: "**/*.{md,mdx}" }),

src/layouts/BlogLayout.astro

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
---
22
import BaseLayout from "./BaseLayout.astro";
33
import FormattedDate from "@/components/FormattedDate.astro";
4-
import { slugify } from "@/utils";
4+
import { slugify, createExcerpt } from "@/utils";
55
import "@/styles/posts.css";
66
7-
const { title, date, tags, noindex, og_image, external_url, hastweet, hascaniuse, hascodepen } =
8-
Astro.props;
7+
const {
8+
title,
9+
date,
10+
tags,
11+
noindex,
12+
og_image,
13+
external_url,
14+
hastweet,
15+
hascaniuse,
16+
hascodepen,
17+
description,
18+
} = Astro.props;
919
const dateObj = new Date(date);
1020
const canonicalURL = external_url ? external_url : new URL(Astro.url.pathname, Astro.site).href;
1121
---
1222

1323
<BaseLayout
1424
title={title}
25+
description={description}
1526
ogImageUrl={og_image}
1627
noindex={noindex}
1728
ogType="article"

src/pages/blog/[...slug].astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
import { type CollectionEntry, getCollection, render } from "astro:content";
33
import BlogLayout from "@/layouts/BlogLayout.astro";
4+
import { createExcerpt } from "@/utils";
45
56
export async function getStaticPaths() {
67
const posts = await getCollection("blog");
@@ -13,8 +14,9 @@ type Props = CollectionEntry<"blog">;
1314
1415
const post = Astro.props;
1516
const { Content } = await render(post);
17+
const ogDescription = post.data.description ? post.data.description : createExcerpt(post.body, 160);
1618
---
1719

18-
<BlogLayout {...post.data}>
20+
<BlogLayout {...post.data} description={ogDescription}>
1921
<Content />
2022
</BlogLayout>

0 commit comments

Comments
 (0)