()
| 32 | } |
| 33 | |
| 34 | async function indexDocs() { |
| 35 | await index.reset() |
| 36 | |
| 37 | for (const doc of allDocs) { |
| 38 | try { |
| 39 | const sections = splitMdxByHeadings(doc.content) |
| 40 | |
| 41 | for (const section of sections) { |
| 42 | if (!section || !section.content) continue |
| 43 | |
| 44 | const headingId = `${doc._meta.path}#${slugify(section.title!)}` |
| 45 | |
| 46 | const metadata = { |
| 47 | title: section.title ?? "<Error displaying title>", |
| 48 | path: doc._meta.path, |
| 49 | level: section.level ?? 2, |
| 50 | type: "section", |
| 51 | content: section.content, |
| 52 | documentTitle: doc.title, |
| 53 | } satisfies SearchMetadata |
| 54 | |
| 55 | await index.upsert({ |
| 56 | id: headingId, |
| 57 | data: `${section.title}\n\n${section.content}`, |
| 58 | metadata, |
| 59 | }) |
| 60 | } |
| 61 | |
| 62 | console.log(`✅ Indexed document sections: ${doc.title}`) |
| 63 | } catch (error) { |
| 64 | console.error(`❌ Failed to index ${doc.title}:`, error) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | console.log("✅ Finished indexing docs") |
| 69 | } |
| 70 | |
| 71 | indexDocs().catch(console.error) |
no test coverage detected