1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768openAstringopenOdoc_json_indexopenOr_erroropenOdoc_modellethandle_filefile~unit~page=Odoc_file.loadfile>>=fununit'->matchunit'with|{Odoc_file.content=Unit_contentunit';_}whenunit'.hidden->Error(`Msg"Hidden units are ignored when generating an index")|{Odoc_file.content=Unit_contentunit';_}(* when not unit'.hidden *)->Ok(unitunit')|{Odoc_file.content=Page_contentpage';_}->Ok(pagepage')|_->Error(`Msg"Only pages and unit are allowed as input when generating an index")letparse_input_fileinput=letis_sep=function'\n'|'\r'->true|_->falseinFs.File.readinput>>=funcontent->letfiles=String.fields~empty:false~is_sepcontent|>List.rev_mapFs.File.of_stringinOkfilesletparse_input_filesinput=List.fold_left(funaccfile->acc>>=funacc->parse_input_filefile>>=funfiles->Ok(files::acc))(Ok[])input>>=funfiles->Ok(List.concatfiles)letcompile~output~warnings_optionsinputs_in_fileinputs=parse_input_filesinputs_in_file>>=funfiles->letfiles=List.rev_appendinputsfilesinletoutput_channel=Fs.Directory.mkdir_p(Fs.File.dirnameoutput);open_out_bin(Fs.File.to_stringoutput)inletoutput=Format.formatter_of_out_channeloutput_channelinletprintffirstup=ifnotfirstthenFormat.fprintfoutput",";foutputup;falseinFormat.fprintfoutput"[";letindex()=List.fold_left(funaccfile->matchhandle_file~unit:(printJson_search.unitacc)~page:(printJson_search.pageacc)filewith|Okacc->acc|Error(`Msgm)->Error.raise_warning~non_fatal:true(Error.filename_only"%s"m(Fs.File.to_stringfile));acc)truefilesinletresult=Error.catch_warningsindexinresult|>Error.handle_warnings~warnings_options>>=fun(_:bool)->Format.fprintfoutput"]";Ok()