From ef3e6d59750a6c378586e39c8201a2caada899ae Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 15 Sep 2023 00:38:00 +0100 Subject: [PATCH] related posts fixes --- content/_schemas.ts | 3 ++- .../index.md | 2 +- src/components/RelatedPosts/index.astro | 17 ++++++++--------- src/lib/astro/getAllPostsForSearch.ts | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/content/_schemas.ts b/content/_schemas.ts index 811aed3b0..3289a687e 100644 --- a/content/_schemas.ts +++ b/content/_schemas.ts @@ -25,7 +25,8 @@ const schemaShared = { style: z.string().optional(), toc: z.boolean().optional(), githubLink: z.string().optional(), - changelog: z.string().optional() + changelog: z.string().optional(), + lead: z.string().optional() } export const schemaArticles = (image: ImageFunction) => diff --git a/content/articles/2023-09-13-favicon-generation-with-astro/index.md b/content/articles/2023-09-13-favicon-generation-with-astro/index.md index c0605b9af..0f51e1b10 100644 --- a/content/articles/2023-09-13-favicon-generation-with-astro/index.md +++ b/content/articles/2023-09-13-favicon-generation-with-astro/index.md @@ -13,7 +13,7 @@ toc: true draft: true --- -Those small but impactful icons displayed next to a website's title in a browser tab seem like a minor detail. Implementing favicons involves various considerations for different formats and sizes to fit a range of devices and browsers. Luckily, we can always count on Evil Martians to tell us [which files are needed](https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs) in modern times. Those findings can be implemented quite easy in Astro. +Those small but impactful icons displayed next to a website's title in a browser tab seem like a minor detail, yet implementing favicons involves various considerations for different formats and sizes to fit a range of devices and browsers. Luckily, we can always count on Evil Martians to tell us [which files are needed](https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs) in modern times. Those findings can be implemented quite easy in Astro. This article outlines how to implement just that with [Astro](https://astro.build), utilizing its [Static File Endpoints](https://docs.astro.build/en/core-concepts/endpoints/) and [`getImage()`](https://docs.astro.build/en/guides/images/#generating-images-with-getimage) function to generate multiple favicon sizes. diff --git a/src/components/RelatedPosts/index.astro b/src/components/RelatedPosts/index.astro index cf2a713a2..3b016c41f 100644 --- a/src/components/RelatedPosts/index.astro +++ b/src/components/RelatedPosts/index.astro @@ -18,23 +18,22 @@ const allPosts = await getAllPostsForSearch() const fuseOptions: Fuse.IFuseOptions< CollectionEntry<'articles' | 'photos' | 'links'> > = { - keys: ['data.tags', 'data.title', 'collection'], - includeMatches: true, + keys: ['data.tags', 'data.title', 'data.lead', 'collection'], useExtendedSearch: true, minMatchCharLength: 3, - threshold: 0.5 + threshold: 0.8 } -// TODO; firgure out how to remove any -const fuse = new Fuse( - (allPosts as any).filter((post: any) => post.slug !== Astro.props.post.slug), - fuseOptions +// TODO; figure out how to remove any +const allPostsWithoutCurrent = allPosts.filter( + (post) => post.slug !== Astro.props.post.slug ) +const fuse = new Fuse(allPostsWithoutCurrent as any, fuseOptions) const relatedPosts = fuse // https://www.fusejs.io/examples.html#extended-search .search( `${post?.data?.tags?.join(' | ')} | ${post?.data?.title} | ${ - post.collection - }` + (post?.data as any)?.lead + } | ${post?.collection}` ) .map((result) => result.item) .slice(0, 6) diff --git a/src/lib/astro/getAllPostsForSearch.ts b/src/lib/astro/getAllPostsForSearch.ts index f881cd8a0..2834b3b80 100644 --- a/src/lib/astro/getAllPostsForSearch.ts +++ b/src/lib/astro/getAllPostsForSearch.ts @@ -21,10 +21,10 @@ export async function getAllPostsForSearch() { // : null return { slug: post.slug, + collection: post.collection, data: { title: post.data.title, tags: post.data.tags, - collection: post.collection, lead: post.body.substring(0, 200), image: imageSrc }