1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-28 00:27:58 +02:00
blog/src/lib/astro/getAllPostsForSearch.ts
Matthias Kretschmann c123dd9d68
Switch to astro-redirect-from (#830)
* astro-redirect-from prototype

* move out plugin

* switch to astro-redirect-from

* fixes

* new post: astro-redirect-from

* fix dependency

* test fixes

* downgrade and lock astro

* until fix for https://github.com/withastro/astro/issues/8649 has been released

* mention debug json file

* fix e2e test
2023-09-23 21:32:18 +01:00

37 lines
908 B
TypeScript

import { type CollectionEntry } from 'astro:content'
import { getAllPosts } from './getAllPosts'
// helps to reduce DOM size
export async function getAllPostsForSearch() {
const allPosts = await getAllPosts()
if (!allPosts) return []
const cleaned = await Promise.all(
allPosts.map(async (post) => {
const imageSrc = (
post.data as CollectionEntry<'articles' | 'photos'>['data']
).image
// const image = imageSrc
// ? await getImage({
// src: imageSrc,
// width: 300,
// height: 100,
// format: 'png'
// })
// : null
return {
slug: post.slug,
collection: post.collection,
data: {
title: post.data.title,
tags: post.data.tags,
lead: post.body.substring(0, 200),
image: imageSrc
}
}
})
)
return cleaned
}