@btst/stack 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -709
- package/dist/api/index.cjs +2 -1
- package/dist/api/index.d.cts +4 -3
- package/dist/api/index.d.mts +4 -3
- package/dist/api/index.d.ts +4 -3
- package/dist/api/index.mjs +1 -1
- package/dist/client/components/compose.cjs +68 -0
- package/dist/client/components/compose.mjs +65 -0
- package/dist/client/components/error-boundary.cjs +24 -0
- package/dist/client/components/error-boundary.mjs +22 -0
- package/dist/client/components/index.cjs +10 -0
- package/dist/client/components/index.d.cts +52 -0
- package/dist/client/components/index.d.mts +52 -0
- package/dist/client/components/index.d.ts +52 -0
- package/dist/client/components/index.mjs +2 -0
- package/dist/client/index.cjs +24 -5
- package/dist/client/index.d.cts +125 -8
- package/dist/client/index.d.mts +125 -8
- package/dist/client/index.d.ts +125 -8
- package/dist/client/index.mjs +21 -4
- package/dist/client/meta-utils.cjs +162 -0
- package/dist/client/meta-utils.mjs +160 -0
- package/dist/client/path-utils.cjs +15 -0
- package/dist/client/path-utils.mjs +13 -0
- package/dist/client/sitemap-utils.cjs +14 -0
- package/dist/client/sitemap-utils.mjs +12 -0
- package/dist/context/index.cjs +6 -63
- package/dist/context/index.d.cts +21 -24
- package/dist/context/index.d.mts +21 -24
- package/dist/context/index.d.ts +21 -24
- package/dist/context/index.mjs +1 -61
- package/dist/context/provider.cjs +51 -0
- package/dist/context/provider.mjs +46 -0
- package/dist/index.cjs +2 -3
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +1 -2
- package/dist/plugins/api/index.cjs +13 -0
- package/dist/plugins/api/index.d.cts +40 -0
- package/dist/plugins/api/index.d.mts +40 -0
- package/dist/plugins/api/index.d.ts +40 -0
- package/dist/plugins/api/index.mjs +8 -0
- package/dist/plugins/blog/api/index.cjs +11 -0
- package/dist/plugins/blog/api/index.d.cts +7 -0
- package/dist/plugins/blog/api/index.d.mts +7 -0
- package/dist/plugins/blog/api/index.d.ts +7 -0
- package/dist/plugins/blog/api/index.mjs +2 -0
- package/dist/plugins/blog/api/plugin.cjs +569 -0
- package/dist/plugins/blog/api/plugin.mjs +565 -0
- package/dist/plugins/blog/client/components/forms/image-field.cjs +133 -0
- package/dist/plugins/blog/client/components/forms/image-field.mjs +131 -0
- package/dist/plugins/blog/client/components/forms/markdown-editor-styles.css +30 -0
- package/dist/plugins/blog/client/components/forms/markdown-editor.cjs +106 -0
- package/dist/plugins/blog/client/components/forms/markdown-editor.mjs +104 -0
- package/dist/plugins/blog/client/components/forms/post-forms.cjs +401 -0
- package/dist/plugins/blog/client/components/forms/post-forms.mjs +398 -0
- package/dist/plugins/blog/client/components/forms/tags-multiselect.cjs +71 -0
- package/dist/plugins/blog/client/components/forms/tags-multiselect.mjs +65 -0
- package/dist/plugins/blog/client/components/index.cjs +17 -0
- package/dist/plugins/blog/client/components/index.d.cts +22 -0
- package/dist/plugins/blog/client/components/index.d.mts +22 -0
- package/dist/plugins/blog/client/components/index.d.ts +22 -0
- package/dist/plugins/blog/client/components/index.mjs +12 -0
- package/dist/plugins/blog/client/components/loading/form-page-skeleton.cjs +62 -0
- package/dist/plugins/blog/client/components/loading/form-page-skeleton.mjs +60 -0
- package/dist/plugins/blog/client/components/loading/index.cjs +20 -0
- package/dist/plugins/blog/client/components/loading/index.mjs +16 -0
- package/dist/plugins/blog/client/components/loading/list-page-skeleton.cjs +26 -0
- package/dist/plugins/blog/client/components/loading/list-page-skeleton.mjs +24 -0
- package/dist/plugins/blog/client/components/loading/page-header-skeleton.cjs +13 -0
- package/dist/plugins/blog/client/components/loading/page-header-skeleton.mjs +11 -0
- package/dist/plugins/blog/client/components/loading/post-card-skeleton.cjs +22 -0
- package/dist/plugins/blog/client/components/loading/post-card-skeleton.mjs +20 -0
- package/dist/plugins/blog/client/components/loading/post-page-skeleton.cjs +56 -0
- package/dist/plugins/blog/client/components/loading/post-page-skeleton.mjs +54 -0
- package/dist/plugins/blog/client/components/pages/404-page.cjs +19 -0
- package/dist/plugins/blog/client/components/pages/404-page.mjs +17 -0
- package/dist/plugins/blog/client/components/pages/edit-post-page.cjs +41 -0
- package/dist/plugins/blog/client/components/pages/edit-post-page.internal.cjs +57 -0
- package/dist/plugins/blog/client/components/pages/edit-post-page.internal.mjs +55 -0
- package/dist/plugins/blog/client/components/pages/edit-post-page.mjs +39 -0
- package/dist/plugins/blog/client/components/pages/home-page.cjs +41 -0
- package/dist/plugins/blog/client/components/pages/home-page.internal.cjs +61 -0
- package/dist/plugins/blog/client/components/pages/home-page.internal.mjs +59 -0
- package/dist/plugins/blog/client/components/pages/home-page.mjs +39 -0
- package/dist/plugins/blog/client/components/pages/new-post-page.cjs +37 -0
- package/dist/plugins/blog/client/components/pages/new-post-page.internal.cjs +53 -0
- package/dist/plugins/blog/client/components/pages/new-post-page.internal.mjs +51 -0
- package/dist/plugins/blog/client/components/pages/new-post-page.mjs +35 -0
- package/dist/plugins/blog/client/components/pages/post-page.cjs +39 -0
- package/dist/plugins/blog/client/components/pages/post-page.internal.cjs +101 -0
- package/dist/plugins/blog/client/components/pages/post-page.internal.mjs +99 -0
- package/dist/plugins/blog/client/components/pages/post-page.mjs +37 -0
- package/dist/plugins/blog/client/components/pages/tag-page.cjs +39 -0
- package/dist/plugins/blog/client/components/pages/tag-page.internal.cjs +61 -0
- package/dist/plugins/blog/client/components/pages/tag-page.internal.mjs +59 -0
- package/dist/plugins/blog/client/components/pages/tag-page.mjs +37 -0
- package/dist/plugins/blog/client/components/shared/better-blog-attribution.cjs +24 -0
- package/dist/plugins/blog/client/components/shared/better-blog-attribution.mjs +22 -0
- package/dist/plugins/blog/client/components/shared/default-error.cjs +18 -0
- package/dist/plugins/blog/client/components/shared/default-error.mjs +16 -0
- package/dist/plugins/blog/client/components/shared/defaults.cjs +13 -0
- package/dist/plugins/blog/client/components/shared/defaults.mjs +10 -0
- package/dist/plugins/blog/client/components/shared/empty-list.cjs +21 -0
- package/dist/plugins/blog/client/components/shared/empty-list.mjs +19 -0
- package/dist/plugins/blog/client/components/shared/error-placeholder.cjs +24 -0
- package/dist/plugins/blog/client/components/shared/error-placeholder.mjs +22 -0
- package/dist/plugins/blog/client/components/shared/highlight-text.cjs +53 -0
- package/dist/plugins/blog/client/components/shared/highlight-text.mjs +51 -0
- package/dist/plugins/blog/client/components/shared/markdown-content-styles.css +328 -0
- package/dist/plugins/blog/client/components/shared/markdown-content.cjs +324 -0
- package/dist/plugins/blog/client/components/shared/markdown-content.mjs +315 -0
- package/dist/plugins/blog/client/components/shared/on-this-page.cjs +161 -0
- package/dist/plugins/blog/client/components/shared/on-this-page.mjs +158 -0
- package/dist/plugins/blog/client/components/shared/page-header.cjs +40 -0
- package/dist/plugins/blog/client/components/shared/page-header.mjs +38 -0
- package/dist/plugins/blog/client/components/shared/page-layout.cjs +24 -0
- package/dist/plugins/blog/client/components/shared/page-layout.mjs +22 -0
- package/dist/plugins/blog/client/components/shared/page-wrapper.cjs +23 -0
- package/dist/plugins/blog/client/components/shared/page-wrapper.mjs +21 -0
- package/dist/plugins/blog/client/components/shared/post-card.cjs +279 -0
- package/dist/plugins/blog/client/components/shared/post-card.mjs +277 -0
- package/dist/plugins/blog/client/components/shared/post-navigation.cjs +74 -0
- package/dist/plugins/blog/client/components/shared/post-navigation.mjs +72 -0
- package/dist/plugins/blog/client/components/shared/posts-list.cjs +48 -0
- package/dist/plugins/blog/client/components/shared/posts-list.mjs +46 -0
- package/dist/plugins/blog/client/components/shared/recent-posts-carousel.cjs +59 -0
- package/dist/plugins/blog/client/components/shared/recent-posts-carousel.mjs +57 -0
- package/dist/plugins/blog/client/components/shared/search-input.cjs +136 -0
- package/dist/plugins/blog/client/components/shared/search-input.mjs +117 -0
- package/dist/plugins/blog/client/components/shared/search-modal.cjs +135 -0
- package/dist/plugins/blog/client/components/shared/search-modal.mjs +116 -0
- package/dist/plugins/blog/client/components/shared/tags-list.cjs +22 -0
- package/dist/plugins/blog/client/components/shared/tags-list.mjs +20 -0
- package/dist/plugins/blog/client/components/shared/use-route-lifecycle.cjs +50 -0
- package/dist/plugins/blog/client/components/shared/use-route-lifecycle.mjs +48 -0
- package/dist/plugins/blog/client/hooks/blog-hooks.cjs +380 -0
- package/dist/plugins/blog/client/hooks/blog-hooks.mjs +368 -0
- package/dist/plugins/blog/client/hooks/index.cjs +17 -0
- package/dist/plugins/blog/client/hooks/index.d.cts +150 -0
- package/dist/plugins/blog/client/hooks/index.d.mts +150 -0
- package/dist/plugins/blog/client/hooks/index.d.ts +150 -0
- package/dist/plugins/blog/client/hooks/index.mjs +1 -0
- package/dist/plugins/blog/client/hooks/use-debounce.cjs +16 -0
- package/dist/plugins/blog/client/hooks/use-debounce.mjs +14 -0
- package/dist/plugins/blog/client/index.cjs +7 -0
- package/dist/plugins/blog/client/index.d.cts +414 -0
- package/dist/plugins/blog/client/index.d.mts +414 -0
- package/dist/plugins/blog/client/index.d.ts +414 -0
- package/dist/plugins/blog/client/index.mjs +1 -0
- package/dist/plugins/blog/client/localization/blog-card.cjs +7 -0
- package/dist/plugins/blog/client/localization/blog-card.mjs +5 -0
- package/dist/plugins/blog/client/localization/blog-common.cjs +10 -0
- package/dist/plugins/blog/client/localization/blog-common.mjs +8 -0
- package/dist/plugins/blog/client/localization/blog-forms.cjs +40 -0
- package/dist/plugins/blog/client/localization/blog-forms.mjs +38 -0
- package/dist/plugins/blog/client/localization/blog-list.cjs +18 -0
- package/dist/plugins/blog/client/localization/blog-list.mjs +16 -0
- package/dist/plugins/blog/client/localization/blog-post.cjs +13 -0
- package/dist/plugins/blog/client/localization/blog-post.mjs +11 -0
- package/dist/plugins/blog/client/localization/index.cjs +17 -0
- package/dist/plugins/blog/client/localization/index.mjs +15 -0
- package/dist/plugins/blog/client/plugin.cjs +462 -0
- package/dist/plugins/blog/client/plugin.mjs +460 -0
- package/dist/plugins/blog/client.css +3 -0
- package/dist/plugins/blog/db.cjs +90 -0
- package/dist/plugins/blog/db.mjs +88 -0
- package/dist/plugins/blog/query-keys.cjs +181 -0
- package/dist/plugins/blog/query-keys.d.cts +530 -0
- package/dist/plugins/blog/query-keys.d.mts +530 -0
- package/dist/plugins/blog/query-keys.d.ts +530 -0
- package/dist/plugins/blog/query-keys.mjs +179 -0
- package/dist/plugins/blog/schemas.cjs +39 -0
- package/dist/plugins/blog/schemas.mjs +35 -0
- package/dist/plugins/blog/style.css +22 -0
- package/dist/plugins/blog/utils.cjs +97 -0
- package/dist/plugins/blog/utils.mjs +87 -0
- package/dist/plugins/client/index.cjs +15 -0
- package/dist/plugins/client/index.d.cts +57 -0
- package/dist/plugins/client/index.d.mts +57 -0
- package/dist/plugins/client/index.d.ts +57 -0
- package/dist/plugins/client/index.mjs +9 -0
- package/dist/{shared/stack.3OUyGp_E.mjs → plugins/utils.mjs} +1 -1
- package/dist/shared/{stack.DORw_1ps.d.cts → stack.ByOugz9d.d.cts} +17 -1
- package/dist/shared/{stack.DORw_1ps.d.mts → stack.ByOugz9d.d.mts} +17 -1
- package/dist/shared/{stack.DORw_1ps.d.ts → stack.ByOugz9d.d.ts} +17 -1
- package/dist/shared/stack.CoPoHVfV.d.cts +76 -0
- package/dist/shared/stack.CoPoHVfV.d.mts +76 -0
- package/dist/shared/stack.CoPoHVfV.d.ts +76 -0
- package/package.json +102 -14
- package/src/__tests__/plugins.test.tsx +539 -0
- package/src/__tests__/sitemap.test.ts +60 -0
- package/src/api/index.ts +75 -0
- package/src/client/components/compose.tsx +116 -0
- package/src/client/components/error-boundary.tsx +30 -0
- package/src/client/components/index.tsx +2 -0
- package/src/client/index.ts +109 -0
- package/src/client/meta-utils.ts +228 -0
- package/src/client/path-utils.ts +38 -0
- package/src/client/sitemap-utils.ts +46 -0
- package/src/context/index.ts +1 -0
- package/src/context/provider.tsx +157 -0
- package/src/index.ts +1 -0
- package/src/plugins/api/index.ts +50 -0
- package/src/plugins/blog/api/index.ts +2 -0
- package/src/plugins/blog/api/plugin.ts +759 -0
- package/src/plugins/blog/client/components/forms/image-field.tsx +165 -0
- package/src/plugins/blog/client/components/forms/markdown-editor-styles.css +30 -0
- package/src/plugins/blog/client/components/forms/markdown-editor.tsx +136 -0
- package/src/plugins/blog/client/components/forms/post-forms.tsx +531 -0
- package/src/plugins/blog/client/components/forms/tags-multiselect.tsx +79 -0
- package/src/plugins/blog/client/components/index.tsx +11 -0
- package/src/plugins/blog/client/components/loading/form-page-skeleton.tsx +75 -0
- package/src/plugins/blog/client/components/loading/index.tsx +27 -0
- package/src/plugins/blog/client/components/loading/list-page-skeleton.tsx +38 -0
- package/src/plugins/blog/client/components/loading/page-header-skeleton.tsx +10 -0
- package/src/plugins/blog/client/components/loading/post-card-skeleton.tsx +30 -0
- package/src/plugins/blog/client/components/loading/post-page-skeleton.tsx +75 -0
- package/src/plugins/blog/client/components/pages/404-page.tsx +23 -0
- package/src/plugins/blog/client/components/pages/edit-post-page.internal.tsx +60 -0
- package/src/plugins/blog/client/components/pages/edit-post-page.tsx +40 -0
- package/src/plugins/blog/client/components/pages/home-page.internal.tsx +71 -0
- package/src/plugins/blog/client/components/pages/home-page.tsx +42 -0
- package/src/plugins/blog/client/components/pages/new-post-page.internal.tsx +59 -0
- package/src/plugins/blog/client/components/pages/new-post-page.tsx +36 -0
- package/src/plugins/blog/client/components/pages/post-page.internal.tsx +142 -0
- package/src/plugins/blog/client/components/pages/post-page.tsx +38 -0
- package/src/plugins/blog/client/components/pages/tag-page.internal.tsx +74 -0
- package/src/plugins/blog/client/components/pages/tag-page.tsx +38 -0
- package/src/plugins/blog/client/components/shared/better-blog-attribution.tsx +19 -0
- package/src/plugins/blog/client/components/shared/default-error.tsx +20 -0
- package/src/plugins/blog/client/components/shared/defaults.tsx +9 -0
- package/src/plugins/blog/client/components/shared/empty-list.tsx +25 -0
- package/src/plugins/blog/client/components/shared/error-placeholder.tsx +20 -0
- package/src/plugins/blog/client/components/shared/highlight-text.tsx +80 -0
- package/src/plugins/blog/client/components/shared/markdown-content-styles.css +328 -0
- package/src/plugins/blog/client/components/shared/markdown-content.tsx +448 -0
- package/src/plugins/blog/client/components/shared/on-this-page.tsx +234 -0
- package/src/plugins/blog/client/components/shared/page-header.tsx +35 -0
- package/src/plugins/blog/client/components/shared/page-layout.tsx +23 -0
- package/src/plugins/blog/client/components/shared/page-wrapper.tsx +32 -0
- package/src/plugins/blog/client/components/shared/post-card.tsx +308 -0
- package/src/plugins/blog/client/components/shared/post-navigation.tsx +98 -0
- package/src/plugins/blog/client/components/shared/posts-list.tsx +67 -0
- package/src/plugins/blog/client/components/shared/recent-posts-carousel.tsx +79 -0
- package/src/plugins/blog/client/components/shared/search-input.tsx +146 -0
- package/src/plugins/blog/client/components/shared/search-modal.tsx +162 -0
- package/src/plugins/blog/client/components/shared/tags-list.tsx +34 -0
- package/src/plugins/blog/client/components/shared/use-route-lifecycle.tsx +68 -0
- package/src/plugins/blog/client/hooks/blog-hooks.tsx +623 -0
- package/src/plugins/blog/client/hooks/index.tsx +1 -0
- package/src/plugins/blog/client/hooks/use-debounce.ts +43 -0
- package/src/plugins/blog/client/index.ts +9 -0
- package/src/plugins/blog/client/localization/blog-card.ts +3 -0
- package/src/plugins/blog/client/localization/blog-common.ts +7 -0
- package/src/plugins/blog/client/localization/blog-forms.ts +45 -0
- package/src/plugins/blog/client/localization/blog-list.ts +14 -0
- package/src/plugins/blog/client/localization/blog-post.ts +9 -0
- package/src/plugins/blog/client/localization/index.ts +15 -0
- package/src/plugins/blog/client/overrides.ts +123 -0
- package/src/plugins/blog/client/plugin.tsx +672 -0
- package/src/plugins/blog/client.css +3 -0
- package/src/plugins/blog/db.ts +90 -0
- package/src/plugins/blog/query-keys.ts +267 -0
- package/src/plugins/blog/schemas.ts +39 -0
- package/src/plugins/blog/style.css +22 -0
- package/src/plugins/blog/types.ts +37 -0
- package/src/plugins/blog/utils.ts +144 -0
- package/src/plugins/client/index.ts +53 -0
- package/src/plugins/index.ts +0 -0
- package/src/plugins/utils.ts +35 -0
- package/src/types.ts +209 -0
- package/dist/plugins/index.cjs +0 -15
- package/dist/plugins/index.d.cts +0 -64
- package/dist/plugins/index.d.mts +0 -64
- package/dist/plugins/index.d.ts +0 -64
- package/dist/plugins/index.mjs +0 -11
- package/dist/shared/stack.DrUAVfIH.d.cts +0 -17
- package/dist/shared/stack.DrUAVfIH.d.mts +0 -17
- package/dist/shared/stack.DrUAVfIH.d.ts +0 -17
- /package/dist/{shared/stack.CktCg4PJ.cjs → plugins/utils.cjs} +0 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { usePostSearch } from "../../hooks/blog-hooks";
|
|
5
|
+
import { stripHtml, stripMarkdown } from "../../../utils";
|
|
6
|
+
import { HighlightText } from "./highlight-text";
|
|
7
|
+
import { SearchModal, type SearchResult } from "./search-modal";
|
|
8
|
+
import type { BlogPluginOverrides } from "../../overrides";
|
|
9
|
+
import { useBasePath, usePluginOverrides } from "@btst/stack/context";
|
|
10
|
+
|
|
11
|
+
// Simplified blog post search result interface
|
|
12
|
+
interface BlogPostSearchResult extends SearchResult {
|
|
13
|
+
slug: string;
|
|
14
|
+
publishedAt?: string | null;
|
|
15
|
+
authorName?: string;
|
|
16
|
+
processedContent: string;
|
|
17
|
+
processedExcerpt?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface SearchInputProps {
|
|
21
|
+
className?: string;
|
|
22
|
+
triggerClassName?: string;
|
|
23
|
+
placeholder?: string;
|
|
24
|
+
buttonText?: string;
|
|
25
|
+
emptyMessage?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const renderBlogResult = (
|
|
29
|
+
item: BlogPostSearchResult,
|
|
30
|
+
index: number,
|
|
31
|
+
query: string,
|
|
32
|
+
): React.ReactNode => {
|
|
33
|
+
const q = (query || "").toLowerCase();
|
|
34
|
+
const excerptMatches = item.processedExcerpt
|
|
35
|
+
? item.processedExcerpt.toLowerCase().includes(q)
|
|
36
|
+
: false;
|
|
37
|
+
const contentMatches = item.processedContent
|
|
38
|
+
? item.processedContent.toLowerCase().includes(q)
|
|
39
|
+
: false;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<button
|
|
43
|
+
data-testid="search-result"
|
|
44
|
+
type="button"
|
|
45
|
+
key={item.id}
|
|
46
|
+
className="flex w-full cursor-pointer flex-col gap-2 rounded-sm border-border border-b px-4 py-3 text-left transition-colors hover:bg-accent"
|
|
47
|
+
onClick={() => item.onClick?.()}
|
|
48
|
+
>
|
|
49
|
+
<div className="flex items-start justify-between gap-2">
|
|
50
|
+
<HighlightText
|
|
51
|
+
text={item.title}
|
|
52
|
+
searchQuery={query}
|
|
53
|
+
className="flex-1 font-medium text-sm leading-5"
|
|
54
|
+
/>
|
|
55
|
+
{item.publishedAt && (
|
|
56
|
+
<span className="whitespace-nowrap text-muted-foreground text-xs">
|
|
57
|
+
{new Date(item.publishedAt).toLocaleDateString()}
|
|
58
|
+
</span>
|
|
59
|
+
)}
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
{excerptMatches && (
|
|
63
|
+
<HighlightText
|
|
64
|
+
text={item.processedExcerpt || ""}
|
|
65
|
+
searchQuery={query}
|
|
66
|
+
className="text-muted-foreground text-xs leading-4"
|
|
67
|
+
maxLength={120}
|
|
68
|
+
/>
|
|
69
|
+
)}
|
|
70
|
+
{contentMatches && (
|
|
71
|
+
<HighlightText
|
|
72
|
+
text={item.processedContent}
|
|
73
|
+
searchQuery={query}
|
|
74
|
+
className="text-muted-foreground text-xs leading-4"
|
|
75
|
+
maxLength={120}
|
|
76
|
+
/>
|
|
77
|
+
)}
|
|
78
|
+
{!excerptMatches && !contentMatches && (
|
|
79
|
+
<HighlightText
|
|
80
|
+
text={item.processedExcerpt || item.processedContent}
|
|
81
|
+
searchQuery={query}
|
|
82
|
+
className="text-muted-foreground text-xs leading-4"
|
|
83
|
+
maxLength={120}
|
|
84
|
+
/>
|
|
85
|
+
)}
|
|
86
|
+
</button>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export function SearchInput({
|
|
91
|
+
className,
|
|
92
|
+
triggerClassName,
|
|
93
|
+
placeholder,
|
|
94
|
+
buttonText,
|
|
95
|
+
emptyMessage,
|
|
96
|
+
}: SearchInputProps) {
|
|
97
|
+
const { navigate } = usePluginOverrides<BlogPluginOverrides>("blog");
|
|
98
|
+
const basePath = useBasePath();
|
|
99
|
+
const [currentQuery, setCurrentQuery] = React.useState("");
|
|
100
|
+
|
|
101
|
+
const { data: searchResults = [], isLoading } = usePostSearch({
|
|
102
|
+
query: currentQuery,
|
|
103
|
+
enabled: currentQuery.trim().length > 0,
|
|
104
|
+
debounceMs: 300,
|
|
105
|
+
published: true,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const formattedResults: BlogPostSearchResult[] = React.useMemo(() => {
|
|
109
|
+
return searchResults.map((post) => ({
|
|
110
|
+
id: post.id,
|
|
111
|
+
title: post.title,
|
|
112
|
+
slug: post.slug,
|
|
113
|
+
publishedAt: post.publishedAt,
|
|
114
|
+
authorName: "",
|
|
115
|
+
processedContent: stripMarkdown(stripHtml(post.content || "")),
|
|
116
|
+
processedExcerpt: stripMarkdown(stripHtml(post.excerpt || "")),
|
|
117
|
+
onClick: () => navigate(`${basePath}/blog/${post.slug}`),
|
|
118
|
+
}));
|
|
119
|
+
}, [searchResults, navigate, basePath]);
|
|
120
|
+
|
|
121
|
+
// Search function that updates our query state
|
|
122
|
+
const handleSearch = React.useCallback(
|
|
123
|
+
(query: string): BlogPostSearchResult[] => {
|
|
124
|
+
setCurrentQuery(query);
|
|
125
|
+
return []; // Return empty since we use external async results
|
|
126
|
+
},
|
|
127
|
+
[],
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<SearchModal<BlogPostSearchResult>
|
|
132
|
+
placeholder={placeholder}
|
|
133
|
+
buttonText={buttonText}
|
|
134
|
+
emptyMessage={emptyMessage}
|
|
135
|
+
searchFn={handleSearch}
|
|
136
|
+
renderResult={renderBlogResult}
|
|
137
|
+
results={formattedResults}
|
|
138
|
+
isLoading={isLoading}
|
|
139
|
+
className={className}
|
|
140
|
+
triggerClassName={triggerClassName}
|
|
141
|
+
keyboardShortcut="⌘K"
|
|
142
|
+
/>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export default SearchInput;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { SearchIcon } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { useDebounce } from "../../hooks/use-debounce";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
CommandDialog,
|
|
9
|
+
CommandEmpty,
|
|
10
|
+
CommandInput,
|
|
11
|
+
CommandList,
|
|
12
|
+
} from "@workspace/ui/components/command";
|
|
13
|
+
|
|
14
|
+
export interface SearchResult {
|
|
15
|
+
id: string;
|
|
16
|
+
title: string;
|
|
17
|
+
subtitle?: string;
|
|
18
|
+
content?: string;
|
|
19
|
+
onClick?: () => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SearchModalProps<T = SearchResult> {
|
|
23
|
+
placeholder?: string;
|
|
24
|
+
emptyMessage?: string;
|
|
25
|
+
buttonText?: string;
|
|
26
|
+
keyboardShortcut?: string;
|
|
27
|
+
searchFn: (query: string) => T[];
|
|
28
|
+
renderResult: (item: T, index: number, query: string) => React.ReactNode;
|
|
29
|
+
results?: T[];
|
|
30
|
+
isLoading?: boolean;
|
|
31
|
+
groupTitle?: string;
|
|
32
|
+
className?: string;
|
|
33
|
+
triggerClassName?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function SearchModal<T extends SearchResult>({
|
|
37
|
+
placeholder = "Type to search...",
|
|
38
|
+
emptyMessage = "No results found.",
|
|
39
|
+
buttonText = "Search",
|
|
40
|
+
keyboardShortcut = "⌘K",
|
|
41
|
+
searchFn,
|
|
42
|
+
renderResult,
|
|
43
|
+
results: externalResults,
|
|
44
|
+
isLoading = false,
|
|
45
|
+
className,
|
|
46
|
+
triggerClassName,
|
|
47
|
+
}: SearchModalProps<T>) {
|
|
48
|
+
const [open, setOpen] = React.useState(false);
|
|
49
|
+
const [query, setQuery] = React.useState("");
|
|
50
|
+
const [results, setResults] = React.useState<T[]>([]);
|
|
51
|
+
|
|
52
|
+
// Only debounce if not using external results
|
|
53
|
+
const shouldDebounce = externalResults === undefined;
|
|
54
|
+
const debouncedQuery = useDebounce(query, shouldDebounce ? 300 : 0);
|
|
55
|
+
|
|
56
|
+
// Handle keyboard shortcut
|
|
57
|
+
React.useEffect(() => {
|
|
58
|
+
const down = (e: KeyboardEvent) => {
|
|
59
|
+
const cleanShortcut = keyboardShortcut
|
|
60
|
+
.replace("⌘", "")
|
|
61
|
+
.replace("⇧", "")
|
|
62
|
+
.toLowerCase();
|
|
63
|
+
if (e.key === cleanShortcut && (e.metaKey || e.ctrlKey)) {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
|
|
66
|
+
setOpen((open) => !open);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
document.addEventListener("keydown", down);
|
|
71
|
+
return () => document.removeEventListener("keydown", down);
|
|
72
|
+
}, [keyboardShortcut]);
|
|
73
|
+
|
|
74
|
+
React.useEffect(() => {
|
|
75
|
+
if (!open) {
|
|
76
|
+
setQuery("");
|
|
77
|
+
setResults([]);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}, [open]);
|
|
81
|
+
|
|
82
|
+
React.useEffect(() => {
|
|
83
|
+
if (!open) return;
|
|
84
|
+
|
|
85
|
+
// Always call searchFn to notify parent component of the search query
|
|
86
|
+
const searchResults = searchFn(debouncedQuery);
|
|
87
|
+
|
|
88
|
+
// If external results are provided, use them; otherwise use searchFn results
|
|
89
|
+
if (externalResults !== undefined) {
|
|
90
|
+
setResults(externalResults);
|
|
91
|
+
} else {
|
|
92
|
+
setResults(searchResults);
|
|
93
|
+
}
|
|
94
|
+
}, [debouncedQuery, open, searchFn, externalResults]);
|
|
95
|
+
|
|
96
|
+
// Base button classes for better readability
|
|
97
|
+
const buttonClasses = [
|
|
98
|
+
"border-input bg-background text-foreground",
|
|
99
|
+
"placeholder:text-muted-foreground",
|
|
100
|
+
"focus-visible:border-ring focus-visible:ring-ring/50",
|
|
101
|
+
"inline-flex h-9 w-fit rounded-md border px-3 py-2 text-sm",
|
|
102
|
+
"shadow-xs transition-[color,box-shadow] outline-none",
|
|
103
|
+
"focus-visible:ring-[3px]",
|
|
104
|
+
triggerClassName,
|
|
105
|
+
]
|
|
106
|
+
.filter(Boolean)
|
|
107
|
+
.join(" ");
|
|
108
|
+
|
|
109
|
+
// Determine what to show based on state
|
|
110
|
+
const showEmpty = debouncedQuery && !isLoading && results.length === 0;
|
|
111
|
+
const currentEmptyMessage = isLoading ? "Searching..." : emptyMessage;
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<>
|
|
115
|
+
<button
|
|
116
|
+
data-testid="search-button"
|
|
117
|
+
type="button"
|
|
118
|
+
className={buttonClasses}
|
|
119
|
+
onClick={() => setOpen(true)}
|
|
120
|
+
>
|
|
121
|
+
<span className="flex grow items-center">
|
|
122
|
+
<SearchIcon
|
|
123
|
+
className="-ms-1 me-3 text-muted-foreground"
|
|
124
|
+
size={16}
|
|
125
|
+
aria-hidden="true"
|
|
126
|
+
/>
|
|
127
|
+
<span className="font-normal text-muted-foreground">
|
|
128
|
+
{buttonText}
|
|
129
|
+
</span>
|
|
130
|
+
</span>
|
|
131
|
+
{keyboardShortcut && (
|
|
132
|
+
<kbd className="-me-1 ms-12 inline-flex h-5 max-h-full items-center rounded border bg-background px-1 font-[inherit] font-medium text-[0.625rem] text-muted-foreground">
|
|
133
|
+
{keyboardShortcut}
|
|
134
|
+
</kbd>
|
|
135
|
+
)}
|
|
136
|
+
</button>
|
|
137
|
+
<CommandDialog
|
|
138
|
+
data-testid="search-modal"
|
|
139
|
+
open={open}
|
|
140
|
+
onOpenChange={setOpen}
|
|
141
|
+
className={className}
|
|
142
|
+
>
|
|
143
|
+
<CommandInput
|
|
144
|
+
data-testid="search-input"
|
|
145
|
+
placeholder={placeholder}
|
|
146
|
+
value={query}
|
|
147
|
+
onValueChange={setQuery}
|
|
148
|
+
/>
|
|
149
|
+
<CommandList className="max-h-[400px]">
|
|
150
|
+
{showEmpty && <CommandEmpty>{currentEmptyMessage}</CommandEmpty>}
|
|
151
|
+
|
|
152
|
+
{results.length > 0 &&
|
|
153
|
+
results.map((item, index) =>
|
|
154
|
+
renderResult(item, index, debouncedQuery),
|
|
155
|
+
)}
|
|
156
|
+
</CommandList>
|
|
157
|
+
</CommandDialog>
|
|
158
|
+
</>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default SearchModal;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { usePluginOverrides, useBasePath } from "@btst/stack/context";
|
|
4
|
+
import type { BlogPluginOverrides } from "../../overrides";
|
|
5
|
+
import { DefaultLink } from "./defaults";
|
|
6
|
+
import { Badge } from "@workspace/ui/components/badge";
|
|
7
|
+
import { useSuspenseTags } from "../../hooks/blog-hooks";
|
|
8
|
+
|
|
9
|
+
export function TagsList() {
|
|
10
|
+
const { tags } = useSuspenseTags();
|
|
11
|
+
const { Link } = usePluginOverrides<
|
|
12
|
+
BlogPluginOverrides,
|
|
13
|
+
Partial<BlogPluginOverrides>
|
|
14
|
+
>("blog", {
|
|
15
|
+
Link: DefaultLink,
|
|
16
|
+
});
|
|
17
|
+
const basePath = useBasePath();
|
|
18
|
+
|
|
19
|
+
if (!tags || tags.length === 0) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div className="flex flex-wrap gap-2 justify-center">
|
|
25
|
+
{tags.map((tag) => (
|
|
26
|
+
<Link key={tag.id} href={`${basePath}/blog/tag/${tag.slug}`}>
|
|
27
|
+
<Badge variant="secondary" className="text-xs">
|
|
28
|
+
{tag.name}
|
|
29
|
+
</Badge>
|
|
30
|
+
</Link>
|
|
31
|
+
))}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { usePluginOverrides } from "@btst/stack/context";
|
|
5
|
+
import type { BlogPluginOverrides, RouteContext } from "../../overrides";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook to handle route lifecycle events
|
|
9
|
+
* - Calls authorization check before render
|
|
10
|
+
* - Calls onRouteRender on mount
|
|
11
|
+
* - Handles errors with onRouteError
|
|
12
|
+
*/
|
|
13
|
+
export function useRouteLifecycle({
|
|
14
|
+
routeName,
|
|
15
|
+
context,
|
|
16
|
+
beforeRenderHook,
|
|
17
|
+
}: {
|
|
18
|
+
routeName: string;
|
|
19
|
+
context: RouteContext;
|
|
20
|
+
beforeRenderHook?: (
|
|
21
|
+
overrides: BlogPluginOverrides,
|
|
22
|
+
context: RouteContext,
|
|
23
|
+
) => boolean;
|
|
24
|
+
}) {
|
|
25
|
+
const overrides = usePluginOverrides<BlogPluginOverrides>("blog");
|
|
26
|
+
|
|
27
|
+
// Authorization check - runs synchronously before render
|
|
28
|
+
if (beforeRenderHook) {
|
|
29
|
+
const canRender = beforeRenderHook(overrides, context);
|
|
30
|
+
if (!canRender) {
|
|
31
|
+
const error = new Error(`Unauthorized: Cannot render ${routeName}`);
|
|
32
|
+
// Call error hook synchronously
|
|
33
|
+
if (overrides.onRouteError) {
|
|
34
|
+
try {
|
|
35
|
+
const result = overrides.onRouteError(routeName, error, context);
|
|
36
|
+
if (result instanceof Promise) {
|
|
37
|
+
result.catch(() => {}); // Ignore promise rejection
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
// Ignore errors in error hook
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Lifecycle hook - runs on mount
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (overrides.onRouteRender) {
|
|
50
|
+
try {
|
|
51
|
+
const result = overrides.onRouteRender(routeName, context);
|
|
52
|
+
if (result instanceof Promise) {
|
|
53
|
+
result.catch((error) => {
|
|
54
|
+
// If onRouteRender throws, call onRouteError
|
|
55
|
+
if (overrides.onRouteError) {
|
|
56
|
+
overrides.onRouteError(routeName, error, context);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
} catch (error) {
|
|
61
|
+
// If onRouteRender throws, call onRouteError
|
|
62
|
+
if (overrides.onRouteError) {
|
|
63
|
+
overrides.onRouteError(routeName, error as Error, context);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, [routeName, overrides, context]);
|
|
68
|
+
}
|