% Dim page, mdPath, mdContent, htmlContent, menuContent, menuHtml, apiAction Dim g3md, fso, ax, indexPathDir, indexCompiledPath Set fso = Server.CreateObject("Scripting.FileSystemObject") Set ax = Server.CreateObject("G3AXON.FUNCTIONS") ' Initialize index paths indexPathDir = Server.MapPath("search-index") indexCompiledPath = indexPathDir & ax.AxDirSeparator() & "manual" apiAction = LCase(Trim(Request.QueryString("api"))) If apiAction = "search" Then Response.ContentType = "application/json" Response.Charset = "utf-8" Response.Write SearchManualJson(Trim(Request.QueryString("q"))) Response.End End If 'Future implementation If apiAction = "triggerindexbuild" Then Response.ContentType = "application/json" Response.Charset = "utf-8" InitializeIndexIfNeeded() Response.Write GetIndexStatusJson() Response.End End If If apiAction = "indexstatus" Then Response.ContentType = "application/json" Response.Charset = "utf-8" Response.Write GetIndexStatusJson() Response.End End If Function BoolToJson(value) If CBool(value) Then BoolToJson = "true" Else BoolToJson = "false" End If End Function Function GetIndexStatusJson() Dim indexExists, isBuilding indexExists = fso.FolderExists(indexCompiledPath) isBuilding = False GetIndexStatusJson = "{""exists"":" & BoolToJson(indexExists) & ",""building"":" & BoolToJson(isBuilding) & "}" End Function Function InitializeIndexIfNeeded() ' Ensure index directory exists and initialize if needed Dim search On Error Resume Next If Not fso.FolderExists(indexPathDir) Then fso.CreateFolder indexPathDir End If ' Trigger BuildIndex only when compiled index does not exist If Not fso.FolderExists(indexCompiledPath) Then Set search = Server.CreateObject("G3SEARCH") If Err.Number = 0 Then search.IndexPath = indexCompiledPath search.DocsPath = Server.MapPath("md") search.Extension = ".md" search.BuildIndex() Err.Clear End If Set search = Nothing End If On Error Goto 0 End Function ' 1. Get requested page page = Request.QueryString("page") If page = "" Then page = "md/axonasp/welcome" ' Security: Basic path sanitization page = Replace(page, "..", "") ' Accept menu links that include .md and normalize to internal page key If LCase(Right(page, 3)) = ".md" Then page = Left(page, Len(page) - 3) End If ' 2. Load Content mdPath = Server.MapPath(page & ".md") If fso.FileExists(mdPath) Then mdContent = ReadFile(mdPath) Else mdContent = "# 404 - Page Not Found" & vbCrLf & "The requested documentation page '" & ax.AxStripTags(page) & "' was not found." End If ' 3. Render Markdown Set g3md = Server.CreateObject("G3MD") g3md.Unsafe = True htmlContent = g3md.Process(mdContent) If htmlContent = "" And mdContent <> "" Then htmlContent = "
Error: Markdown rendering failed.
" End If ' 4. Render Menu Dim menuMdPath menuMdPath = Server.MapPath("menu.md") If fso.FileExists(menuMdPath) Then menuContent = ReadFile(menuMdPath) ' We use a simple custom parser for the menu to generate the tree structure menuHtml = ParseMenuToTree(menuContent) Else menuHtml = "Menu not found." End If Function ReadFile(path) Dim stream ReadFile = "" On Error Resume Next Set stream = Server.CreateObject("ADODB.Stream") If Err.Number = 0 Then stream.Type = 2 ' Text stream.Charset = "utf-8" stream.Open If Err.Number = 0 Then stream.LoadFromFile path If Err.Number = 0 Then ReadFile = stream.ReadText End If End If End If Err.Clear If Not stream Is Nothing Then stream.Close Set stream = Nothing End If On Error Goto 0 End Function Function ParseMenuToTree(content) ParseMenuToTree = "" End Function Function SearchManualJson(term) Dim search, docsPath, results, resultRow, resultPath, relPath Dim i, rowCount, jsonParts SearchManualJson = "[]" If term = "" Then Exit Function End If On Error Resume Next ' Ensure index is initialized (with concurrency protection) InitializeIndexIfNeeded() Set search = Server.CreateObject("G3SEARCH") If Err.Number <> 0 Then Err.Clear Exit Function End If docsPath = Server.MapPath("md") search.IndexPath = indexCompiledPath search.DocsPath = docsPath search.Extension = ".md" results = search.Search(term) If Err.Number <> 0 Then Err.Clear Exit Function End If If Not IsArray(results) Then Exit Function End If rowCount = UBound(results) - LBound(results) + 1 If rowCount <= 0 Then Exit Function End If ReDim jsonParts(rowCount - 1) rowCount = 0 For i = LBound(results) To UBound(results) resultPath = "" resultRow = results(i) If IsArray(resultRow) Then If UBound(resultRow) >= 0 Then resultPath = CStr(resultRow(0)) End If Else resultPath = CStr(resultRow) End If relPath = NormalizeSearchDocPath(resultPath, docsPath) If relPath <> "" Then jsonParts(rowCount) = Chr(34) & JsonEscape(relPath) & Chr(34) rowCount = rowCount + 1 End If Next If rowCount <= 0 Then Exit Function End If ReDim Preserve jsonParts(rowCount - 1) SearchManualJson = "[" & Join(jsonParts, ",") & "]" End Function Function NormalizeSearchDocPath(rawPath, docsPath) Dim normalizedPath, normalizedDocs, relPath normalizedPath = Replace(CStr(rawPath), "\", "/") normalizedDocs = Replace(CStr(docsPath), "\", "/") relPath = normalizedPath If Len(normalizedDocs) > 0 Then If LCase(Left(normalizedPath, Len(normalizedDocs))) = LCase(normalizedDocs) Then relPath = Mid(normalizedPath, Len(normalizedDocs) + 1) If Left(relPath, 1) = "/" Then relPath = Mid(relPath, 2) End If End If End If If LCase(Left(relPath, 3)) = "md/" Then relPath = Mid(relPath, 4) End If NormalizeSearchDocPath = relPath End Function Function JsonEscape(value) Dim escaped escaped = CStr(value) escaped = Replace(escaped, "\", "\\") escaped = Replace(escaped, Chr(34), "\" & Chr(34)) escaped = Replace(escaped, vbCrLf, "\n") escaped = Replace(escaped, vbCr, "\n") escaped = Replace(escaped, vbLf, "\n") escaped = Replace(escaped, vbTab, "\t") JsonEscape = escaped End Function %>