@@ -11,14 +11,37 @@ const INDEX_NAME = "tailwindcss";
1111const API_KEY = "5fc87cef58bb80203d2207578309fab6" ;
1212const APP_ID = "KNPXZI5B0M" ;
1313
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+ )
1620}
1721
1822function isExternalURL ( url : string ) {
23+ if ( url . startsWith ( 'https://tailwindui.com' ) ) {
24+ return false
25+ }
26+
1927 return / ^ h t t p s ? : \/ \/ / . test ( url ) && ! url . startsWith ( window . location . origin ) ;
2028}
2129
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+
2245const SearchContext = createContext < any > ( { } ) ;
2346
2447export function SearchProvider ( { children } : React . PropsWithChildren ) {
@@ -55,7 +78,7 @@ export function SearchProvider({ children }: React.PropsWithChildren) {
5578 try {
5679 let data = JSON . parse ( localStorage . getItem ( key ) as any ) ;
5780 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" ) ) {
5982 item . hierarchy . lvl1 = `Components / ${ item . hierarchy . lvl1 } ` ;
6083 }
6184 }
@@ -122,13 +145,20 @@ export function SearchProvider({ children }: React.PropsWithChildren) {
122145 setIsOpen ( false ) ;
123146 if ( isExternalURL ( itemUrl ) ) {
124147 window . open ( itemUrl , "_blank" ) ;
148+ } else if ( ! isTailwindPlusURL ( itemUrl ) ) {
149+ router . push ( itemUrl ) ;
125150 } else {
126151 router . push ( itemUrl ) ;
127152 }
128153 } ,
129154 } }
130155 hitComponent = { Hit }
131156 transformItems = { ( items ) => {
157+ items = items . map ( ( item ) => {
158+ item . url = rewriteURL ( item . url )
159+ return item
160+ } )
161+
132162 return items . map ( ( item , index ) => {
133163 // We transform the absolute URL into a relative URL to
134164 // leverage Next's preloading.
@@ -148,7 +178,7 @@ export function SearchProvider({ children }: React.PropsWithChildren) {
148178 ) ;
149179 }
150180
151- let isTailwindUI = isTailwindUIUrl ( item . url ) ;
181+ let isTailwindUI = isTailwindPlusURL ( item . url ) ;
152182
153183 return {
154184 ...item ,
@@ -159,14 +189,15 @@ export function SearchProvider({ children }: React.PropsWithChildren) {
159189 { lvl1 : `${ item . product } / ${ item . product_category } ` }
160190 : { } ) ,
161191 } ,
162- url : isTailwindUI ? item . url . split ( "#" ) [ 0 ] : `${ a . pathname } ${ hash } ` ,
192+ url : `${ a . pathname } ${ hash } ` ,
163193 __is_result : ( ) => true ,
164194 __is_parent : ( ) => item . type === "lvl1" && items . length > 1 && index === 0 ,
165195 __is_child : ( ) =>
166196 item . type !== "lvl1" && items . length > 1 && items [ 0 ] . type === "lvl1" && index !== 0 ,
167197 __is_first : ( ) => index === 1 ,
168198 __is_last : ( ) => index === items . length - 1 && index !== 0 ,
169199 __is_tailwindui : ( ) => isTailwindUI ,
200+ __is_tailwindcss : ( ) => ! isTailwindUI ,
170201 } ;
171202 } ) ;
172203 } }
@@ -182,7 +213,6 @@ function Hit({ hit, children }: { hit: any; children: React.ReactNode }) {
182213 return (
183214 < Link
184215 href = { hit . url }
185- target = { hit . __is_tailwindui ?.( ) ? "_blank" : undefined }
186216 className = { clsx ( {
187217 "DocSearch-Hit--Result" : hit . __is_result ?.( ) ,
188218 "DocSearch-Hit--Parent" : hit . __is_parent ?.( ) ,
0 commit comments