Skip to content

Commit ed2e97e

Browse files
committed
fix: raycast and gitbook change to GitBook AI Search
1 parent a4ac81b commit ed2e97e

File tree

3 files changed

+79
-11
lines changed

3 files changed

+79
-11
lines changed

src/data/docs/gitbook.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1+
import { randomUUID } from "crypto";
2+
import { FormatResultItem } from "../../utils";
13
import { DocItem } from "../types";
4+
import { parseNextFlightText } from "../utils";
5+
6+
const ACTION_ID = "600943e3ab9307ee861b42e0036d6f54427022714e";
27

38
const 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

1536
export default gitbook;

src/data/docs/raycast.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
import { 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

38
const 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

src/data/utils/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+

0 commit comments

Comments
 (0)