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

Commit

Permalink
Implement sidebar-eleneo parsing ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed May 16, 2023
1 parent 63eae69 commit a1dff67
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 110 deletions.
34 changes: 18 additions & 16 deletions client/docs/_sidebars/mainSidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ To-Dos:
- Update links to other KB articles
---

```Metadata
# Metadata:/docs/metadata.html
## What is metadata?:/docs/metadata.html#what-is-metadata
## Where does metadata come from?:/docs/metadata.html#where-does-metadata-come-from
## Why do I benefit from metadata?:/docs/metadata.html#why-do-i-benefit-from-metadata
## What tasks are important for rich metadata?:/docs/metadata.html#what-tasks-are-important-for-rich-metadata
### Collection:/docs/metadata.html#collection
### Structuring:/docs/metadata.html#structuring
### Sharing and curation:/docs/metadata.html#sharing-and-curation
## How does DataPLANT support me in metadata annotation:/docs/metadata.html#how-does-dataplant-support-me-in-metadata-annotation
## DataPLANT Support:/docs/metadata.html#dataplant-support
```

```Fornax Testing Example
# Code Examples:/docs/CodeExamples.html
```
# [Metadata](/docs/metadata.html)
## [What is metadata?](/docs/metadata.html#what-is-metadata)
## [Where does metadata come from?](/docs/metadata.html#where-does-metadata-come-from)
## [Why do I benefit from metadata?](/docs/metadata.html#why-do-i-benefit-from-metadata)
## [What tasks are important for rich metadata?](/docs/metadata.html#what-tasks-are-important-for-rich-metadata)
### [Collection](/docs/metadata.html#collection)
### [Structuring](/docs/metadata.html#structuring)
### [Sharing and curation](/docs/metadata.html#sharing-and-curation)
## [How does DataPLANT support me in metadata annotation](/docs/metadata.html#how-does-dataplant-support-me-in-metadata-annotation)
## [DataPLANT Support](/docs/metadata.html#dataplant-support)
# [Test 1](/path/any)
# [Test 1](/path/any)
## [Test 2](/path/any)
## [Test 2](/path/any)
## [Test 2](/path/any)
### [Test 3](/path/any)
#### [Test 4](/path/any)
##### [Test 5](/path/any)
2 changes: 2 additions & 0 deletions client/docs/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ for f in *.md; do pandoc -s -o "${f%.md}.docx" "$f"; done

This file is used to test sidebar in-page navigation. All links are possibly not working.

<kbd>Test</kbd>

## What is metadata?

Metadata is "data that provides information about other data"[^1][Merriam]. In order to put some (plant) life into this web dictionary explanation, let us explore metadata with a plant biology example:
Expand Down
155 changes: 87 additions & 68 deletions client/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,91 @@ html,body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
font-size: 14px;
background: #F0F2F4;
}
.navbar.is-white {
background: #F0F2F4;
}
.navbar-brand .brand-text {
font-size: 1.11rem;
font-weight: bold;
}
.hero-body
{background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Plum_trees_Kitano_Tenmangu.jpg/1200px-Plum_trees_Kitano_Tenmangu.jpg);
background-position: center;
background-size: cover;
background-repeat: no-repeat;
height: 500px;
}
.articles {
margin: 5rem 0;
margin-top: -200px;
}
.articles .content p {
line-height: 1.9;
margin: 15px 0;
}
.author-image {
position: absolute;
top: -30px;
left: 50%;
width: 60px;
height: 60px;
margin-left: -30px;
border: 3px solid #ccc;
border-radius: 50%;
}
.media-center {
display: block;
margin-bottom: 1rem;
}
.media-content {
margin-top: 3rem;
}
.article, .promo-block {
margin-top: 6rem;
}
div.column.is-8:first-child {
padding-top: 0;
margin-top: 0;
}
.article-title {
font-size: 2rem;
font-weight: lighter;
line-height: 2;
}
.article-subtitle {
color: #909AA0;
margin-bottom: 3rem;
}
.article-body {
};
.navbar.is-white {
background: #F0F2F4;
};
.navbar-brand .brand-text {
font-size: 1.11rem;
font-weight: bold;
};
.hero-body{
background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Plum_trees_Kitano_Tenmangu.jpg/1200px-Plum_trees_Kitano_Tenmangu.jpg);
background-position: center;
background-size: cover;
background-repeat: no-repeat;
height: 500px;
};
.articles {
margin: 5rem 0;
margin-top: -200px;
}
.articles .content p {
line-height: 1.9;
margin: 15px 0;
}
.author-image {
position: absolute;
top: -30px;
left: 50%;
width: 60px;
height: 60px;
margin-left: -30px;
border: 3px solid #ccc;
border-radius: 50%;
}
.media-center {
display: block;
margin-bottom: 1rem;
}
.media-content {
margin-top: 3rem;
}
.article, .promo-block {
margin-top: 6rem;
}
div.column.is-8:first-child {
padding-top: 0;
margin-top: 0;
}
.article-title {
font-size: 2rem;
font-weight: lighter;
line-height: 2;
}
.article-subtitle {
color: #909AA0;
margin-bottom: 3rem;
}
.article-body {
line-height: 1.4;
margin: 0 6rem;
}
@media screen and (max-width: 991px) {
.article-body {
line-height: 1.4;
margin: 0 6rem;
}
@media screen and (max-width: 991px) {
.article-body {
line-height: 1.4;
margin: 0;
}
}
.promo-block .container {
margin: 1rem 5rem;
}
margin: 0;
}
}
.promo-block .container {
margin: 1rem 5rem;
}
kbd {
padding: 0.1em 0.6em 0.1em 0.4em;
border:1px solid #ccc;
font-size:11px;
font-family:Arial,Helvetica,sans-serif;
background-color:#f7f7f7;
color:#333;
-moz-box-shadow:0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;
-webkit-box-shadow:0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;
box-shadow:0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
display:inline-block;
margin:0 0.1em;
text-shadow:0 1px 0 #fff;
line-height:1.4;
white-space:nowrap;
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"homepage": "https://github.com/Freymaurer/nfdi4plants-fornax-template#readme",
"dependencies": {
"@nfdi4plants/web-components": "^0.12.0",
"@nfdi4plants/web-components": "^1.0.0",
"bulma": "^0.9.2"
},
"devDependencies": {
Expand Down
102 changes: 102 additions & 0 deletions src/Nfdi4Plants.Fornax/CustomParsing/nfdi-sidebar-eleneo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
namespace Fornax.Nfdi4Plants.CustomParsing

module SidebarEleneo =

open System.Text.RegularExpressions

type SidebarEleneo = {
Main: string
Children: SidebarEleneo list
} with
static member markdownLinkPattern = @"^\[(?<innerhtml>.*)\]\((?<href>.*)\)"
member this.mainToLink =
let pre_content = this.Main.TrimStart([|'#'|]).Trim()
let regex = Regex.Match(pre_content, SidebarEleneo.markdownLinkPattern)
{|innerHtml = regex.Groups.["innerhtml"].Value; href = regex.Groups.["href"].Value|}
static member create(main: string, ?children) = {
Main = main
Children = Option.defaultValue [] children
}

module HelperRead =
type SortingType = {
Hashcount: int
Content: string
Children: SortingType list
} with
static member create (count, c, ?children) = {
Hashcount = count
Content = c
Children = Option.defaultValue [] children
}

let inline splitSeq (array: seq<'T>) (predicate: 'T -> bool) =
array
|> Seq.fold (fun (current, result) ele ->
let isNew = predicate ele
match current, isNew with
| [], true ->
[ele], result
| _, true ->
[ele], (List.rev current)::result
| _, false ->
ele::current, result
) ([],[])
|> fun (current, result) -> (List.rev current)::result
|> List.rev

let sortMarkdown (contentArr: string []) =
let countHashes (str: string) = str |> Seq.takeWhile ((=) '#') |> Seq.length
let prepare = contentArr |> Array.map (fun x -> SortingType.create(countHashes x, x)) |> List.ofArray
let rec sort (inp: SortingType list) =
let nextLowestLevel = inp |> List.minBy (fun st -> st.Hashcount) |> fun x -> x.Hashcount
let subElements = splitSeq inp (fun x -> x.Hashcount = nextLowestLevel)
subElements
|> List.map (fun sublist ->
match sublist with
| head::[] ->
// printfn "[INDEX %i] Hit no child" index
SidebarEleneo.create(head.Content)
| head::tail ->
// printfn "[INDEX %i] %A" index (List.map (fun x -> x.Content) tail)
let children = sort tail
SidebarEleneo.create(head.Content, children)
| [] -> failwith "Should never return empty list."
)
sort prepare


module HelperWrite =

open Html

let rec sidebarEleneoToHtml (isRoot:bool) (ele:SidebarEleneo) =
let linkInfo = ele.mainToLink
let hasChildren = List.isEmpty ele.Children |> not
// not root and no children
let link =
a [
if ((not hasChildren) && (not isRoot)) then HtmlProperties.Custom ("slot", "child")
Href linkInfo.href
] [
!!linkInfo.innerHtml
]
// root must always be sidebar-eleneo element.
if hasChildren || isRoot then
custom "nfdi-sidebar-eleneo" [
if isRoot then HtmlProperties.Custom ("slot", "sidebar") else HtmlProperties.Custom ("slot", "child")
] [
link
yield! ele.Children |> List.map (fun x -> sidebarEleneoToHtml false x)
]
else
link

let read (content: string []) =
content
|> HelperRead.sortMarkdown

let write (isRoot:bool) (ele:SidebarEleneo) =
HelperWrite.sidebarEleneoToHtml isRoot ele


3 changes: 2 additions & 1 deletion src/Nfdi4Plants.Fornax/Nfdi4Plants.Fornax.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="CustomParsing\nfdi-sidebar-eleneo.fs" />
<Compile Include="MarkdigExtensions/nfdi-code.fs" />
<Compile Include="MarkdigExtensions/nfdi-header.fs" />
<Compile Include="MarkdigExtensions/nfdi-sidebar-element-header.fs" />
Expand All @@ -38,6 +39,6 @@
<Pack>true</Pack>
<PackagePath>lib\$(TargetFramework)</PackagePath>
</Content>
<None Include="../../LICENSE" Pack="true" PackagePath=""/>
<None Include="../../LICENSE" Pack="true" PackagePath="" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion tests/Nfdi4Plants.Fornax.Tests/Loaders.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ open Fornax.Nfdi4Plants

open Aux

[<Tests>]
let getConfigTests =
testList "getConfig" [
// Test whitespace after first separator
Expand Down
Loading

0 comments on commit a1dff67

Please sign in to comment.