Skip to content

Commit a7304ef

Browse files
authored
Merge pull request #118 from timlrx/v2
Fix kbar fetch to load relative to base url and add back starting actions
2 parents 7a509c4 + db528a4 commit a7304ef

File tree

7 files changed

+37
-27
lines changed

7 files changed

+37
-27
lines changed

.changeset/pre.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"tricky-carpets-fly",
2222
"unlucky-keys-join",
2323
"weak-swans-heal",
24+
"wicked-maps-rest",
2425
"yellow-ligers-sort"
2526
]
2627
}

.changeset/wicked-maps-rest.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pliny': patch
3+
---
4+
5+
Fix kbar fetch to load relative to base url and add back starting actions

packages/pliny/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# pliny
22

3+
## 0.1.0-beta.10
4+
5+
### Patch Changes
6+
7+
- 9f87280: Fix kbar fetch to load relative to base url and add back starting actions
8+
39
## 0.1.0-beta.9
410

511
### Patch Changes

packages/pliny/add-use-client.mjs

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import globby from 'globby'
1616
}
1717
}
1818
// Handle ui differently as they are not split
19-
const clientPaths = await globby(['ui/NewsletterForm.js', 'ui/Pre.js'])
19+
const clientPaths = await globby([
20+
'ui/NewsletterForm.js',
21+
'ui/BlogNewsletterForm.js',
22+
'ui/Pre.js',
23+
])
2024
for (const path of clientPaths) {
2125
console.log(path)
2226
const data = fs.readFileSync(path)

packages/pliny/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pliny",
33
"description": "Main entry point for pliny components",
44
"homepage": "https://github.com/timlrx/pliny",
5-
"version": "0.1.0-beta.9",
5+
"version": "0.1.0-beta.10",
66
"type": "module",
77
"exports": {
88
"./*": "./*",

packages/pliny/src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const sampleConfig: PlinyConfig = {
9898
search: {
9999
provider: 'kbar', // kbar or algolia
100100
kbarConfig: {
101-
searchDocumentsPath: 'search.json', // path to load documents to search
101+
searchDocumentsPath: 'search.json', // path to load documents to search relative to public folder
102102
},
103103
// algoliaConfig: {
104104
// // The application ID provided by Algolia

packages/pliny/src/search/KBar.tsx

+18-24
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ export const KBarSearchProvider: FC<{
3939
const [modalLoaded, setModalLoaded] = useState(false)
4040
const [dataLoaded, setDataLoaded] = useState(false)
4141

42-
const startingActions = useMemo(() => {
43-
return Array.isArray(defaultActions)
44-
? defaultActions
45-
: [
46-
{
47-
id: 'homepage',
48-
name: 'Homepage',
49-
keywords: '',
50-
section: 'Home',
51-
perform: () => router.push('/'),
52-
},
53-
]
54-
}, [defaultActions, router])
55-
5642
const importDocSearchModalIfNeeded = useCallback(() => {
5743
if (KBarModal) {
5844
return Promise.resolve()
@@ -73,7 +59,18 @@ export const KBarSearchProvider: FC<{
7359
}
7460
}
7561
const mapPosts = (posts: CoreContent<MDXDocument>[]) => {
76-
const actions: Action[] = []
62+
const startingActions = Array.isArray(defaultActions)
63+
? defaultActions
64+
: [
65+
{
66+
id: 'homepage',
67+
name: 'Homepage',
68+
keywords: '',
69+
section: 'Home',
70+
perform: () => router.push('/'),
71+
},
72+
]
73+
const actions: Action[] = startingActions
7774
for (const post of posts) {
7875
actions.push({
7976
id: post.path,
@@ -87,7 +84,11 @@ export const KBarSearchProvider: FC<{
8784
return actions
8885
}
8986
async function fetchData() {
90-
const res = await fetch(searchDocumentsPath)
87+
const url =
88+
searchDocumentsPath.indexOf('://') > 0 || searchDocumentsPath.indexOf('//') === 0
89+
? searchDocumentsPath
90+
: new URL(searchDocumentsPath, window.location.origin)
91+
const res = await fetch(url)
9192
const json = await res.json()
9293
const actions = mapPosts(json)
9394
setSearchActions(actions)
@@ -103,14 +104,7 @@ export const KBarSearchProvider: FC<{
103104
/*removes event listener on cleanup*/
104105
window.removeEventListener('keydown', handleKeyDown)
105106
}
106-
}, [
107-
importDocSearchModalIfNeeded,
108-
modalLoaded,
109-
dataLoaded,
110-
startingActions,
111-
router,
112-
searchDocumentsPath,
113-
])
107+
}, [importDocSearchModalIfNeeded, modalLoaded, dataLoaded, router, searchDocumentsPath])
114108

115109
return (
116110
<>

0 commit comments

Comments
 (0)