-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(blog): add search feature (#61)
* feat(blog): add search feature Signed-off-by: james-a-morris <[email protected]> * chore: keyword search Signed-off-by: james-a-morris <[email protected]> --------- Signed-off-by: james-a-morris <[email protected]>
- Loading branch information
1 parent
3c96d06
commit e8f474b
Showing
7 changed files
with
111 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Text } from "@/app/_components/text"; | ||
import ArticleSnippetCard from "./article-snippet-card"; | ||
import ArticleFullCard from "./article-full-card"; | ||
import { | ||
BlogPostWithRelevantEntries, | ||
retrieveContentfulPublishedSlugs, | ||
} from "@/app/_lib/contentful"; | ||
import { SearchParams } from "../page"; | ||
|
||
export async function Posts({ | ||
getStartedSnippets, | ||
recentArticleSlugs, | ||
searchParams, | ||
}: { | ||
searchParams: SearchParams; | ||
recentArticleSlugs: string[]; | ||
getStartedSnippets: (BlogPostWithRelevantEntries | undefined)[]; | ||
}) { | ||
const search = searchParams["search"]; | ||
if (!search) { | ||
return ( | ||
<> | ||
<div className="flex w-full flex-col gap-4"> | ||
<Text variant="body" className="text-grey-400"> | ||
Get started with Across | ||
</Text> | ||
<div className="w-full overflow-x-scroll scrollbar-hide"> | ||
<div className="grid w-[1024px] grid-cols-3 gap-5 md:w-full"> | ||
{getStartedSnippets.slice(0, 3).map((snippet) => ( | ||
<div className="w-full" key={snippet?.fields.slug}> | ||
<ArticleSnippetCard article={snippet!} /> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
<div className="flex w-full flex-col gap-4"> | ||
<Text variant="body" className="text-grey-400"> | ||
Most recent articles | ||
</Text> | ||
{recentArticleSlugs.map((slug) => ( | ||
<ArticleFullCard key={slug} slug={slug} /> | ||
))} | ||
</div> | ||
</> | ||
); | ||
} else { | ||
const searchedSlugs = await retrieveContentfulPublishedSlugs({ | ||
query: search, | ||
}); | ||
return ( | ||
<div className="flex w-full flex-col gap-4"> | ||
<Text variant="body" className="text-grey-400"> | ||
Search results | ||
</Text> | ||
{searchedSlugs.map((slug) => ( | ||
<ArticleFullCard key={slug} slug={slug} /> | ||
))} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { SearchParams } from "../(routes)/blog/page"; | ||
|
||
export function createCacheKey(options: { searchParams: SearchParams }) { | ||
const { searchParams } = options; | ||
const newParamString = new URLSearchParams(); | ||
Object.entries(searchParams).forEach(([key, value]) => { | ||
if (typeof value === "string") { | ||
newParamString.set(key, value); | ||
} | ||
}); | ||
|
||
return newParamString.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters