diff --git a/build/Build.fs b/build/Build.fs index 481a645..fe1e737 100644 --- a/build/Build.fs +++ b/build/Build.fs @@ -16,20 +16,22 @@ open TestTasks open PackageTasks open ReleaseTasks open ReleaseNotesTasks +open FornaxTasks /// Referenced here to make ReleaseNotesTasks accessible. let _ = updateReleaseNotes +let _ = watchFornax /// Full release of nuget package for the prerelease version. let _release = BuildTask.createEmpty - "ReleaseNoDocs" + "Release" [clean; build; runTests; pack; createTag; publishNuget;] /// Full release of nuget package for the prerelease version. let _preRelease = BuildTask.createEmpty - "PreReleaseNoDocs" + "PreRelease" [setPrereleaseTag; clean; build; runTests; packPrerelease; createPrereleaseTag; publishNugetPrerelease] diff --git a/build/FornaxTasks.fs b/build/FornaxTasks.fs new file mode 100644 index 0000000..3b2c659 --- /dev/null +++ b/build/FornaxTasks.fs @@ -0,0 +1,9 @@ +module FornaxTasks + +open BlackFox.Fake +open Helpers + +let watchFornax = BuildTask.create "fornax" [] { + runDotNet "dotnet build" "src/Fornax.Nfdi4Plants" + runDotNet "fornax watch" "src" +} diff --git a/build/build.fsproj b/build/build.fsproj index 3943ef2..2fad79f 100644 --- a/build/build.fsproj +++ b/build/build.fsproj @@ -9,6 +9,7 @@ + diff --git a/src/Fornax.Nfdi4Plants/Fornax.Nfdi4Plants.fsproj b/src/Fornax.Nfdi4Plants/Fornax.Nfdi4Plants.fsproj index 5c8a00e..116a70d 100644 --- a/src/Fornax.Nfdi4Plants/Fornax.Nfdi4Plants.fsproj +++ b/src/Fornax.Nfdi4Plants/Fornax.Nfdi4Plants.fsproj @@ -5,7 +5,7 @@ Fornax.Nfdi4Plants Loaders, web-component integration and general structures for the Nfdi4Plants documentation - https://raw.githubusercontent.com/nfdi4plants/Branding/138420e3b6f9ec9e125c1ca8840874b2be2a1262/logos/DataPLANT_logo_minimal_rounded_bg_transparent.svg + https://raw.githubusercontent.com/nfdi4plants/Branding/138420e3b6f9ec9e125c1ca8840874b2be2a1262/logos/DataPLANT_logo_minimal_rounded_bg_transparent.svg https://github.com/Freymaurer/nfdi4plants-fornax-template git diff --git a/src/Fornax.Nfdi4Plants/Loaders.fs b/src/Fornax.Nfdi4Plants/Loaders.fs index 3129079..d20b722 100644 --- a/src/Fornax.Nfdi4Plants/Loaders.fs +++ b/src/Fornax.Nfdi4Plants/Loaders.fs @@ -18,28 +18,26 @@ module Pipelines = .UseSidebarHeader() .Build() -[] -module Types = - - 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 - } + +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 +} module internal Aux = @@ -68,7 +66,6 @@ module internal Aux = |> Map.ofSeq open System.IO - open Types /// Read sidebar markdown file at `sidebarPath` to and parse it nfdi-sidebar-element's. /// Name of the subfolder in which the docs files are. @@ -140,8 +137,7 @@ module internal Aux = module Docs = open System.IO - open Types - + /// Parse markdown `fileContent` to HTML with markdig and custom nfdi-webcomponent converter. /// Base root directory path, will be appended to 'contentDir'. /// Folder which to search for docs .md files. This folder will be used a relative root for sidebars. diff --git a/src/generators/docs.fsx b/src/generators/docs.fsx index a27d726..bec2322 100644 --- a/src/generators/docs.fsx +++ b/src/generators/docs.fsx @@ -2,10 +2,11 @@ #load "layout.fsx" open Html +open Fornax.Nfdi4Plants let generate' (ctx : SiteContents) (page: string) = let doc = - ctx.TryGetValues () + ctx.TryGetValues () |> Option.defaultValue Seq.empty |> Seq.find (fun n -> n.file = page) diff --git a/src/generators/index.fsx b/src/generators/index.fsx index f637a5b..fafbf97 100644 --- a/src/generators/index.fsx +++ b/src/generators/index.fsx @@ -2,10 +2,11 @@ #load "layout.fsx" open Html +open Fornax.Nfdi4Plants let generate' (ctx : SiteContents) (_: string) = - let docs0 = ctx.TryGetValues () |> Option.defaultValue Seq.empty - + let docs0 = ctx.TryGetValues () |> Option.defaultValue Seq.empty + printfn "hier3: %i" <| Seq.length docs0 // let layoutForMinimalDocsAncestor (docsLists: seq list) = // Layout.layout ctx "Home" [ // section [Class "section"] [ @@ -29,7 +30,7 @@ let generate' (ctx : SiteContents) (_: string) = // |> layoutForMinimalDocsAncestor // |> Layout.render ctx - let landingPage = docs0 |> Seq.tryFind(fun x -> x.title = "Index") + let landingPage = docs0 |> Seq.tryFind(fun x -> x.title = "Index" || x.title = "Home") match landingPage with | Some docs -> Layout.layout ctx docs.title [ diff --git a/src/generators/layout.fsx b/src/generators/layout.fsx index 12f5a47..1f38bde 100644 --- a/src/generators/layout.fsx +++ b/src/generators/layout.fsx @@ -97,14 +97,16 @@ let layout (ctx : SiteContents) (activePageTitle: string) bodyCnt = custom "nfdi-footer" [] [] ] +open Fornax.Nfdi4Plants + let render (ctx : SiteContents) cnt = - let disableLiveRefresh = ctx.TryGetValue () |> Option.map (fun n -> n.disableLiveRefresh) |> Option.defaultValue false + let disableLiveRefresh = ctx.TryGetValue () |> 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