Add optional snippet for article preview
1 minute read
Currently the PostPreview component only displays the article
title, cover image, and authors. Adding an optional Svelte snippet would
allow rich preview content for articles.
Problem
Svelte snippets cannot be passed through JSON. The current architecture:
- Pages export metadata in
<script module> page-renderer.svelte.jsextracts exports into JSON feedArticles.sveltereads frompage.data.feed(JSON)PostPreview.svelterenders from JSON data
Svelte snippets are runtime constructs that cannot be serialized to JSON.
Solution
Import all page modules directly in the layout and map them to feed items, bypassing JSON serialization for snippet data.
Tasks
- Import all page modules in layout using
import.meta.glob - Create a map from feed item URLs to page modules
- Extract snippet from page module and pass to
PostPreview - Update
PostPreview.svelteto accept and render optional snippet prop
Considerations
- Performance impact of importing all page modules in layout
- May want different snippet visibility for compact vs fancy layouts
- Snippet should be optional - fall back to title-only preview
Read next