From de4de10703ab724faf20900068695c212d53355f Mon Sep 17 00:00:00 2001 From: grassblock Date: Fri, 16 May 2025 21:34:02 +0800 Subject: [PATCH] feat: add a friend link (blogroll) shortcode --- src/components/shortcodes/BlogRoll.astro | 19 ++++++++++++++++++ src/content/config.ts | 25 +++++++++++++++++------- src/content/pages/test.md | 5 ----- src/content/pages/test.mdx | 9 +++++++++ src/content/posts/_schemas.ts | 2 +- src/data/links.yaml | 7 +++++++ 6 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 src/components/shortcodes/BlogRoll.astro delete mode 100644 src/content/pages/test.md create mode 100644 src/content/pages/test.mdx create mode 100644 src/data/links.yaml diff --git a/src/components/shortcodes/BlogRoll.astro b/src/components/shortcodes/BlogRoll.astro new file mode 100644 index 0000000..5708b1b --- /dev/null +++ b/src/components/shortcodes/BlogRoll.astro @@ -0,0 +1,19 @@ +--- +import {getCollection} from "astro:content"; +import { Image } from 'astro:assets'; +const links = await getCollection('links'); +--- +

My Blogroll

+{links.length > 0 && links.map((link => + +))} + \ No newline at end of file diff --git a/src/content/config.ts b/src/content/config.ts index f0cc13e..c330693 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,17 +1,28 @@ -import { defineCollection } from 'astro:content'; -import { posts } from './posts/_schemas'; -import { pages } from "./pages/_schemas"; +import {defineCollection} from 'astro:content'; +import {posts} from './posts/_schemas'; +import {pages} from "./pages/_schemas"; +import {file} from 'astro/loaders'; +import { z } from 'astro:content'; const blogCollection = defineCollection({ - type: 'content', - schema: posts, + type: 'content', + schema: posts, }); const pageCollection = defineCollection({ type: 'content', schema: pages, }); +const blogRollData = defineCollection({ + loader: file("src/data/links.yaml"), + schema: z.object({ + link: z.string(), + avatar: z.string().optional(), + description: z.string().optional(), + }) +}); export const collections = { - 'posts': blogCollection, - 'pages': pageCollection, + 'posts': blogCollection, + 'pages': pageCollection, + 'links': blogRollData, }; \ No newline at end of file diff --git a/src/content/pages/test.md b/src/content/pages/test.md deleted file mode 100644 index 7818aee..0000000 --- a/src/content/pages/test.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: 'Test Page' -description: 'This is a test page' ---- -testestestest \ No newline at end of file diff --git a/src/content/pages/test.mdx b/src/content/pages/test.mdx new file mode 100644 index 0000000..2f6b370 --- /dev/null +++ b/src/content/pages/test.mdx @@ -0,0 +1,9 @@ +--- +title: 'Test Page' +description: 'This is a test page' +--- +import BlogRoll from "../../components/shortcodes/BlogRoll.astro" + +testestestest + + \ No newline at end of file diff --git a/src/content/posts/_schemas.ts b/src/content/posts/_schemas.ts index 25b39dd..e62adfb 100644 --- a/src/content/posts/_schemas.ts +++ b/src/content/posts/_schemas.ts @@ -1,6 +1,6 @@ import { z } from 'astro:content'; -export const posts = ({ image }:{image: ()=> z.ZodAny}) => z.object({ +export const posts = ({ image }) => z.object({ title: z.string(), description: z.string(), pubDate: z.coerce.date(), diff --git a/src/data/links.yaml b/src/data/links.yaml new file mode 100644 index 0000000..ae22321 --- /dev/null +++ b/src/data/links.yaml @@ -0,0 +1,7 @@ +Link: # the name/title of the destination + link: https://www.youtube.com/watch?v=cqT0OKlEo9w # the link to the destination + avatar: https://example.org/avatar.png # set an avatar + description: We know each other for so long # the description +Another Link: + link: https://google.com + description: Your heart's been aching, but you're too shy to say it \ No newline at end of file