Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: search not working if postsPage is set in frontity.settings.js… #9

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const useSearch = ({ state, actions, libraries }) => {
// Better to trim write spaces as well
if (searchString.trim().length > 0) {
// Let's go search for blogs that match the search string
actions.router.set(`/?s=${searchString.toLowerCase()}`);
actions.router.set(
`${state.source.postsPage}?s=${searchString.toLowerCase()}`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please note that the default value of state.source.postPage is an empty string "". Your code will return "?s=?=some+search" instead of "/?s=?=some+search" for that case.

Maybe something like this works better (I haven't tested):

const prefix = state.source.postsPage || "/";
actions.router.set(`${prefix}?s=${searchString.toLowerCase()}`);

);

// Scroll the page to the top
window.scrollTo(0, 0);
Expand Down