Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
try set up to use .fsproj in fornax
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Jun 13, 2022
1 parent 04c3d97 commit 240ed47
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 450 deletions.
6 changes: 4 additions & 2 deletions build/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down
9 changes: 9 additions & 0 deletions build/FornaxTasks.fs
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions build/build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Compile Include="Helpers.fs" />
<Compile Include="MessagePrompts.fs" />
<Compile Include="ProjectInfo.fs" />
<Compile Include="FornaxTasks.fs" />
<Compile Include="ReleaseNotesTasks.fs" />
<Compile Include="BasicTasks.fs" />
<Compile Include="TestTasks.fs" />
Expand Down
2 changes: 1 addition & 1 deletion src/Fornax.Nfdi4Plants/Fornax.Nfdi4Plants.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>Fornax.Nfdi4Plants</Title>
<Description>Loaders, web-component integration and general structures for the Nfdi4Plants documentation</Description>
<!-- <PackageLicenseExpression>MIT</PackageLicenseExpression> -->
<PackageIconUrl>https://raw.githubusercontent.com/nfdi4plants/Branding/138420e3b6f9ec9e125c1ca8840874b2be2a1262/logos/DataPLANT_logo_minimal_rounded_bg_transparent.svg</PackageIconUrl>
<Icon>https://raw.githubusercontent.com/nfdi4plants/Branding/138420e3b6f9ec9e125c1ca8840874b2be2a1262/logos/DataPLANT_logo_minimal_rounded_bg_transparent.svg</Icon>
<PackageTags></PackageTags>
<RepositoryUrl>https://github.com/Freymaurer/nfdi4plants-fornax-template</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
46 changes: 21 additions & 25 deletions src/Fornax.Nfdi4Plants/Loaders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,26 @@ module Pipelines =
.UseSidebarHeader()
.Build()

[<AutoOpen>]
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 =

Expand Down Expand Up @@ -68,7 +66,6 @@ module internal Aux =
|> Map.ofSeq

open System.IO
open Types

/// <summary>Read sidebar markdown file at `sidebarPath` to and parse it nfdi-sidebar-element's.</summary>
/// <param name="contentDir">Name of the subfolder in which the docs files are.</param>
Expand Down Expand Up @@ -140,8 +137,7 @@ module internal Aux =
module Docs =

open System.IO
open Types


/// <summary>Parse markdown `fileContent` to HTML with markdig and custom nfdi-webcomponent converter.</summary>
/// <param name="rootDir">Base root directory path, will be appended to 'contentDir'.</param>
/// <param name="contentDir">Folder which to search for docs .md files. This folder will be used a relative root for sidebars.</param>
Expand Down
3 changes: 2 additions & 1 deletion src/generators/docs.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#load "layout.fsx"

open Html
open Fornax.Nfdi4Plants

let generate' (ctx : SiteContents) (page: string) =
let doc =
ctx.TryGetValues<Docsloader.Docs> ()
ctx.TryGetValues<Docs> ()
|> Option.defaultValue Seq.empty
|> Seq.find (fun n -> n.file = page)

Expand Down
7 changes: 4 additions & 3 deletions src/generators/index.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#load "layout.fsx"

open Html
open Fornax.Nfdi4Plants

let generate' (ctx : SiteContents) (_: string) =
let docs0 = ctx.TryGetValues<Docsloader.Docs> () |> Option.defaultValue Seq.empty

let docs0 = ctx.TryGetValues<Docs> () |> Option.defaultValue Seq.empty
printfn "hier3: %i" <| Seq.length docs0
// let layoutForMinimalDocsAncestor (docsLists: seq<HtmlElement> list) =
// Layout.layout ctx "Home" [
// section [Class "section"] [
Expand All @@ -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 [
Expand Down
8 changes: 5 additions & 3 deletions src/generators/layout.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Docsloader.DocsConfig> () |> Option.map (fun n -> n.disableLiveRefresh) |> Option.defaultValue false
let disableLiveRefresh = ctx.TryGetValue<DocsConfig> () |> 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
Expand Down Expand Up @@ -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] ]
Expand Down
165 changes: 3 additions & 162 deletions src/loaders/docsloader.fsx
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down
Loading

0 comments on commit 240ed47

Please sign in to comment.