@robindoc/minisearch 0.0.0-experimental-11b183c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/lib/cli.d.ts +3 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +3 -0
- package/lib/cli.js.map +1 -0
- package/lib/create-static-searcher.d.ts +3 -0
- package/lib/create-static-searcher.d.ts.map +1 -0
- package/lib/create-static-searcher.js +2 -0
- package/lib/create-static-searcher.js.map +1 -0
- package/lib/generate-search-index.d.ts +3 -0
- package/lib/generate-search-index.d.ts.map +1 -0
- package/lib/generate-search-index.js +2 -0
- package/lib/generate-search-index.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/provider.d.ts +2 -0
- package/lib/provider.d.ts.map +1 -0
- package/lib/provider.js +2 -0
- package/lib/provider.js.map +1 -0
- package/lib/types.d.ts +23 -0
- package/lib/types.d.ts.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alex Savelyev <dev@alexdln.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/cli.d.ts
ADDED
package/lib/cli.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/lib/cli.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{resolve as e,join as t}from"path";import{existsSync as r}from"fs";import{generateSearchIndex as o}from"./generate-search-index.js";import{pathToFileURL as s}from"node:url";const a=process.argv.slice(2),i=a.indexOf("--template"),c=a.indexOf("--output");-1!==i&&a[i+1]||(console.error("Error: --template option is required"),console.error("Usage: npx robindoc-minisearch --template <path> [--output <path>]"),process.exit(1));const n=e(process.cwd(),a[i+1]),p=s(n).toString(),l=-1!==c&&a[c+1]?e(process.cwd(),a[c+1]):t(process.cwd(),"public","search-index.json");r(n)||(console.error(`Error: Template file not found: ${n}`),process.exit(1));(async()=>{try{if(n.endsWith(".ts")||n.endsWith(".tsx")){const e=await import("tsx");e.register&&e.register()}const e=await import(p),t="default"in e?e.default:e,{getStaticParams:r,getPageData:s}=t;if(!r||!s)throw new Error("Template file must export 'getStaticParams' and 'getPageData' from initializeRobindoc.\nExample: export const { getStaticParams, getPageData } = initializeRobindoc(...);");await o(r,s,l),console.log(`Search index generated successfully at ${l}`),process.exit(0)}catch(e){console.error("Failed to generate search index:",e),e instanceof Error&&(console.error(e.message),e.stack&&console.error(e.stack)),process.exit(1)}})();
|
|
3
|
+
//# sourceMappingURL=cli.js.map
|
package/lib/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { resolve, join } from \"path\";\nimport { existsSync } from \"fs\";\nimport { generateSearchIndex } from \"./generate-search-index\";\nimport { pathToFileURL } from \"node:url\";\n\nconst args = process.argv.slice(2);\nconst templateIndex = args.indexOf(\"--template\");\nconst outputIndex = args.indexOf(\"--output\");\n\nif (templateIndex === -1 || !args[templateIndex + 1]) {\n console.error(\"Error: --template option is required\");\n console.error(\"Usage: npx robindoc-minisearch --template <path> [--output <path>]\");\n process.exit(1);\n}\n\nconst templatePath = resolve(process.cwd(), args[templateIndex + 1]);\nconst templatePathUrl = pathToFileURL(templatePath).toString();\nconst outputPath =\n outputIndex !== -1 && args[outputIndex + 1]\n ? resolve(process.cwd(), args[outputIndex + 1])\n : join(process.cwd(), \"public\", \"search-index.json\");\n\nif (!existsSync(templatePath)) {\n console.error(`Error: Template file not found: ${templatePath}`);\n process.exit(1);\n}\n\nconst run = async () => {\n try {\n if (templatePath.endsWith(\".ts\") || templatePath.endsWith(\".tsx\")) {\n // @ts-expect-error - optional peer dependency\n const tsx = await import(\"tsx\");\n\n if (tsx.register) {\n tsx.register();\n }\n }\n\n const templateModule = await import(templatePathUrl);\n const moduleDefault = \"default\" in templateModule ? templateModule.default : templateModule;\n const { getStaticParams, getPageData } = moduleDefault;\n\n if (!getStaticParams || !getPageData) {\n throw new Error(\n \"Template file must export 'getStaticParams' and 'getPageData' from initializeRobindoc.\\n\" +\n \"Example: export const { getStaticParams, getPageData } = initializeRobindoc(...);\",\n );\n }\n\n await generateSearchIndex(getStaticParams, getPageData, outputPath);\n\n console.log(`Search index generated successfully at ${outputPath}`);\n process.exit(0);\n } catch (error) {\n console.error(\"Failed to generate search index:\", error);\n if (error instanceof Error) {\n console.error(error.message);\n if (error.stack) {\n console.error(error.stack);\n }\n }\n process.exit(1);\n }\n};\n\nrun();\n"],"names":["args","process","argv","slice","templateIndex","indexOf","outputIndex","console","error","exit","templatePath","resolve","cwd","templatePathUrl","pathToFileURL","toString","outputPath","join","existsSync","async","endsWith","tsx","import","register","templateModule","moduleDefault","default","getStaticParams","getPageData","Error","generateSearchIndex","log","message","stack","run"],"mappings":";mLAOA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAMA,EAAOC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAQC,CAAAA,CAAAA,CAAAA,CAAAA,CAAKC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAM,CAAA,CAAA,CAC1BC,EAAgBJ,CAAAA,CAAKK,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAQ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAC7BC,CAAAA,CAAcN,CAAAA,CAAKK,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAQ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAEX,CAAA,CAAA,CAAA,CAAlBD,GAAyBJ,CAAAA,CAAKI,CAAAA,CAAgB,CAAA,CAAA,CAAA,CAAA,CAC9CG,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAQC,MAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACdD,CAAAA,CAAAA,CAAAA,CAA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null;const e=e=>async(i,n)=>{if(!i.trim())return[];try{const o=await(async e=>{if(r)return r;const i=await fetch(e);if(!i.ok)throw new Error(`Failed to load search index: ${i.statusText}`);const n=await i.json(),o=await t.loadJSAsync(n,{fields:["title","content","headings","description"],storeFields:["id","title","href","headings","description"],searchOptions:{boost:{title:5,headings:3,description:2},fuzzy:.2}});return r=o,o})(e);if(n.signal.aborted)return[];const s=o.search(i,{fuzzy:.2,prefix:!0,boost:{title:5,headings:3,description:2}});return n.signal.aborted?[]:s.slice(0,10).map(t=>({title:t.title,href:t.href,description:t.description}))}catch(t){return t instanceof Error&&"AbortError"===t.name||console.error("Search error:",t),[]}};export{e as createStaticSearcher};
|
|
2
|
+
//# sourceMappingURL=create-static-searcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-static-searcher.js","sources":["../src/create-static-searcher.ts"],"sourcesContent":["import MiniSearch, { type AsPlainObject } from \"minisearch\";\n\nimport { type Searcher, type SearchItem, type SearchIndexItem } from \"./types\";\n\nlet cachedIndex: MiniSearch<SearchIndexItem> | null = null;\n\nconst loadSearchIndex = async (indexUrl: string): Promise<MiniSearch<SearchIndexItem>> => {\n if (cachedIndex) return cachedIndex;\n\n const response = await fetch(indexUrl);\n if (!response.ok) {\n throw new Error(`Failed to load search index: ${response.statusText}`);\n }\n\n const data: AsPlainObject = await response.json();\n const searchIndex = await MiniSearch.loadJSAsync(data, {\n fields: [\"title\", \"content\", \"headings\", \"description\"],\n storeFields: [\"id\", \"title\", \"href\", \"headings\", \"description\"],\n searchOptions: {\n boost: { title: 5, headings: 3, description: 2 },\n fuzzy: 0.2,\n },\n });\n\n cachedIndex = searchIndex;\n\n return searchIndex;\n};\n\nexport const createStaticSearcher = (indexUrl: string): Searcher => {\n return async (search: string, abortController: AbortController): Promise<SearchItem[]> => {\n if (!search.trim()) return [];\n\n try {\n const searchIndex = await loadSearchIndex(indexUrl);\n\n if (abortController.signal.aborted) return [];\n\n const results = searchIndex.search(search, {\n fuzzy: 0.2,\n prefix: true,\n boost: { title: 5, headings: 3, description: 2 },\n });\n\n if (abortController.signal.aborted) return [];\n\n return results.slice(0, 10).map((result) => ({\n title: result.title,\n href: result.href,\n description: result.description,\n }));\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") {\n return [];\n }\n console.error(\"Search error:\", error);\n return [];\n }\n };\n};\n"],"names":["cachedIndex","createStaticSearcher","indexUrl","async","search","abortController","trim","searchIndex","response","fetch","ok","Error","statusText","data","json","MiniSearch","loadJSAsync","fields","storeFields","searchOptions","boost","title","headings","description","fuzzy","loadSearchIndex","signal","aborted","results","prefix","slice","map","result","href","error","name","console"],"mappings":"0BAIA,IAAIA,EAAkD,KAEtD,MAuBaC,EAAwBC,GAC1BC,MAAOC,EAAgBC,KAC1B,IAAKD,EAAOE,OAAQ,MAAO,GAE3B,IACI,MAAMC,OA5BMJ,OAAOD,IAC3B,GAAIF,EAAa,OAAOA,EAExB,MAAMQ,QAAiBC,MAAMP,GAC7B,IAAKM,EAASE,GACV,MAAM,IAAIC,MAAM,gCAAgCH,EAASI,cAG7D,MAAMC,QAA4BL,EAASM,OACrCP,QAAoBQ,EAAWC,YAAYH,EAAM,CACnDI,OAAQ,CAAC,QAAS,UAAW,WAAY,eACzCC,YAAa,CAAC,KAAM,QAAS,OAAQ,WAAY,eACjDC,cAAe,CACXC,MAAO,CAAEC,MAAO,EAAGC,SAAU,EAAGC,YAAa,GAC7CC,MAAO,MAMf,OAFAxB,EAAcO,EAEPA,GAQ2BkB,CAAgBvB,GAE1C,GAAIG,EAAgBqB,OAAOC,QAAS,MAAO,GAE3C,MAAMC,EAAUrB,EAAYH,OAAOA,EAAQ,CACvCoB,MAAO,GACPK,QAAQ,EACRT,MAAO,CAAEC,MAAO,EAAGC,SAAU,EAAGC,YAAa,KAGjD,OAAIlB,EAAgBqB,OAAOC,QAAgB,GAEpCC,EAAQE,MAAM,EAAG,IAAIC,IAAKC,IAAM,CACnCX,MAAOW,EAAOX,MACdY,KAAMD,EAAOC,KACbV,YAAaS,EAAOT,cAE5B,CAAE,MAAOW,GACL,OAAIA,aAAiBvB,OAAwB,eAAfuB,EAAMC,MAGpCC,QAAQF,MAAM,gBAAiBA,GAFpB,EAIf"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type GetPageDataFunction, type GetStaticParamsFunction } from "./types";
|
|
2
|
+
export declare const generateSearchIndex: (getStaticParams: GetStaticParamsFunction, getPageData: GetPageDataFunction, outputPath: string) => Promise<void>;
|
|
3
|
+
//# sourceMappingURL=generate-search-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-search-index.d.ts","sourceRoot":"","sources":["../src/generate-search-index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,uBAAuB,EAAwB,MAAM,SAAS,CAAC;AA6DvG,eAAO,MAAM,mBAAmB,GAC5B,iBAAiB,uBAAuB,EACxC,aAAa,mBAAmB,EAChC,YAAY,MAAM,KACnB,OAAO,CAAC,IAAI,CAwCd,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{mkdir as t,writeFile as i}from"fs/promises";import{lexer as e}from"marked";import{dirname as n}from"path";import o from"minisearch";import s from"gray-matter";const r=t=>t?"tokens"in t?t.tokens?.map(t=>r(t)).join("")||"":"text"in t?t.text:"raw"in t?t.raw:"":"",a=t=>{const{content:i,data:n}=s(t),o=e(i.trim());let a=n.title||"",c=n.description||"";const p=[],d=[];return o.forEach(t=>{if("heading"===t.type){const i=r(t);return void(i&&(a||(a=i),d.push(i),p.push(i)))}if("paragraph"===t.type){const i=r(t);return void(i&&(c||(c=i),p.push(i)))}["list","blockquote","table"].includes(t.type)&&p.push(r(t))}),{title:a,description:c,headings:d.join(" ").trim(),plainText:p.join(" ").trim()}},c=async(e,s,r)=>{const c=[],p=await e();for(const t of p){const i=`/${t.segments.join("/")}`;try{const t=await s(i);if(!t)continue;const e=a(t.raw),n=t.title||e.title,o=e.description||e.plainText.substring(0,200).trim();c.push({id:i,title:n,href:i,headings:e.headings,content:e.plainText,description:o})}catch(t){console.warn(`Failed to index page ${i}:`,t)}}const d=new o({fields:["title","content","headings","description"],storeFields:["id","title","href","headings","description"],searchOptions:{boost:{title:5,headings:3,description:2},fuzzy:.2}});await Promise.all([d.addAllAsync(c),t(n(r),{recursive:!0})]),await i(r,JSON.stringify(d.toJSON()),"utf-8")};export{c as generateSearchIndex};
|
|
2
|
+
//# sourceMappingURL=generate-search-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-search-index.js","sources":["../src/generate-search-index.ts"],"sourcesContent":["import { writeFile, mkdir } from \"fs/promises\";\nimport { lexer, type Token } from \"marked\";\nimport { dirname } from \"path\";\nimport MiniSearch from \"minisearch\";\nimport matter from \"gray-matter\";\n\nimport { type GetPageDataFunction, type GetStaticParamsFunction, type SearchIndexItem } from \"./types\";\n\nconst parseTokenText = (token: Token): string => {\n if (!token) return \"\";\n\n if (\"tokens\" in token) {\n return token.tokens?.map((el: Token) => parseTokenText(el)).join(\"\") || \"\";\n }\n\n if (\"text\" in token) {\n return token.text;\n }\n\n if (\"raw\" in token) {\n return token.raw;\n }\n\n return \"\";\n};\n\nconst parseMarkdownContent = (rawContent: string) => {\n const { content: matterContent, data: matterData } = matter(rawContent);\n const tokens = lexer(matterContent.trim());\n\n let title = matterData.title || \"\";\n let description = matterData.description || \"\";\n const plainTextParts: string[] = [];\n\n const headings: string[] = [];\n tokens.forEach((token: Token) => {\n if (token.type === \"heading\") {\n const headingText = parseTokenText(token);\n if (headingText) {\n if (!title) title = headingText;\n headings.push(headingText);\n plainTextParts.push(headingText);\n }\n return;\n }\n if (token.type === \"paragraph\") {\n const paragraphText = parseTokenText(token);\n if (paragraphText) {\n if (!description) description = paragraphText;\n plainTextParts.push(paragraphText);\n }\n return;\n }\n if ([\"list\", \"blockquote\", \"table\"].includes(token.type)) {\n plainTextParts.push(parseTokenText(token));\n return;\n }\n });\n\n return {\n title,\n description,\n headings: headings.join(\" \").trim(),\n plainText: plainTextParts.join(\" \").trim(),\n };\n};\n\nexport const generateSearchIndex = async (\n getStaticParams: GetStaticParamsFunction,\n getPageData: GetPageDataFunction,\n outputPath: string,\n): Promise<void> => {\n const searchItems: SearchIndexItem[] = [];\n\n const staticParams = await getStaticParams();\n\n for (const staticParam of staticParams) {\n const pathname = `/${staticParam.segments.join(\"/\")}`;\n try {\n const pageData = await getPageData(pathname);\n\n if (!pageData) continue;\n\n const parsed = parseMarkdownContent(pageData.raw);\n const title = pageData.title || parsed.title;\n const description = parsed.description || parsed.plainText.substring(0, 200).trim();\n\n searchItems.push({\n id: pathname,\n title,\n href: pathname,\n headings: parsed.headings,\n content: parsed.plainText,\n description,\n });\n } catch (error) {\n console.warn(`Failed to index page ${pathname}:`, error);\n }\n }\n\n const searchIndex = new MiniSearch<SearchIndexItem>({\n fields: [\"title\", \"content\", \"headings\", \"description\"],\n storeFields: [\"id\", \"title\", \"href\", \"headings\", \"description\"],\n searchOptions: {\n boost: { title: 5, headings: 3, description: 2 },\n fuzzy: 0.2,\n },\n });\n\n await Promise.all([searchIndex.addAllAsync(searchItems), mkdir(dirname(outputPath), { recursive: true })]);\n await writeFile(outputPath, JSON.stringify(searchIndex.toJSON()), \"utf-8\");\n};\n"],"names":["parseTokenText","token","tokens","map","el","join","text","raw","parseMarkdownContent","rawContent","content","matterContent","data","matterData","matter","lexer","trim","title","description","plainTextParts","headings","forEach","type","headingText","push","paragraphText","includes","plainText","generateSearchIndex","async","getStaticParams","getPageData","outputPath","searchItems","staticParams","staticParam","pathname","segments","pageData","parsed","substring","id","href","error","console","warn","searchIndex","MiniSearch","fields","storeFields","searchOptions","boost","fuzzy","Promise","all","addAllAsync","mkdir","dirname","recursive","writeFile","JSON","stringify","toJSON"],"mappings":"sKAQA,MAAMA,EAAkBC,GACfA,EAED,WAAYA,EACLA,EAAMC,QAAQC,IAAKC,GAAcJ,EAA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UAChBT,eAER,CAAE,MAAOyB,GACLC,QAAQC,KAAK,wBAAwBT,KAAaO,EACtD,CACJ,CAEA,MAAMG,EAAc,IAAIC,EAA4B,CAChDC,OAAQ,CAAC,QAAS,UAAW,WAAY,eACzCC,YAAa,CAAC,KAAM,QAAS,OAAQ,WAAY,eACjDC,cAAe,CACXC,MAAO,CAAElC,MAAO,EAAGG,SAAU,EAAGF,YAAa,GAC7CkC,MAAO,YAITC,QAAQC,IAAI,CAACR,EAAYS,YAAYtB,GAAcuB,EAAMC,EAAQzB,GAAa,CAAE0B,WAAW,YAC3FC,EAAU3B,EAAY4B,KAAKC,UAAUf,EAAYgB,UAAW"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,cAAc,SAAS,CAAC"}
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,kDAAuB,CAAC"}
|
package/lib/provider.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../src/provider.ts"],"sourcesContent":["import { createStaticSearcher } from \"./create-static-searcher\";\n\nexport const createSearchProvider = createStaticSearcher;\n"],"names":["createSearchProvider","createStaticSearcher"],"mappings":"mEAEO,MAAMA,EAAuBC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type SearchItem = {
|
|
2
|
+
title: string;
|
|
3
|
+
href: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
};
|
|
6
|
+
export type SearchResults = SearchItem[];
|
|
7
|
+
export type Searcher = (search: string, abortController: AbortController) => Promise<SearchItem[]>;
|
|
8
|
+
export type SearchIndexItem = {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
headings: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
content: string;
|
|
14
|
+
href: string;
|
|
15
|
+
};
|
|
16
|
+
export type GetStaticParamsFunction = () => Promise<Array<{
|
|
17
|
+
segments: string[];
|
|
18
|
+
}>>;
|
|
19
|
+
export type GetPageDataFunction = (pathname: string) => Promise<{
|
|
20
|
+
title: string;
|
|
21
|
+
raw: string;
|
|
22
|
+
} | null>;
|
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,MAAM,MAAM,aAAa,GAAG,UAAU,EAAE,CAAC;AAEzC,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,eAAe,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AAEnG,MAAM,MAAM,eAAe,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAAC,CAAC;AACnF,MAAM,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@robindoc/minisearch",
|
|
3
|
+
"version": "0.0.0-experimental-11b183c",
|
|
4
|
+
"description": "MiniSearch integration for robindoc documentation sites",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"robindoc-minisearch": "./lib/cli.js",
|
|
8
|
+
"@robindoc/minisearch": "./lib/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./lib/index.js",
|
|
12
|
+
"./provider": "./lib/provider.js"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"prepare": "ts-patch install -s",
|
|
16
|
+
"build": "rollup -c",
|
|
17
|
+
"dev": "rollup -c -w"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"robindoc",
|
|
24
|
+
"minisearch",
|
|
25
|
+
"search",
|
|
26
|
+
"documentation"
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git://github.com/alexdln/robindoc.git"
|
|
31
|
+
},
|
|
32
|
+
"author": {
|
|
33
|
+
"name": "Alex Savelyev",
|
|
34
|
+
"email": "dev@alexdln.com",
|
|
35
|
+
"url": "https://github.com/alexdln/"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"minisearch": "7.2.0",
|
|
40
|
+
"marked": "17.0.1",
|
|
41
|
+
"gray-matter": "^4.0.3"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@rollup/plugin-commonjs": "29.0.0",
|
|
45
|
+
"@rollup/plugin-terser": "0.4.4",
|
|
46
|
+
"@rollup/plugin-typescript": "12.3.0",
|
|
47
|
+
"@types/node": "25.0.8",
|
|
48
|
+
"@types/react": "19.2.8",
|
|
49
|
+
"@types/react-dom": "19.2.3",
|
|
50
|
+
"rollup": "4.55.1",
|
|
51
|
+
"ts-patch": "3.3.0",
|
|
52
|
+
"tsx": "^4.19.2",
|
|
53
|
+
"typescript": "5.9.3",
|
|
54
|
+
"typescript-transform-paths": "3.5.6"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"tsx": ">= 1.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"tsx": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|