Skip to content

Commit

Permalink
related posts tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kremalicious committed Sep 19, 2023
1 parent ca96ae9 commit 124934e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 73 deletions.
1 change: 1 addition & 0 deletions content/photos/2014-04-26-ai-weiwei-stools/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ author: Matthias Kretschmann
---

Ai Weiwei - Evidence, Stools at Martin Gropius Bau

Processed with VSCOcam with b2 preset

[flickr](https://www.flickr.com/photos/krema/14016811365/) | [EyeEm](http://www.eyeem.com/p/35839008)
2 changes: 1 addition & 1 deletion content/photos/2021-11-26-forever-bicycles/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
date: 2021-11-26T15:32:28.000Z

title: Forever Bicycles
title: Ai Weiwei, Forever Bicycles
image: ./2021-11-26-forever-bicycles.jpg
---

Expand Down
2 changes: 1 addition & 1 deletion content/photos/2021-11-26-law-of-the-journey/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
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
---

Expand Down
43 changes: 15 additions & 28 deletions src/components/PhotoTeaser.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,22 @@ const { title, image } = data
---

<style>
.photo a {
.photo {
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>

<article class="photo">
{
image ? (
<a href={`/${slug}`}>
<Picture
width={184}
height={184}
src={image}
alt={title}
title={title}
objectFit
/>
</a>
) : null
}
</article>
{
image ? (
<a class="photo" href={`/${slug}`}>
<Picture
width={202}
height={202}
src={image}
alt={title}
title={title}
objectFit
/>
</a>
) : null
}
36 changes: 13 additions & 23 deletions src/components/RelatedPosts/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,35 @@ type Props = {
}
const { post, isPhotos } = Astro.props as Props
const allPosts = await getAllPostsForSearch()
const allPostsWithoutCurrent = allPosts?.filter(
(post) => post.slug !== Astro.props.post.slug
) as CollectionEntry<'articles' | 'photos' | 'links'>[]
// Configure fuse.js
// https://fusejs.io/api/options.html
const fuseOptions: Fuse.IFuseOptions<
CollectionEntry<'articles' | 'photos' | 'links'>
> = {
keys: ['data.tags', 'data.title', 'data.lead', 'collection'],
const fuse = new Fuse(allPostsWithoutCurrent, {
keys: ['data.tags', 'data.title', 'data.lead'],
useExtendedSearch: true,
minMatchCharLength: 3,
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)
threshold: 0.6
})
const relatedPosts = fuse
// https://www.fusejs.io/examples.html#extended-search
.search(
`${post?.data?.tags?.join(' | ')} | ${post?.data?.title} | ${
(post?.data as any)?.lead
} | ${post?.collection}`
`${post?.data?.tags?.join(' | ')} | "${post?.data?.lead}" | "${
post?.data?.title
}"`
)
.map((result) => result.item)
.slice(0, 6)
---

<section class={styles.relatedPosts}>
<h1 class={styles.title}>
Related {isPhotos ? 'Photos' : 'Posts'}{' '}
<!-- <button class={styles.button} onClick={() => refreshPosts()}>
Refresh
</button> -->
</h1>
<section class={`${styles.relatedPosts} ${isPhotos ? styles.photos : ''}`}>
<h1 class={styles.title}>Related</h1>
<ul>
{
relatedPosts?.map((post) => (
<li>
{isPhotos ? (
{post.collection === 'photos' ? (
<PhotoTeaser post={post as CollectionEntry<'photos'>} />
) : (
<PostTeaser
Expand Down
23 changes: 5 additions & 18 deletions src/components/RelatedPosts/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

@media (min-width: 40rem) {
.relatedPosts ul {
grid-template-columns: repeat(3, 1fr);
gap: var(--spacer);
}

.relatedPosts.photos ul {
grid-template-columns: repeat(3, 1fr);
}
}

.relatedPosts li {
Expand All @@ -28,26 +31,10 @@
display: none;
}

.relatedPosts figure {
margin: 0;
}

.relatedPosts img {
margin-bottom: 0;
}

.relatedPosts a > div {
margin-bottom: 0;
}

.relatedPosts a h1 {
font-size: var(--font-size-h4);
}

.button {
font-size: var(--font-size-mini);
display: inline-block;
color: var(--text-color-light);
text-transform: uppercase;
margin-left: calc(var(--spacer) / 2);
font-size: var(--font-size-h5);
}
3 changes: 2 additions & 1 deletion src/components/layouts/Archive.astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ const classes = `posts ${

<style>
.photos {
display: grid;
gap: var(--spacer);
grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 40rem) {
.photos {
gap: calc(var(--spacer) * 1.5);
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const photos = (await loadAndFormatCollection('photos')).slice(

@media (min-width: 40rem) {
.photos {
gap: calc(var(--spacer) * 1.5);
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
}
Expand Down

1 comment on commit 124934e

@vercel
Copy link

@vercel vercel bot commented on 124934e Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blog – ./

blog-kremalicious.vercel.app
kremalicious.vercel.app
blog-git-main-kremalicious.vercel.app

Please sign in to comment.