diff --git a/www/Default.aspx.vb b/www/Default.aspx.vb index 740e7d8..acbe0b4 100644 --- a/www/Default.aspx.vb +++ b/www/Default.aspx.vb @@ -2,6 +2,7 @@ Option Strict On Imports System.IO Imports System.Globalization +Imports System.Text.Json Imports System.XML Imports System.XML.Linq @@ -51,19 +52,19 @@ Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Han requestType = Request.QueryString("type") ''' sanitize for empty values and the default file - if String.IsNullOrEmpty(requestType) then + If String.IsNullOrEmpty(requestType) Then requestType = "document" - end if + End If ''' Get the current requested URL requestUrl = Request.QueryString("path") ''' sanitize for empty values and the default file - if String.IsNullOrEmpty(requestUrl) then + If String.IsNullOrEmpty(requestUrl) Then requestUrl = "/" - else if requestUrl = "default.aspx" then + Else If requestUrl = "default.aspx" Then requestUrl = "/" - end if + End If ''' Evaluate which file is required: ''' @@ -76,27 +77,27 @@ Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Han ''' this is called from Default.aspx to actually include the requested content -Protected function preparePage(pageFile As FileInfo, ByRef basename As String, ByRef caption As String) As FileInfo +Protected Function preparePage(pageFile As FileInfo, ByRef basename As String, ByRef caption As String) As FileInfo Dim dirInfo As DirectoryInfo Dim suffix = "" Dim isHTTPS = false - ''' Get server information - SERVER_NAME = Request.ServerVariables.GetValues( "SERVER_NAME")(0) - SERVER_PORT = Request.ServerVariables.GetValues( "SERVER_PORT")(0) - HTTPS = Request.ServerVariables.GetValues( "HTTPS")(0) - isHTTPS = if(HTTPS = "ON", true, false ) - - ''' Build foot URL - IF isHTTPS then - rootUrl = "https://" & SERVER_NAME & if(SERVER_PORT = "443", "", ":" & SERVER_PORT) - else - rootUrl = "http://" & SERVER_NAME & if(SERVER_PORT = "80", "", ":" & SERVER_PORT) - end if - + ''' Get server information + SERVER_NAME = Request.ServerVariables.GetValues( "SERVER_NAME")(0) + SERVER_PORT = Request.ServerVariables.GetValues( "SERVER_PORT")(0) + HTTPS = Request.ServerVariables.GetValues( "HTTPS")(0) + isHTTPS = if(HTTPS = "ON", true, false ) + + ''' Build foot URL + If isHTTPS Then + rootUrl = "https://" & SERVER_NAME & if(SERVER_PORT = "443", "", ":" & SERVER_PORT) + Else + rootUrl = "http://" & SERVER_NAME & if(SERVER_PORT = "80", "", ":" & SERVER_PORT) + End If + ''' If the url ends with ".html", we just go for it - if Not pageFile.Extension.ToLower() = ".html" Then + If Not pageFile.Extension.ToLower() = ".html" Then ''' Otherwise try adding ".html" - This would be the case for a file in a directory ''' E.g. /docs/installation should really load /docs/installation.html @@ -105,58 +106,58 @@ Protected function preparePage(pageFile As FileInfo, ByRef basename As String, B pageFile = New FileInfo(pageFile.FullName & suffix) ''' test, if file exists - if not pageFile.Exists Then + If not pageFile.Exists Then ''' otherwise it could be a directory, and we look for the "index.html" ''' So test for the directory - if dirInfo.Exists Then - + If dirInfo.Exists Then + ''' If found, assume the default: index.html suffix = "index.html" pageFile = New FileInfo(dirInfo.FullName & "\" & suffix) - - end if - end if + End If - end if + End If + + End If ''' Create helper urls for the bottom of the page gitUrl = gitRootUrl & requestUrl & suffix fileUrl = rgxRemoveIndex.Replace(rootUrl & requestUrl, "$1") nilesoftUrl = rgxRemoveIndex.Replace(nilesoftRoot & requestUrl, "$1") - if pageFile.Exists Then + If pageFile.Exists Then fileModified = File.GetLastWriteTime(pageFile.FullName) - end if + End If extractNames(pageFile.Name, basename, caption) return pageFile -end function +End Function ''' this is called from Default.aspx to actually include the requested content -Protected function includePage(pageFile As FileInfo) As Boolean +Protected Function includePage(pageFile As FileInfo) As Boolean - if Not pageFile.Exists Then + If Not pageFile.Exists Then return false - end if + End If ' Open the stream and read it back. Dim sr As StreamReader = pageFile.OpenText() Response.Write( sr.ReadToEnd() ) sr.Close() - + return true -End function +End Function Protected Function includeImage(imageFile As FileInfo) As Boolean - if not imageFile.Exists Then + If not imageFile.Exists Then Response.Clear() Response.StatusCode = 404 @@ -165,19 +166,19 @@ Protected Function includeImage(imageFile As FileInfo) As Boolean return false - end if + End If - ''' Set the page's content type ... + ''' Set the page's content type ... Select Case imageFile.Extension.ToLower() Case "png" - Response.ContentType = "image/png" + Response.ContentType = "image/png" Case "jpg", "jpeg" - Response.ContentType = "image/jpeg" + Response.ContentType = "image/jpeg" Case Else - Response.ContentType = "application/octet-stream" + Response.ContentType = "application/octet-stream" End Select @@ -186,11 +187,170 @@ Protected Function includeImage(imageFile As FileInfo) As Boolean Response.Flush() return true - + End Function ''' This is used to automagically create the left-side navigation. It's not perfect, but does the job -Protected function PrintNav(ByVal initial As DirectoryInfo) As XElement +Protected Function PrintNav(ByVal initial As DirectoryInfo) As XElement + + ''' create return element + Dim xmlRoot As XElement = + Dim children As IEnumerable(Of XElement) + + Dim menuFile As FileInfo = New FileInfo(initial.FullName & "\menu.json") + + + If menuFile.Exists Then + PrintNavXmlAppendChildren(xmlRoot, PrintNavJson(menuFile)) + Else + PrintNavXmlAppendChildren(xmlRoot, PrintNavFS(initial)) + End If + + return xmlRoot + +End Function + +Protected Function PrintNavXmlMarkActive(ByRef html As XElement, ByVal link As String) As XElement + + ''' If it's the current page, mark it active + If link = "/" & requestUrl Then + html.Descendants("a")(0).Attribute("class").Value = "is-active" + End If + + return html + +End Function + +Protected Function PrintNavXmlCreateDir(ByVal caption As String, ByVal link As String) As XElement + + Dim html As XElement + + ''' Create the html + html = _ +
  • + +
    + + <%= caption %> +
    +
    +
  • + + ''' Update the href attribute + html.Descendants("a")(0).Attribute("href").Value = link + + return PrintNavXmlMarkActive(html, link) + +End Function + +Protected Function PrintNavXmlCreateFile(ByVal caption As String, ByVal link As String) As XElement + + Dim html As XElement + + ''' create the required html + html = _ +
  • + + <%= caption %> + +
  • + + ''' update the href property + html.Descendants("a")(0).Attribute("href").Value = link + + return PrintNavXmlMarkActive(html, link) + +End Function + +Protected Function PrintNavXmlAppendChildren( + ByRef parentNode As XElement, + ByRef childNode As XElement + ) As Long + + Dim children As IEnumerable(Of XElement) + + ''' get files and sub-folders + children = childNode.Elements + + ''' if found any, append them + If children.count() > 0 Then + + parentNode.add(