sc
Scott avatar
ttwillsey

Media Reviews Are Now in Search Results

Astro

Part of the Astro series

When I added a Reviews page, I wanted to be able to have individual reviews show up in my site search. Due to some complexities I won’t go into of how Pagefind indexes things and how I optimize my images using the Astro Image component, this was easier said than done – until I remembered the good old HTML hidden global attribute. Then I just made a hidden span and populated it with the image alt text.

<div class="review">
<p>
{
page.data.map((book) => (
<span hidden>{`${book.alttext}`}</span>
<a href={`/images/posts/${book.review}.jpg`}>
<Image
src={import(`../../../assets/images/posts/${book.review}.png`)}
alt={`${book.alttext}`}
/>
</a>
))
}
</p>
</div>

Now all my media reviews show up in site seach results!

SearchReviewsResults

Enjoy the reviews, and don’t forget there are separate categories for Book Reviews, Movie Reviews, TV Show Reviews, and Music Reviews. I will be actively adding more reviews from this point forward.