() |> Option.map (fun n -> n.disableLiveRefresh) |> Option.defaultValue false
cnt
|> HtmlElement.ToString
|> fun n -> if disableLiveRefresh then n else injectWebsocketCode n
-let docsLayout (docs: Docsloader.Docs) =
+let docsLayout (docs: Docs) =
let publishedDate = docs.published.Value.ToString("yyyy-MM-dd")
let sidebar = [
if Array.isEmpty docs.sidebar |> not then
@@ -144,7 +146,7 @@ let docsLayout (docs: Docsloader.Docs) =
]
]
-let docsMinimalLayout (docs: Docsloader.Docs) =
+let docsMinimalLayout (docs: Docs) =
div [Class "tile is-4 is-parent"] [
div [Class "tile is-child box"] [
p [Class "title"] [ a [Href docs.link] [!! docs.title] ]
diff --git a/src/loaders/docsloader.fsx b/src/loaders/docsloader.fsx
index 76ec8bf..d8188a2 100644
--- a/src/loaders/docsloader.fsx
+++ b/src/loaders/docsloader.fsx
@@ -1,173 +1,12 @@
#r "../_lib/Fornax.Core.dll"
#r "../_lib/Markdig.dll"
-#r @"..\Fornax.Nfdi4Plants\bin\Debug\net5.0\Fornax.Nfdi4Plants.dll"
+#r "../Fornax.Nfdi4Plants/bin/Debug/net5.0/Fornax.Nfdi4Plants.dll"
open System.IO
open Fornax.Nfdi4Plants
-// type DocsConfig = {
-// disableLiveRefresh: bool
-// }
-
-// type SidebarElement = {
-// Title: string
-// Content: string
-// }
-
-// type Docs = {
-// file: string
-// link : string
-// title: string
-// author: string option
-// published: System.DateTime option
-// add_toc: bool
-// sidebar: SidebarElement []
-// content: string
-// }
-
let contentDir = "docs"
-// open ``Nfdi-header-extension``
-// open ``Sidebar-header-extension``
-
-// let markdownPipeline =
-// MarkdownPipelineBuilder()
-// .UseAdvancedExtensions()
-// .UseEmojiAndSmiley()
-// .UseNFDIHeader()
-// .Build()
-
-// let isSeparator (input : string) =
-// input.StartsWith "---"
-
-// let splitKey (line: string) =
-// let seperatorIndex = line.IndexOf(':')
-// if seperatorIndex > 0 then
-// let key = line.[.. seperatorIndex - 1].Trim().ToLower()
-// let value = line.[seperatorIndex + 1 ..].Trim()
-// Some(key, value)
-// else
-// None
-
-// // Parse over line to find area between "---". Parse input, very simple by separating by ":"
-// ///`fileConfig` - Metadata at the top of an .md file
-// let getConfig (fileContent : string) =
-// let fileContent = fileContent.Split '\n'
-// let fileContent = fileContent |> Array.skip 1 //First line must be ---
-// let indexOfSeperator = fileContent |> Array.findIndex isSeparator
-// fileContent
-// |> Array.splitAt indexOfSeperator
-// |> fst
-// |> Seq.choose splitKey
-// |> Map.ofSeq
-
-// let sidebarMarkdownPipeline =
-// MarkdownPipelineBuilder()
-// .UseSidebarHeader()
-// .Build()
-
-// let getSidebar (sidebarPath: string) =
-// let fileContent =
-// let docsPath = Path.Combine(contentDir, sidebarPath)
-// File.ReadAllLines(docsPath)
-// |> Array.skip 1 //First line must be ---
-// let indexOfSeperator = fileContent |> Array.findIndex isSeparator
-// let content =
-// fileContent
-// |> Array.splitAt indexOfSeperator
-// |> snd
-// |> Array.skip 1 // starts with ---
-// let sidebar =
-// content
-// |> List.ofArray
-// |> List.fold (fun acc line ->
-// // opens new sidebar element with title
-// // ` = '\096'
-// if line.Trim() = "```" then
-// acc
-// elif line.StartsWith "```" then
-// // get sidebar element title
-// let title = line.Replace("`", "").Trim()
-// // add to list collection with empty list.
-// // empty list will be used to add all related lines
-// (title, List.empty)::acc
-// elif line.Trim() <> "" then
-// // match with list collection to check if it is empty (should not be empty, this is error prediction)
-// match acc with
-// // if has element, add line to sidebar element
-// | h::t -> (fst h, line::snd h)::t
-// // if is empty add sidebar placeholder
-// | [] -> ("Sidebar", line::[])::acc
-// else
-// acc
-// ) []
-// |> List.map (fun (title, lines) ->
-// let c = lines |> List.rev |> String.concat "\n"
-// {
-// Title = title
-// Content = Markdown.ToHtml(c, sidebarMarkdownPipeline)
-// }
-// )
-// |> List.rev
-// |> Array.ofList
-// sidebar
-
-// ///`fileContent` - content of page to parse. Usually whole content of `.md` file
-// ///returns HTML version of content of the page
-// let getContent (fileContent : string) =
-// let fileContent = fileContent.Split '\n'
-// let fileContent = fileContent |> Array.skip 1 //First line must be ---
-// let indexOfSeperator = fileContent |> Array.findIndex isSeparator
-// let content =
-// fileContent
-// |> Array.splitAt indexOfSeperator
-// |> snd
-// |> Array.skip 1 // starts with ---
-// |> String.concat "\n"
-
-// Markdown.ToHtml(content, markdownPipeline)
-
-// let trimString (str : string) =
-// str.Trim().TrimEnd('"').TrimStart('"')
-
-// let loadFile (rootDir: string) (filePath: string) =
-// let text = File.ReadAllText filePath
-
-// let config = getConfig text
-
-// let title = config |> Map.find "title" |> trimString
-// let author = config |> Map.tryFind "author" |> Option.map trimString
-// let published = config |> Map.tryFind "published" |> Option.map (trimString >> System.DateTime.Parse)
-// let addToc = config |> Map.tryFind "add toc" |> Option.map (trimString >> System.Boolean.Parse) |> Option.defaultValue true
-// let addSidebar =
-// let docsPath = Path.Combine(rootDir, contentDir)
-// config |> Map.tryFind "add sidebar" |> Option.map (trimString >> fun x -> Path.Combine(docsPath, x.Replace('\\','/')))
-
-// let content = getContent text
-// let sidebar = addSidebar |> Option.map getSidebar
-// let chopLength =
-// if rootDir.EndsWith(Path.DirectorySeparatorChar) then rootDir.Length
-// else rootDir.Length + 1
-
-// let dirPart =
-// filePath
-// |> Path.GetDirectoryName
-// |> fun x -> x.[chopLength .. ]
-
-// let file = Path.Combine(dirPart, (filePath |> Path.GetFileNameWithoutExtension) + ".md").Replace("\\", "/")
-// let link = "/" + Path.Combine(dirPart, (filePath |> Path.GetFileNameWithoutExtension) + ".html").Replace("\\", "/")
-
-// { file = file
-// link = link
-// title = title
-// author = author
-// published = published
-// content = content
-// add_toc = addToc
-// sidebar = if sidebar.IsSome then sidebar.Value else [||] }
-
-open Types
-
let loader (projectRoot: string) (siteContent: SiteContents) =
let docsPath = Path.Combine(projectRoot, contentDir)
// let options = EnumerationOptions(RecurseSubdirectories = true)
@@ -176,9 +15,11 @@ let loader (projectRoot: string) (siteContent: SiteContents) =
Directory.GetFiles(docsPath, "*")
|> Array.filter (fun n -> n.EndsWith ".md")
|> Array.filter (fun n -> n.Contains "README.md" |> not)
+ printfn "HIER: %i" files.Length
let docs =
files
|> Array.map (loadFile projectRoot)
+ printfn "HIER2: %i" docs.Length
docs
|> Array.iter siteContent.Add
diff --git a/src/loaders/nfdi-header-extension.fsx b/src/loaders/nfdi-header-extension.fsx
deleted file mode 100644
index 9f93b17..0000000
--- a/src/loaders/nfdi-header-extension.fsx
+++ /dev/null
@@ -1,113 +0,0 @@
-#r "nuget: Expecto, 9.0.4"
-#r "../_lib/Markdig.dll"
-
-// https://odetocode.com/blogs/scott/archive/2020/01/23/a-custom-renderer-extension-for-markdig.aspx
-// https://github.com/arthurrump/MarkdigExtensions/blob/master/src/MarkdigExtensions.ImageAsFigure/ImageAsFigure.fs
-
-open Markdig.Renderers
-open Markdig
-open Markdig.Renderers.Html
-open Markdig.Syntax
-
-open System
-
-type NFDIHeaderRenderer() =
- inherit HeadingRenderer()
-
- override __.Write(renderer : HtmlRenderer, hb : HeadingBlock ) =
-
- let headingTexts = [|
- "nfdi-h1";
- "nfdi-h2";
- "nfdi-h3";
- "nfdi-h4";
- "nfdi-h5";
- "nfdi-h6";
- |]
- let index = hb.Level - 1
- let headingText =
- if index < headingTexts.Length then
- headingTexts[index]
- else
- // this cannot hit, as any heading with level > 6 will not be rendered as heading, but as
- headingTexts.[headingTexts.Length-1]
-
- if (renderer.EnableHtmlForBlock) then
- renderer.Write('<') |> ignore
- renderer.Write(headingText) |> ignore
- renderer.WriteAttributes(hb) |> ignore
- renderer.Write('>') |> ignore
-
- // renderer.WriteLeafRawLines(hb, true, true, true) |> ignore
- renderer.WriteLeafInline(hb) |> ignore
-
- if (renderer.EnableHtmlForBlock) then
- renderer.Write("") |> ignore
- renderer.Write(headingText) |> ignore
- renderer.WriteLine(">") |> ignore
-
- renderer.EnsureLine() |> ignore
-
-///
-type NFDIHeaderExtension() =
-
- interface IMarkdownExtension with
-
- member __.Setup(_) = ()
-
- member __.Setup(_, renderer) =
- renderer.ObjectRenderers.ReplaceOrAdd(new NFDIHeaderRenderer()) |> ignore
-
-open System.Runtime.CompilerServices
-
-[]
-type MarkdownPipelineBuilderExtensions() =
- []
- // Highlight code in fenced code blocks
- // The Markdig to add the extension to
- static member UseNFDIHeader(pipeline : MarkdownPipelineBuilder) =
- pipeline.Extensions.Add(NFDIHeaderExtension())
- pipeline
-
-// let markdown = """
-// # Start testing!
-
-// This is a text with some *emphasis* :tada:
-
-// ![Test](https://upload.wikimedia.org/wikipedia/en/9/95/Test_image.jpg)
-// """
-
-// let result = Markdown.ToHtml(markdown, pipeline)
-// result
-
-
-module Testing =
- open Expecto
-
- let pipeline =
- let builder = new MarkdownPipelineBuilder()
- builder
- .UseAdvancedExtensions()
- .UseEmojiAndSmiley()
- .UseNFDIHeader()
- .Build()
-
- []
- let tests =
- testList "UseNFDIHeader" [
- test "basic case" {
- let markdown = """# Start testing!"""
- let result = Markdown.ToHtml(markdown, pipeline)
- Expect.equal result $"""Start testing!{'\010'}""" ""
- }
- test "5 depth case" {
- let markdown = """##### Start testing!"""
- let result = Markdown.ToHtml(markdown, pipeline)
- Expect.equal result $"""Start testing!{'\010'}""" ""
- }
- test "6 depth case" {
- let markdown = """###### Start testing!"""
- let result = Markdown.ToHtml(markdown, pipeline)
- Expect.equal result $"""Start testing!{'\010'}""" ""
- }
- ]
\ No newline at end of file
diff --git a/src/loaders/runTests.fsx b/src/loaders/runTests.fsx
deleted file mode 100644
index fa8ac31..0000000
--- a/src/loaders/runTests.fsx
+++ /dev/null
@@ -1,16 +0,0 @@
-#r "nuget: Expecto, 9.0.4"
-#load "nfdi-header-extension.fsx"
-#load "sidebar-header-extension.fsx"
-
-// put this into separate .fsx file to not run tests everytime file is referenced
-
-open Expecto
-open ``Nfdi-header-extension``
-open ``Sidebar-header-extension``
-
-let allTests = testList "" [
- ``Nfdi-header-extension``.Testing.tests
- ``Sidebar-header-extension``.Testing.tests
-]
-
-runTestsWithCLIArgs [] [||] allTests
diff --git a/src/loaders/sidebar-header-extension.fsx b/src/loaders/sidebar-header-extension.fsx
deleted file mode 100644
index 14d68de..0000000
--- a/src/loaders/sidebar-header-extension.fsx
+++ /dev/null
@@ -1,124 +0,0 @@
-#r "nuget: Expecto, 9.0.4"
-#r "../_lib/Markdig.dll"
-
-// https://odetocode.com/blogs/scott/archive/2020/01/23/a-custom-renderer-extension-for-markdig.aspx
-// https://github.com/arthurrump/MarkdigExtensions/blob/master/src/MarkdigExtensions.ImageAsFigure/ImageAsFigure.fs
-
-open Markdig.Renderers
-open Markdig
-open Markdig.Renderers.Html
-open Markdig.Syntax
-
-open System
-
-let private splitKey (line: string) =
- let seperatorIndex = line.IndexOf(':')
- if seperatorIndex > 0 then
- let key = line.[.. seperatorIndex - 1].Trim()
- let value = line.[seperatorIndex + 1 ..].Trim()
- key, Some value
- else
- line, None
-
-type SidebarHeaderRenderer() =
- inherit HeadingRenderer()
-
- override __.Write(renderer : HtmlRenderer, hb : HeadingBlock ) =
-
- let headingTexts = [|
- "h1";
- "h2";
- "h3";
- // "nfdi-h4";
- // "nfdi-h5";
- // "nfdi-h6";
- |]
- let index = hb.Level - 1
- let headingText =
- if index < headingTexts.Length then
- headingTexts[index]
- else
- headingTexts.[headingTexts.Length-1]
- let innerText, href =
- let s = String.concat "" [for i in hb.Inline do yield i.ToString()]
- splitKey s
-
- let attr = hb.GetAttributes()
- attr.AddProperty("slot", "inner")
- if href.IsSome then attr.AddProperty("href", href.Value)
-
- if (renderer.EnableHtmlForBlock) then
- renderer.Write('<') |> ignore
- renderer.Write(headingText) |> ignore
- renderer.WriteAttributes(hb) |> ignore
- renderer.Write('>') |> ignore
-
- renderer.Write(innerText) |> ignore
-
- if (renderer.EnableHtmlForBlock) then
- renderer.Write("") |> ignore
- renderer.Write(headingText) |> ignore
- renderer.WriteLine(">") |> ignore
-
- renderer.EnsureLine() |> ignore
-
-/// An extension for Markdig that highlights syntax in fenced code blocks
-type SidebarHeaderExtension() =
-
- interface IMarkdownExtension with
-
- member __.Setup(_) = ()
-
- member __.Setup(_, renderer) =
- renderer.ObjectRenderers.ReplaceOrAdd(new SidebarHeaderRenderer()) |> ignore
-
-open System.Runtime.CompilerServices
-
-[]
-type MarkdownPipelineBuilderExtensions() =
- []
- // Highlight code in fenced code blocks
- // The Markdig to add the extension to
- static member UseSidebarHeader(pipeline : MarkdownPipelineBuilder) =
- pipeline.Extensions.Add(SidebarHeaderExtension())
- pipeline
-
-// let pipeline =
-// let builder = new MarkdownPipelineBuilder()
-// builder
-// .UseSidebarHeader()
-// .Build()
-
-// let markdown = """# Start testing!:#start-testing"""
-// let result = Markdown.ToHtml(markdown, pipeline)
-// printfn "Result! %A" result
-
-
-module Testing =
- open Expecto
-
- let pipeline =
- let builder = new MarkdownPipelineBuilder()
- builder
- .UseSidebarHeader()
- .Build()
-
- []
- let tests =
- testList "UseSidebarHeader" [
- test "basic case" {
- let markdown = """# Start testing!:#start-testing"""
- let result = Markdown.ToHtml(markdown, pipeline)
- Expect.equal result $"""Start testing!
{'\010'}""" ""
- }
- test "base case without link" {
- let markdown = """# Start testing!"""
- let result = Markdown.ToHtml(markdown, pipeline)
- Expect.equal result $"""Start testing!
{'\010'}""" ""
- }
- test "6 depth case" {
- let markdown = """###### Start testing!"""
- let result = Markdown.ToHtml(markdown, pipeline)
- Expect.equal result $"""Start testing!
{'\010'}""" ""
- }
- ]
\ No newline at end of file