This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
335b961
commit 3a35af7
Showing
6 changed files
with
135 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Nfdi4Plants.Fornax/CustomParsing/nfdi-sidebar-element.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
namespace Fornax.Nfdi4Plants.CustomParsing | ||
|
||
module SidebarElement = | ||
|
||
open Html | ||
open Fornax.Nfdi4Plants.MarkdigExtensions | ||
|
||
type SidebarElement = { | ||
Title: string | ||
Content: string | ||
} | ||
|
||
let read (productionBasePath: string option) (contentArr: string []) = | ||
contentArr | ||
|> 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 = Markdig.Markdown.ToHtml(c, Pipelines.sidebarMarkdownPipeline(productionBasePath)) | ||
} | ||
) | ||
|> List.rev | ||
|> Array.ofList | ||
|
||
let write (eleArr: SidebarElement []) = | ||
[ | ||
for sidebarEle in eleArr do | ||
yield custom "nfdi-sidebar-element" [HtmlProperties.Custom ("slot", "sidebar"); HtmlProperties.Custom ("isActive","true") ] [ | ||
div [HtmlProperties.Custom ("slot", "title")] [!! sidebarEle.Title] | ||
!! sidebarEle.Content | ||
] | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Fornax.Nfdi4Plants.MarkdigExtensions | ||
|
||
module Pipelines = | ||
|
||
open Markdig | ||
open Fornax.Nfdi4Plants.MarkdigExtensions.NfdiCode | ||
open Fornax.Nfdi4Plants.MarkdigExtensions.NfdiHeader | ||
open Fornax.Nfdi4Plants.MarkdigExtensions.NfdiSidebarElementHeader | ||
|
||
let markdownPipeline = | ||
MarkdownPipelineBuilder() | ||
.UseAdvancedExtensions() | ||
.UseEmojiAndSmiley() | ||
.UseNFDIHeader() | ||
.UseNFDICodeBlock() | ||
.Build() | ||
|
||
let sidebarMarkdownPipeline(productionBasePath: string option) = | ||
if productionBasePath.IsSome then | ||
MarkdownPipelineBuilder() | ||
.UseSidebarHeader(productionBasePath.Value) | ||
.Build() | ||
else | ||
MarkdownPipelineBuilder() | ||
.UseSidebarHeader() | ||
.Build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Fornax.Nfdi4Plants.SubComponents | ||
|
||
open Html | ||
|
||
type PagefindSearchbar = class end | ||
with | ||
static member create (?productionBasePath: string) = | ||
let appendBasePath (url: string) = | ||
let p = Option.defaultValue "" productionBasePath | ||
p.TrimEnd([|'/'; '\\'|]) + url | ||
div [HtmlProperties.Custom("slot","searchbar")] [ | ||
link [Href <| appendBasePath "/_pagefind/pagefind-ui.css"; Rel "stylesheet"] | ||
script [Src <| appendBasePath "/_pagefind/pagefind-ui.js"; Type "text/javascript"] [] | ||
div [Id "search"] [] | ||
script [] [ | ||
!!"""window.addEventListener('DOMContentLoaded', (event) => { | ||
new PagefindUI({ element: "#search" }); | ||
});""" | ||
] | ||
] | ||
|
||
|