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

Commit

Permalink
Init fornax 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed May 6, 2022
1 parent 6f16a43 commit 65ad6f6
Show file tree
Hide file tree
Showing 27 changed files with 694 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"fornax": {
"version": "0.14.1",
"commands": [
"fornax"
]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
src/_public
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# nfdi4plants-fornax-template

This fornax template implements the existing [nfdi-web-components](https://github.com/nfdi4plants/web-components) for **documentation**.
Binary file added src/_lib/Fornax.Core.dll
Binary file not shown.
Binary file added src/_lib/Markdig.dll
Binary file not shown.
43 changes: 43 additions & 0 deletions src/config.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#r "_lib/Fornax.Core.dll"

open Config
open System.IO

let postPredicate (projectRoot: string, page: string) =
let fileName = Path.Combine(projectRoot,page)
let ext = Path.GetExtension page
if ext = ".md" then
let ctn = File.ReadAllText fileName
page.Contains("_public") |> not
&& ctn.Contains("layout: post")
else
false

let staticPredicate (projectRoot: string, page: string) =
let ext = Path.GetExtension page
let fileShouldBeExcluded =
ext = ".fsx" ||
ext = ".md" ||
page.Contains "_public" ||
page.Contains "_bin" ||
page.Contains "_lib" ||
page.Contains "_data" ||
page.Contains "_settings" ||
page.Contains "_config.yml" ||
page.Contains ".sass-cache" ||
page.Contains ".git" ||
page.Contains ".ionide"
fileShouldBeExcluded |> not


let config = {
Generators = [
{Script = "less.fsx"; Trigger = OnFileExt ".less"; OutputFile = ChangeExtension "css" }
{Script = "sass.fsx"; Trigger = OnFileExt ".scss"; OutputFile = ChangeExtension "css" }
{Script = "post.fsx"; Trigger = OnFilePredicate postPredicate; OutputFile = ChangeExtension "html" }
{Script = "staticfile.fsx"; Trigger = OnFilePredicate staticPredicate; OutputFile = SameFileName }
{Script = "index.fsx"; Trigger = Once; OutputFile = MultipleFiles id }
{Script = "about.fsx"; Trigger = Once; OutputFile = NewFileName "about.html" }
{Script = "contact.fsx"; Trigger = Once; OutputFile = NewFileName "contact.html" }
]
}
40 changes: 40 additions & 0 deletions src/generators/about.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#r "../_lib/Fornax.Core.dll"
#load "layout.fsx"

open Html

let about = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi nisi diam, vehicula quis blandit id, suscipit sed libero. Proin at diam dolor. In hac habitasse platea dictumst. Donec quis dui vitae quam eleifend dignissim non sed libero. In hac habitasse platea dictumst. In ullamcorper mollis risus, a vulputate quam accumsan at. Donec sed felis sodales, blandit orci id, vulputate orci."

let generate' (ctx : SiteContents) (_: string) =
let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo> ()
let desc =
siteInfo
|> Option.map (fun si -> si.description)
|> Option.defaultValue ""


Layout.layout ctx "About" [
section [Class "hero is-info is-medium is-bold"] [
div [Class "hero-body"] [
div [Class "container has-text-centered"] [
h1 [Class "title"] [!!desc]
]
]
]
div [Class "container"] [
section [Class "articles"] [
div [Class "column is-8 is-offset-2"] [
div [Class "card article"] [
div [Class "card-content"] [
div [Class "content article-body"] [
!! about
]
]
]
]
]
]]

let generate (ctx : SiteContents) (projectRoot: string) (page: string) =
generate' ctx page
|> Layout.render ctx
40 changes: 40 additions & 0 deletions src/generators/contact.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#r "../_lib/Fornax.Core.dll"
#load "layout.fsx"

open Html

let about = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi nisi diam, vehicula quis blandit id, suscipit sed libero. Proin at diam dolor. In hac habitasse platea dictumst. Donec quis dui vitae quam eleifend dignissim non sed libero. In hac habitasse platea dictumst. In ullamcorper mollis risus, a vulputate quam accumsan at. Donec sed felis sodales, blandit orci id, vulputate orci."

let generate' (ctx : SiteContents) (_: string) =
let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo> ()
let desc =
siteInfo
|> Option.map (fun si -> si.description)
|> Option.defaultValue ""


Layout.layout ctx "Home" [
section [Class "hero is-info is-medium is-bold"] [
div [Class "hero-body"] [
div [Class "container has-text-centered"] [
h1 [Class "title"] [!!desc]
]
]
]
div [Class "container"] [
section [Class "articles"] [
div [Class "column is-8 is-offset-2"] [
div [Class "card article"] [
div [Class "card-content"] [
div [Class "content article-body"] [
!! about
]
]
]
]
]
]]

let generate (ctx : SiteContents) (projectRoot: string) (page: string) =
generate' ctx page
|> Layout.render ctx
67 changes: 67 additions & 0 deletions src/generators/index.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#r "../_lib/Fornax.Core.dll"
#load "layout.fsx"

open Html

let generate' (ctx : SiteContents) (_: string) =
let posts = ctx.TryGetValues<Postloader.Post> () |> Option.defaultValue Seq.empty
let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo> ()
let desc, postPageSize =
siteInfo
|> Option.map (fun si -> si.description, si.postPageSize)
|> Option.defaultValue ("", 10)


let psts =
posts
|> Seq.sortByDescending Layout.published
|> Seq.toList
|> List.chunkBySize postPageSize
|> List.map (List.map (Layout.postLayout true))

let pages = List.length psts

let getFilenameForIndex i =
if i = 0 then
sprintf "index.html"
else
sprintf "posts/page%i.html" i

let layoutForPostSet i psts =
let nextPage =
if i = (pages - 1) then "#"
else "/" + getFilenameForIndex (i + 1)

let previousPage =
if i = 0 then "#"
else "/" + getFilenameForIndex (i - 1)

Layout.layout ctx "Home" [
section [Class "hero is-info is-medium is-bold"] [
div [Class "hero-body"] [
div [Class "container has-text-centered"] [
h1 [Class "title"] [!!desc]
]
]
]
div [Class "container"] [
section [Class "articles"] [
div [Class "column is-8 is-offset-2"] psts
]
]
div [Class "container"] [
div [Class "container has-text-centered"] [
a [Href previousPage] [!! "Previous"]
!! (sprintf "%i of %i" (i + 1) pages)
a [Href nextPage] [!! "Next"]
]
]]

psts
|> List.mapi (fun i psts ->
getFilenameForIndex i,
layoutForPostSet i psts
|> Layout.render ctx)

let generate (ctx : SiteContents) (projectRoot: string) (page: string) =
generate' ctx page
106 changes: 106 additions & 0 deletions src/generators/layout.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#r "../_lib/Fornax.Core.dll"
#if !FORNAX
#load "../loaders/postloader.fsx"
#load "../loaders/pageloader.fsx"
#load "../loaders/globalloader.fsx"
#endif

open Html

let injectWebsocketCode (webpage:string) =
let websocketScript =
"""
<script type="text/javascript">
var wsUri = "ws://localhost:8080/websocket";
function init()
{
websocket = new WebSocket(wsUri);
websocket.onclose = function(evt) { onClose(evt) };
}
function onClose(evt)
{
console.log('closing');
websocket.close();
document.location.reload();
}
window.addEventListener("load", init, false);
</script>
"""
let head = "<head>"
let index = webpage.IndexOf head
webpage.Insert ( (index + head.Length + 1),websocketScript)

let layout (ctx : SiteContents) active bodyCnt =
let pages = ctx.TryGetValues<Pageloader.Page> () |> Option.defaultValue Seq.empty
let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo> ()
let ttl =
siteInfo
|> Option.map (fun si -> si.title)
|> Option.defaultValue ""

let menuEntries =
pages
|> Seq.map (fun p ->
let cls = if p.title = active then "navbar-item is-active" else "navbar-item"
a [Class cls; Href p.link] [!! p.title ])
|> Seq.toList

html [] [
head [] [
meta [CharSet "utf-8"]
meta [Name "viewport"; Content "width=device-width, initial-scale=1"]
title [] [!! ttl]
link [Rel "icon"; Type "image/png"; Sizes "32x32"; Href "/images/favicon.png"]
link [Rel "stylesheet"; Href "https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"]
link [Rel "stylesheet"; Href "https://fonts.googleapis.com/css?family=Open+Sans"]
link [Rel "stylesheet"; Href "https://unpkg.com/bulma@0.8.0/css/bulma.min.css"]
link [Rel "stylesheet"; Type "text/css"; Href "/style/style.css"]

]
body [] [
nav [Class "navbar"] [
div [Class "container"] [
div [Class "navbar-brand"] [
a [Class "navbar-item"; Href "/"] [
img [Src "/images/bulma.png"; Alt "Logo"]
]
span [Class "navbar-burger burger"; HtmlProperties.Custom ("data-target", "navbarMenu")] [
span [] []
span [] []
span [] []
]
]
div [Id "navbarMenu"; Class "navbar-menu"] menuEntries
]
]
yield! bodyCnt
]
]

let render (ctx : SiteContents) cnt =
let disableLiveRefresh = ctx.TryGetValue<Postloader.PostConfig> () |> Option.map (fun n -> n.disableLiveRefresh) |> Option.defaultValue false
cnt
|> HtmlElement.ToString
|> fun n -> if disableLiveRefresh then n else injectWebsocketCode n

let published (post: Postloader.Post) =
post.published
|> Option.defaultValue System.DateTime.Now
|> fun n -> n.ToString("yyyy-MM-dd")

let postLayout (useSummary: bool) (post: Postloader.Post) =
div [Class "card article"] [
div [Class "card-content"] [
div [Class "media-content has-text-centered"] [
p [Class "title article-title"; ] [ a [Href post.link] [!! post.title]]
p [Class "subtitle is-6 article-subtitle"] [
a [Href "#"] [!! (defaultArg post.author "")]
!! (sprintf "on %s" (published post))
]
]
div [Class "content article-body"] [
!! (if useSummary then post.summary else post.content)

]
]
]
38 changes: 38 additions & 0 deletions src/generators/post.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#r "../_lib/Fornax.Core.dll"
#load "layout.fsx"

open Html


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

let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo> ()
let desc =
siteInfo
|> Option.map (fun si -> si.description)
|> Option.defaultValue ""

Layout.layout ctx post.title [
section [Class "hero is-info is-medium is-bold"] [
div [Class "hero-body"] [
div [Class "container has-text-centered"] [
h1 [Class "title"] [!!desc]
]
]
]
div [Class "container"] [
section [Class "articles"] [
div [Class "column is-8 is-offset-2"] [
Layout.postLayout false post
]
]
]
]

let generate (ctx : SiteContents) (projectRoot: string) (page: string) =
generate' ctx page
|> Layout.render ctx
7 changes: 7 additions & 0 deletions src/generators/staticfile.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#r "../_lib/Fornax.Core.dll"

open System.IO

let generate (ctx : SiteContents) (projectRoot: string) (page: string) =
let inputPath = Path.Combine(projectRoot, page)
File.ReadAllBytes inputPath
Binary file added src/images/avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/bulma.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/js/sampleJsFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var x = 1
16 changes: 16 additions & 0 deletions src/loaders/globalloader.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#r "../_lib/Fornax.Core.dll"

type SiteInfo = {
title: string
description: string
postPageSize: int
}

let loader (projectRoot: string) (siteContent: SiteContents) =
let siteInfo =
{ title = "Sample Fornax blog";
description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
postPageSize = 5 }
siteContent.Add(siteInfo)

siteContent
Loading

0 comments on commit 65ad6f6

Please sign in to comment.