Skip to content

Commit d254469

Browse files
authored
Fixes orama summaries (#652)
1 parent dec6820 commit d254469

4 files changed

Lines changed: 34 additions & 72 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"@solidjs/router": "^0.13.1",
2525
"@solidjs/start": "^1.0.0-rc.0",
2626
"@vinxi/plugin-mdx": "^3.7.1",
27-
"cheerio": "1.0.0-rc.12",
2827
"dotenv": "^16.4.5",
2928
"glob": "^10.3.10",
3029
"gray-matter": "^4.0.3",
@@ -44,6 +43,7 @@
4443
"devDependencies": {
4544
"@kobalte/tailwindcss": "^0.9.0",
4645
"@mdx-js/mdx": "^2.3.0",
46+
"@orama/crawly": "^0.0.4",
4747
"@tailwindcss/typography": "^0.5.10",
4848
"@types/node": "^20.11.28",
4949
"@typescript-eslint/eslint-plugin": "^7.2.0",

pnpm-lock.yaml

Lines changed: 27 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/sync-orama.mjs

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,25 @@
11
import { readFileSync } from "node:fs";
22
import { globSync } from "glob";
3-
import { load } from "cheerio";
3+
import { generalPurposeCrawler } from "@orama/crawly";
44
import "dotenv/config";
55

66
const ORAMA_PRIVATE_API_KEY = process.env.ORAMA_PRIVATE_API_KEY;
77
const ORAMA_PRIVATE_INDEX_ID = process.env.ORAMA_PRIVATE_INDEX_ID;
88

99
const baseURL = new URL("../dist", import.meta.url).pathname;
1010
const HTMLFiles = globSync("**/*.html", { cwd: baseURL });
11-
const headers = ["h1", "h2", "h3", "h4", "h5", "h6"];
1211

1312
const pagesToIndex = HTMLFiles.flatMap((file) => {
1413
const path = file.replace(/\.html$/, "");
1514
const pageContent = readFileSync(
1615
new URL(`../dist/${file}`, import.meta.url),
1716
"utf8"
1817
);
19-
const $ = load(pageContent);
2018

21-
const results = [];
22-
const title = $("h1").first().text().trim();
23-
let currentSection = "";
24-
let currentContent = "";
25-
26-
$("*").each(function () {
27-
const isHeader = $(this).is(headers.join(", "));
28-
if (isHeader) {
29-
if (currentSection && currentContent) {
30-
results.push({
31-
title: title,
32-
content: currentContent.trim(),
33-
path: getPath(path),
34-
category: getCategory(getPath(path)),
35-
section: currentSection,
36-
});
37-
}
38-
if (!$(this).is("h1")) {
39-
currentSection = $(this)
40-
.clone()
41-
.children()
42-
.remove("script")
43-
.end()
44-
.text()
45-
.trim();
46-
}
47-
currentContent = "";
48-
} else if ($(this).is("p")) {
49-
currentContent += `${$(this).clone().children().remove("script").end().text().trim()} `;
50-
}
51-
});
52-
53-
if (currentSection && currentContent) {
54-
results.push({
55-
title: title,
56-
content: currentContent.trim(),
57-
path: getPath(path),
58-
category: getCategory(getPath(path)),
59-
section: currentSection,
60-
});
61-
}
62-
63-
return results;
19+
const productionDocsURL = `https://docs.solidjs.com/${path}`;
20+
return generalPurposeCrawler(productionDocsURL, pageContent);
6421
});
6522

66-
function getPath(path) {
67-
return path.endsWith("index") ? path.replace(/index$/, "") : path;
68-
}
69-
70-
function getCategory(path) {
71-
const category = path.split("/")[0];
72-
return category === "index" ? "" : category;
73-
}
74-
7523
async function emptyIndex() {
7624
await fetch(
7725
`https://api.oramasearch.com/api/v1/webhooks/${ORAMA_PRIVATE_INDEX_ID}/snapshot`,

src/ui/searchbox.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export function SearchBox() {
2121
createEffect(() => {
2222
RegisterSearchBox({
2323
summaryGeneration: import.meta.env.VITE_ORAMA_SECURE_PROXY,
24-
searchMode: "hybrid",
2524
oramaInstance: client,
2625
colorScheme: selectedTheme().value,
2726
backdrop: true,
27+
resultsMap: {
28+
description: 'content'
29+
},
2830
themeConfig: {
2931
light: {},
3032
dark: {

0 commit comments

Comments
 (0)