@@ -51,13 +51,19 @@ public function generateSearchIndex(): array
5151 }
5252
5353 $ result [] = [
54+ 'id ' => 'api_ ' . $ fn ->fnName (),
5455 'fnName ' => $ fn ->fnName (),
5556 'fnSignature ' => $ fn ->fnSignature (),
5657 'desc ' => $ this ->formatDescription ($ fn ->description ()),
5758 'anchor ' => $ anchor ,
59+ 'type ' => 'api ' ,
5860 ];
5961 }
6062
63+ // Add documentation files to search index
64+ $ documentationItems = $ this ->generateDocumentationSearchItems ();
65+ $ result = array_merge ($ result , $ documentationItems );
66+
6167 return $ result ;
6268 }
6369
@@ -68,4 +74,61 @@ private function formatDescription(string $desc): string
6874 {
6975 return preg_replace ('/\[(.*?)\]\((.*?)\)/ ' , '<i>$1</i> ' , $ desc );
7076 }
77+
78+ /**
79+ * Generate search index items for documentation files
80+ *
81+ * @return array<array{id: string, title: string, content: string, url: string, type: string}>
82+ */
83+ private function generateDocumentationSearchItems (): array
84+ {
85+ $ result = [];
86+ $ documentationPath = __DIR__ . '/../../../../../content/documentation ' ;
87+
88+ if (!is_dir ($ documentationPath )) {
89+ error_log ("Documentation path not found: " . $ documentationPath );
90+ return [];
91+ }
92+
93+ $ files = scandir ($ documentationPath );
94+ if ($ files === false ) {
95+ error_log ("Could not scan documentation directory: " . $ documentationPath );
96+ return [];
97+ }
98+
99+ foreach ($ files as $ file ) {
100+ if (pathinfo ($ file , PATHINFO_EXTENSION ) !== 'md ' || $ file === '_index.md ' ) {
101+ continue ;
102+ }
103+
104+ $ filePath = $ documentationPath . '/ ' . $ file ;
105+ $ content = file_get_contents ($ filePath );
106+
107+ // Extract title from frontmatter
108+ $ title = pathinfo ($ file , PATHINFO_FILENAME );
109+ if (preg_match ('/title = "([^"]+)"/ ' , $ content , $ matches )) {
110+ $ title = $ matches [1 ];
111+ }
112+
113+ // Remove frontmatter
114+ $ content = preg_replace ('/\+\+\+.*?\+\+\+/s ' , '' , $ content );
115+
116+ // Remove markdown formatting and clean content
117+ $ content = preg_replace ('/[#`*\[\]()]/ ' , ' ' , $ content );
118+ $ content = preg_replace ('/\s+/ ' , ' ' , trim ($ content ));
119+
120+ // Limit content length for search index
121+ $ content = substr ($ content , 0 , 500 );
122+
123+ $ result [] = [
124+ 'id ' => 'doc_ ' . pathinfo ($ file , PATHINFO_FILENAME ),
125+ 'title ' => $ title ,
126+ 'content ' => $ content ,
127+ 'url ' => '/documentation/ ' . pathinfo ($ file , PATHINFO_FILENAME ),
128+ 'type ' => 'documentation ' ,
129+ ];
130+ }
131+
132+ return $ result ;
133+ }
71134}
0 commit comments