@@ -11,14 +11,37 @@ const INDEX_NAME = "tailwindcss";
11
11
const API_KEY = "5fc87cef58bb80203d2207578309fab6" ;
12
12
const APP_ID = "KNPXZI5B0M" ;
13
13
14
- function isTailwindUIUrl ( url : string ) {
15
- return url . startsWith ( "https://tailwindui.com" ) ;
14
+ function isTailwindPlusURL ( url : string ) {
15
+ return (
16
+ url . startsWith ( 'https://tailwindui.com' ) ||
17
+ url . startsWith ( 'https://tailwindcss.com/plus' ) ||
18
+ url . startsWith ( '/plus' )
19
+ )
16
20
}
17
21
18
22
function isExternalURL ( url : string ) {
23
+ if ( url . startsWith ( 'https://tailwindui.com' ) ) {
24
+ return false
25
+ }
26
+
19
27
return / ^ h t t p s ? : \/ \/ / . test ( url ) && ! url . startsWith ( window . location . origin ) ;
20
28
}
21
29
30
+ function rewriteURL ( url : string ) {
31
+ if ( ! url . startsWith ( 'https://tailwindui.com' ) ) {
32
+ return url
33
+ }
34
+
35
+ url = url . replace ( 'https://tailwindui.com/' , 'https://tailwindcss.com/plus/' )
36
+ url = url . replace ( '/plus/components' , '/plus/ui-blocks' )
37
+ url = url . replace ( '/plus/templates/catalyst' , '/plus/ui-kit' )
38
+ url = url . replace ( '/plus/all-access' , '/plus/#pricing' )
39
+ url = url . replace ( '/plus/documentation' , '/plus/ui-blocks/documentation' )
40
+
41
+ return url
42
+ }
43
+
44
+
22
45
const SearchContext = createContext < any > ( { } ) ;
23
46
24
47
export function SearchProvider ( { children } : React . PropsWithChildren ) {
@@ -55,7 +78,7 @@ export function SearchProvider({ children }: React.PropsWithChildren) {
55
78
try {
56
79
let data = JSON . parse ( localStorage . getItem ( key ) as any ) ;
57
80
for ( let item of data ) {
58
- if ( isTailwindUIUrl ( item . url ) && ! item . hierarchy . lvl1 . startsWith ( "Components" ) ) {
81
+ if ( isTailwindPlusURL ( item . url ) && ! item . hierarchy . lvl1 . startsWith ( "Components" ) ) {
59
82
item . hierarchy . lvl1 = `Components / ${ item . hierarchy . lvl1 } ` ;
60
83
}
61
84
}
@@ -122,13 +145,20 @@ export function SearchProvider({ children }: React.PropsWithChildren) {
122
145
setIsOpen ( false ) ;
123
146
if ( isExternalURL ( itemUrl ) ) {
124
147
window . open ( itemUrl , "_blank" ) ;
148
+ } else if ( ! isTailwindPlusURL ( itemUrl ) ) {
149
+ router . push ( itemUrl ) ;
125
150
} else {
126
151
router . push ( itemUrl ) ;
127
152
}
128
153
} ,
129
154
} }
130
155
hitComponent = { Hit }
131
156
transformItems = { ( items ) => {
157
+ items = items . map ( ( item ) => {
158
+ item . url = rewriteURL ( item . url )
159
+ return item
160
+ } )
161
+
132
162
return items . map ( ( item , index ) => {
133
163
// We transform the absolute URL into a relative URL to
134
164
// leverage Next's preloading.
@@ -148,7 +178,7 @@ export function SearchProvider({ children }: React.PropsWithChildren) {
148
178
) ;
149
179
}
150
180
151
- let isTailwindUI = isTailwindUIUrl ( item . url ) ;
181
+ let isTailwindUI = isTailwindPlusURL ( item . url ) ;
152
182
153
183
return {
154
184
...item ,
@@ -159,14 +189,15 @@ export function SearchProvider({ children }: React.PropsWithChildren) {
159
189
{ lvl1 : `${ item . product } / ${ item . product_category } ` }
160
190
: { } ) ,
161
191
} ,
162
- url : isTailwindUI ? item . url . split ( "#" ) [ 0 ] : `${ a . pathname } ${ hash } ` ,
192
+ url : `${ a . pathname } ${ hash } ` ,
163
193
__is_result : ( ) => true ,
164
194
__is_parent : ( ) => item . type === "lvl1" && items . length > 1 && index === 0 ,
165
195
__is_child : ( ) =>
166
196
item . type !== "lvl1" && items . length > 1 && items [ 0 ] . type === "lvl1" && index !== 0 ,
167
197
__is_first : ( ) => index === 1 ,
168
198
__is_last : ( ) => index === items . length - 1 && index !== 0 ,
169
199
__is_tailwindui : ( ) => isTailwindUI ,
200
+ __is_tailwindcss : ( ) => ! isTailwindUI ,
170
201
} ;
171
202
} ) ;
172
203
} }
@@ -182,7 +213,6 @@ function Hit({ hit, children }: { hit: any; children: React.ReactNode }) {
182
213
return (
183
214
< Link
184
215
href = { hit . url }
185
- target = { hit . __is_tailwindui ?.( ) ? "_blank" : undefined }
186
216
className = { clsx ( {
187
217
"DocSearch-Hit--Result" : hit . __is_result ?.( ) ,
188
218
"DocSearch-Hit--Parent" : hit . __is_parent ?.( ) ,
0 commit comments