Skip to content

Commit

Permalink
related posts fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kremalicious committed Sep 14, 2023
1 parent 5c1b37c commit ef3e6d5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
3 changes: 2 additions & 1 deletion content/_schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
17 changes: 8 additions & 9 deletions src/components/RelatedPosts/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/astro/getAllPostsForSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ef3e6d5

Please sign in to comment.