File tree Expand file tree Collapse file tree 3 files changed +79
-11
lines changed
Expand file tree Collapse file tree 3 files changed +79
-11
lines changed Original file line number Diff line number Diff line change 1+ import { randomUUID } from "crypto" ;
2+ import { FormatResultItem } from "../../utils" ;
13import { DocItem } from "../types" ;
4+ import { parseNextFlightText } from "../utils" ;
5+
6+ const ACTION_ID = "600943e3ab9307ee861b42e0036d6f54427022714e" ;
27
38const gitbook : DocItem = {
49 "en-US" : {
510 icon : "../assets/logo/gitbook.png" ,
6- apiKey :
7- "MDgxNzdmZGVhM2MzMDJiMjAxMzczZTllMmVmMDAxOGQ1N2YzMjAyM2M0ZWMxZjk5NmFmYjE0ODA0OWUzYzFlMGZpbHRlcnM9KHZpZXdhYmxlQnlQdWJsaWNTcGFjZXMlM0FOa0VHUzdoemVxYTM1c01YUVo0WC0xKSUyMEFORCUyMHByb2plY3RJZCUzQWdpdGJvb2steC1wcm9k" ,
8- appId : "U102FN9U1K" ,
9- indexName : "pages" ,
10- type : "algolia" ,
11- homepage : "https://docs.gitbook.com/" ,
11+ type : "custom" ,
12+ homepage : "https://gitbook.com/docs/" ,
13+ request : async ( query : string ) => {
14+ const API_URL = `https://gitbook.com/docs/${ encodeURIComponent ( query ) } ` ;
15+ const res = await fetch ( API_URL , {
16+ method : "POST" ,
17+ headers : {
18+ "next-action" : ACTION_ID ,
19+ } ,
20+ body : JSON . stringify ( [ query , "sitesp_VTXrD" ] ) ,
21+ } )
22+ . then ( ( response ) => response . text ( ) )
23+ . then ( ( text ) => parseNextFlightText ( text ) ) ;
24+
25+ return res . map < FormatResultItem > ( ( item ) => ( {
26+ id : randomUUID ( ) ,
27+ title : item . title || item . body ?. slice ( 0 , 50 ) || "Untitled" ,
28+ content : item . body ,
29+ url : `https://gitbook.com${ item . href } ` ,
30+ } ) ) ;
31+ } ,
1232 } ,
33+
1334} ;
1435
1536export default gitbook ;
Original file line number Diff line number Diff line change 11import { DocItem } from "../types" ;
2+ import { FormatResultItem } from "../../utils" ;
3+ import { randomUUID } from "crypto" ;
4+ import { parseNextFlightText } from "../utils" ;
5+
6+ const ACTION_ID = "600943e3ab9307ee861b42e0036d6f54427022714e" ;
27
38const raycast : DocItem = {
49 "en-US" : {
510 icon : "../assets/logo/raycast.png" ,
6- apiKey :
7- "YmZlNDIxZTVlYWQyOWQ4ZThhMzdkOGUxOTY0YjU2NGNjZDNkOTA5NjQ3MmZmMjg0MzViYjYzMDI4NTVkMmQ1ZmZpbHRlcnM9KHZpZXdhYmxlQnlQdWJsaWNTcGFjZXMlM0EtTWVfOEEzOXRGaFpnM1VhVm9TTi0yKSUyMEFORCUyMHByb2plY3RJZCUzQWdpdGJvb2steC1wcm9k" ,
8- appId : "U102FN9U1K" ,
9- indexName : "pages" ,
10- type : "algolia" ,
11+ type : "custom" ,
1112 homepage : "https://developers.raycast.com/" ,
13+ request : async ( query : string ) => {
14+ const API_URL = `https://developers.raycast.com/api-reference/user-interface/list?q=${ encodeURIComponent ( query ) } ` ;
15+ const res = await fetch ( API_URL , {
16+ method : "POST" ,
17+ headers : {
18+ "next-action" : ACTION_ID ,
19+ } ,
20+ body : JSON . stringify ( [ query , "sitesp_VTXrD" ] ) ,
21+ } )
22+ . then ( ( response ) => response . text ( ) )
23+ . then ( ( text ) => parseNextFlightText ( text ) ) ;
24+
25+ return res . map < FormatResultItem > ( ( item ) => ( {
26+ id : randomUUID ( ) ,
27+ title : item . title || item . body ?. slice ( 0 , 50 ) || "Untitled" ,
28+ content : item . body ,
29+ url : `https://developers.raycast.com${ item . href } ` ,
30+ } ) ) ;
31+ } ,
1232 } ,
1333} ;
1434
Original file line number Diff line number Diff line change 1+ type ItemType = "page" | "section" ;
2+ export type GitBookAiSearchItem = {
3+ type : ItemType ;
4+ id : string ;
5+ title : string ;
6+ href : string ;
7+ pageId : string ;
8+ spaceId : string ;
9+ breadcrumbs ?: { label : string } [ ] ;
10+ body ?: string ;
11+ } ;
12+
13+
14+ export function parseNextFlightText ( text : string ) {
15+ const result : Array < GitBookAiSearchItem > = [ ] ;
16+
17+ const matchs = text . match ( / 1 : (?< rawValue > ( ( .* ) \s * ) * ) $ / m) ;
18+ if ( ! matchs ) return result ;
19+
20+ const { rawValue } = matchs . groups as { rawValue : string } ;
21+ const clean = rawValue . trim ( ) . replace ( / \n / g, "" ) . replace ( / \r / g, "" ) ;
22+
23+ result . push ( ...JSON . parse ( clean ) ) ;
24+
25+ return result ;
26+ }
27+
You can’t perform that action at this time.
0 commit comments