This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
Add search bar, fix storybook, fix other minor errors #186
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Search Bar
This setup creates a
SearchBar
component that allows users to search for blog posts based on what they input into a search bar which appears in theHeader
on all pages. The functionality works as below:types.ts
defines the structure of aBlogPost
, including properties like tags, excerpt, title, etc. This type is then imported into other files to ensure consistency in data handling.+layout.ts
in the root importsfilteredPosts
from a data source ($lib/data/blog-posts
) and exports an async functionload()
that returns the filtered posts.+layout.svelte
, also in the root, importsBlogPost
type and receives data containing posts. It passes this data down to theHeader
component.Header.svelte
component contains the search bar UI. It imports theBlogPost
type and receives an array of posts. When a user interacts with the search bar, it emits a search event. It also importsSearchBar.svelte
, where the actual search logic resides.SearchBar.svelte
component handles the search functionality. It importsBlogPost
type and receives an array of posts. It uses FlexSearch to create an index of posts and then performs a search based on the user input. The search results are updated dynamically as the user types.search.ts
module contains the search logic. It imports theBlogPost
type and defines functions to create an index of posts (createPostsIndex
) and search this index (searchPostsIndex
). ThecreatePostsIndex
function initialises a FlexSearch index and adds each post to it, while thesearchPostsIndex
function performs a search based on the user input and returns the matching posts.Previous and Next Posts
In the
PrevNextPost.svelte
component which appears below each blog post, I switched previous and next post to make it natural by the user accessing newer posts by clicking right and older posts by clicking left.Storybook
Fixed errors in Histoire mentioned here by updating dependencies.
Favicon error
Fixed error mentioned here by fixing the file path in the
href
as below:Before:
After:
Links error
Fixed error mentioned here by finding
links
in the Table of Contents forContainerizing Rust Applications
andDeploying Torrust To Production
wasn't working due to a lack of#
so changed fromto