fix: show full content in rss

This commit is contained in:
KazooTTT
2024-11-26 13:02:45 +08:00
parent 1631d1a6fe
commit f943d4bcdc
6 changed files with 152 additions and 58 deletions

View File

@ -2,27 +2,27 @@ import type { CollectionEntry } from 'astro:content'
import { getCollection } from 'astro:content'
/** Note: this function filters out draft posts based on the environment */
export async function getAllPosts() {
return await getCollection('post', ({ data }) => {
export async function getAllPosts(): Promise<CollectionEntry<'post'>[]> {
return await getCollection('post', ({ data }: { data: CollectionEntry<'post'> }) => {
return !data.draft && !data.category?.startsWith('日记-20')
})
}
export async function getAllSortedPosts() {
export async function getAllSortedPosts(): Promise<CollectionEntry<'post'>[]> {
return sortMDByDate(await getAllPosts())
}
export const getallDiaries = async () => {
return await getCollection('post', ({ data }) => {
export const getAllDiaries = async (): Promise<CollectionEntry<'post'>[]> => {
return await getCollection('post', ({ data }: { data: CollectionEntry<'post'> }) => {
return !data.draft && data.category?.startsWith('日记-20')
})
}
export const getallDiariesSorted = async () => {
return sortMDByDate(await getallDiaries())
export const getAllDiariesSorted = async (): Promise<CollectionEntry<'post'>[]> => {
return sortMDByDate(await getAllDiaries())
}
export function sortMDByDate(posts: Array<CollectionEntry<'post'>>) {
export function sortMDByDate(posts: Array<CollectionEntry<'post'>>): CollectionEntry<'post'>[] {
return posts.sort((a, b) => {
const aDate = new Date(a.data.date).valueOf()
const bDate = new Date(b.data.date).valueOf()
@ -31,12 +31,12 @@ export function sortMDByDate(posts: Array<CollectionEntry<'post'>>) {
}
/** Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. */
export function getAllTags(posts: Array<CollectionEntry<'post'>>) {
export function getAllTags(posts: Array<CollectionEntry<'post'>>): string[] {
return posts.flatMap((post) => [...(post.data?.tags ?? [])])
}
/** Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. */
export function getUniqueTags(posts: Array<CollectionEntry<'post'>>) {
export function getUniqueTags(posts: Array<CollectionEntry<'post'>>): string[] {
return [...new Set(getAllTags(posts))]
}
@ -58,7 +58,7 @@ export function getAllCategories(posts: Array<CollectionEntry<'post'>>): string[
}
/** Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. */
export function getUniqueCategories(posts: Array<CollectionEntry<'post'>>) {
export function getUniqueCategories(posts: Array<CollectionEntry<'post'>>): string[] {
return [...new Set(getAllCategories(posts))]
}
@ -74,7 +74,7 @@ export function getUniqueCategoriesWithCount(
].sort((a, b) => b[1] - a[1])
}
export function getIdToSlugMap(posts: Array<CollectionEntry<'post'>>) {
export function getIdToSlugMap(posts: Array<CollectionEntry<'post'>>): Record<string, string> {
return posts.reduce(
(acc, post) => {
acc[post.id.split('.md')[0]] = post.slug