1
0
Fork 0

related posts tweaks

This commit is contained in:
Matthias Kretschmann 2023-09-19 13:41:37 +01:00
parent ca96ae9549
commit 124934e6fb
Signed by: m
GPG Key ID: 606EEEF3C479A91F
8 changed files with 38 additions and 73 deletions

View File

@ -5,6 +5,7 @@ author: Matthias Kretschmann
--- ---
Ai Weiwei - Evidence, Stools at Martin Gropius Bau Ai Weiwei - Evidence, Stools at Martin Gropius Bau
Processed with VSCOcam with b2 preset Processed with VSCOcam with b2 preset
[flickr](https://www.flickr.com/photos/krema/14016811365/) | [EyeEm](http://www.eyeem.com/p/35839008) [flickr](https://www.flickr.com/photos/krema/14016811365/) | [EyeEm](http://www.eyeem.com/p/35839008)

View File

@ -1,7 +1,7 @@
--- ---
date: 2021-11-26T15:32:28.000Z date: 2021-11-26T15:32:28.000Z
title: Forever Bicycles title: Ai Weiwei, Forever Bicycles
image: ./2021-11-26-forever-bicycles.jpg image: ./2021-11-26-forever-bicycles.jpg
--- ---

View File

@ -1,7 +1,7 @@
--- ---
date: 2021-11-26T16:12:03.000Z date: 2021-11-26T16:12:03.000Z
title: Law of the Journey title: Ai Weiwei, Law of the Journey
image: ./2021-11-26-law-of-the-journey.jpg image: ./2021-11-26-law-of-the-journey.jpg
--- ---

View File

@ -9,35 +9,22 @@ const { title, image } = data
--- ---
<style> <style>
.photo a { .photo {
display: block; display: block;
} }
.photo figure,
.photo figure > div {
margin: 0;
}
.photo figcaption {
font-size: var(--font-size-base);
padding-left: calc(var(--spacer) / 2);
padding-right: calc(var(--spacer) / 2);
}
</style> </style>
<article class="photo"> {
{ image ? (
image ? ( <a class="photo" href={`/${slug}`}>
<a href={`/${slug}`}> <Picture
<Picture width={202}
width={184} height={202}
height={184} src={image}
src={image} alt={title}
alt={title} title={title}
title={title} objectFit
objectFit />
/> </a>
</a> ) : null
) : null }
}
</article>

View File

@ -12,45 +12,35 @@ type Props = {
} }
const { post, isPhotos } = Astro.props as Props const { post, isPhotos } = Astro.props as Props
const allPosts = await getAllPostsForSearch() const allPosts = await getAllPostsForSearch()
const allPostsWithoutCurrent = allPosts?.filter(
(post) => post.slug !== Astro.props.post.slug
) as CollectionEntry<'articles' | 'photos' | 'links'>[]
// Configure fuse.js // Configure fuse.js
// https://fusejs.io/api/options.html // https://fusejs.io/api/options.html
const fuseOptions: Fuse.IFuseOptions< const fuse = new Fuse(allPostsWithoutCurrent, {
CollectionEntry<'articles' | 'photos' | 'links'> keys: ['data.tags', 'data.title', 'data.lead'],
> = {
keys: ['data.tags', 'data.title', 'data.lead', 'collection'],
useExtendedSearch: true, useExtendedSearch: true,
minMatchCharLength: 3, threshold: 0.6
threshold: 0.8 })
}
// 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 const relatedPosts = fuse
// https://www.fusejs.io/examples.html#extended-search // https://www.fusejs.io/examples.html#extended-search
.search( .search(
`${post?.data?.tags?.join(' | ')} | ${post?.data?.title} | ${ `${post?.data?.tags?.join(' | ')} | "${post?.data?.lead}" | "${
(post?.data as any)?.lead post?.data?.title
} | ${post?.collection}` }"`
) )
.map((result) => result.item) .map((result) => result.item)
.slice(0, 6) .slice(0, 6)
--- ---
<section class={styles.relatedPosts}> <section class={`${styles.relatedPosts} ${isPhotos ? styles.photos : ''}`}>
<h1 class={styles.title}> <h1 class={styles.title}>Related</h1>
Related {isPhotos ? 'Photos' : 'Posts'}{' '}
<!-- <button class={styles.button} onClick={() => refreshPosts()}>
Refresh
</button> -->
</h1>
<ul> <ul>
{ {
relatedPosts?.map((post) => ( relatedPosts?.map((post) => (
<li> <li>
{isPhotos ? ( {post.collection === 'photos' ? (
<PhotoTeaser post={post as CollectionEntry<'photos'>} /> <PhotoTeaser post={post as CollectionEntry<'photos'>} />
) : ( ) : (
<PostTeaser <PostTeaser

View File

@ -14,9 +14,12 @@
@media (min-width: 40rem) { @media (min-width: 40rem) {
.relatedPosts ul { .relatedPosts ul {
grid-template-columns: repeat(3, 1fr);
gap: var(--spacer); gap: var(--spacer);
} }
.relatedPosts.photos ul {
grid-template-columns: repeat(3, 1fr);
}
} }
.relatedPosts li { .relatedPosts li {
@ -28,26 +31,10 @@
display: none; display: none;
} }
.relatedPosts figure {
margin: 0;
}
.relatedPosts img {
margin-bottom: 0;
}
.relatedPosts a > div { .relatedPosts a > div {
margin-bottom: 0; margin-bottom: 0;
} }
.relatedPosts a h1 { .relatedPosts a h1 {
font-size: var(--font-size-h4); font-size: var(--font-size-h5);
}
.button {
font-size: var(--font-size-mini);
display: inline-block;
color: var(--text-color-light);
text-transform: uppercase;
margin-left: calc(var(--spacer) / 2);
} }

View File

@ -22,12 +22,13 @@ const classes = `posts ${
<style> <style>
.photos { .photos {
display: grid;
gap: var(--spacer);
grid-template-columns: repeat(2, 1fr); grid-template-columns: repeat(2, 1fr);
} }
@media (min-width: 40rem) { @media (min-width: 40rem) {
.photos { .photos {
gap: calc(var(--spacer) * 1.5);
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
} }
} }

View File

@ -35,7 +35,6 @@ const photos = (await loadAndFormatCollection('photos')).slice(
@media (min-width: 40rem) { @media (min-width: 40rem) {
.photos { .photos {
gap: calc(var(--spacer) * 1.5);
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
} }
} }