From 790c91c342ea74a431dcca85000d5facc79d8980 Mon Sep 17 00:00:00 2001 From: KazooTTT Date: Sat, 23 Nov 2024 16:51:13 +0800 Subject: [PATCH] feat: add rss --- src/components/GithubHotLine.tsx | 1 - src/components/layout/Footer.astro | 7 +++++++ src/icons/rss.svg | 5 +++++ src/pages/index.astro | 2 +- src/pages/rss.xml.js | 8 ++++---- src/utils/index.ts | 1 + src/utils/post.ts | 4 ++++ 7 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 src/icons/rss.svg diff --git a/src/components/GithubHotLine.tsx b/src/components/GithubHotLine.tsx index a7be970..4f44546 100644 --- a/src/components/GithubHotLine.tsx +++ b/src/components/GithubHotLine.tsx @@ -1,5 +1,4 @@ import GitHubCalendar from "react-github-calendar"; -import React from "react"; const GithubHotLine = () => { return ( diff --git a/src/components/layout/Footer.astro b/src/components/layout/Footer.astro index feff9d8..4576cf1 100644 --- a/src/components/layout/Footer.astro +++ b/src/components/layout/Footer.astro @@ -48,6 +48,13 @@ import { Icon } from 'astro-icon/components' > + + + diff --git a/src/icons/rss.svg b/src/icons/rss.svg new file mode 100644 index 0000000..87a927a --- /dev/null +++ b/src/icons/rss.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/pages/index.astro b/src/pages/index.astro index 3aa7622..7e91d59 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -45,7 +45,7 @@ const mdProjects = allPosts .map((post) => ({ title: post.data.title, description: post.data.description || '', - url: post.data.projectUrl ? post.data.projectUrl : `/posts/${post.slug}`, + url: post.data.projectUrl ? post.data.projectUrl : `/blog/${post.slug}`, imagePath: post.data.coverImage, altText: post.data.title, isExternal: !!post.data.projectUrl diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index 0e6a689..dcfca0d 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -1,17 +1,17 @@ import rss from '@astrojs/rss' import { siteConfig } from '@/site-config' -import { getAllPosts } from '@/utils' +import { getAllSortedPosts } from '@/utils' export const GET = async () => { - const posts = await getAllPosts() + const posts = await getAllSortedPosts() return rss({ title: siteConfig.title, description: siteConfig.description, site: import.meta.env.SITE, items: posts.map((post) => ({ - title: post.data.title, - description: post.data.description, + title: post.data.title ?? '', + description: `${post.data.description ?? ''}\nfeedId:76245438397618182+userId:62156866798228480`, pubDate: post.data.date, link: `/blog/${post.slug}` })) diff --git a/src/utils/index.ts b/src/utils/index.ts index 42d5d2b..d4ee163 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,7 @@ export { cn } from './tailwind' export { getAllPosts, + getAllSortedPosts, sortMDByDate, getUniqueTags, getUniqueTagsWithCount, diff --git a/src/utils/post.ts b/src/utils/post.ts index 3eca3c4..a4f8d64 100644 --- a/src/utils/post.ts +++ b/src/utils/post.ts @@ -8,6 +8,10 @@ export async function getAllPosts() { }) } +export async function getAllSortedPosts() { + return sortMDByDate(await getAllPosts()) +} + export function sortMDByDate(posts: Array>) { return posts.sort((a, b) => { const aDate = new Date(a.data.date).valueOf()