-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpresentations.fsx
73 lines (60 loc) · 2.74 KB
/
presentations.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#load "./packages/FSharp.Formatting/FSharp.Formatting.fsx"
#r "./packages/HtmlAgilityPack/lib/netstandard2.0/HtmlAgilityPack.dll"
#r "./packages/Fue/lib/netstandard2.0/Fue.dll"
#load "./config.fsx"
namespace Presentations
open FSharp.Markdown
type Presentation = {Title:string;Content:MarkdownDocument}
module Operations =
open System.Text.RegularExpressions
open System.IO
open Fue.Data
open Fue.Compiler
open Config
let getTitle(line:MarkdownParagraph) =
match line with
| Heading (1,heading) ->
match heading with
| [Literal title] -> title
| _ -> "Title"
| _ -> "No Heading"
let getIndex (myString:string) =
match myString.Length with
| x when x < 45 -> myString.Length
| _ -> 45
let getSlug(title:string) =
let lowercase = title.ToLower()
let invalidChars = Regex.Replace(lowercase,@"[^a-z0-9\s-]", "")
let removeMultipleSpaces = Regex.Replace(invalidChars,@"\s+", " ").Trim()
let trimmed = removeMultipleSpaces.Substring(0, (getIndex removeMultipleSpaces)).Trim();
let hyphenate = Regex.Replace(trimmed, @"\s", "-");
hyphenate
let toMarkdown content =
(content,Markdown.Parse content)
let createPresentation (rawContent:string,content:MarkdownDocument) =
let title =
content.Paragraphs
|> List.map(getTitle)
|> List.filter(fun x -> (x <> "No Heading" && x <> "Title"))
|> List.head
let presentation =
{ Title=title
Content=content }
(rawContent,presentation)
let processFile = File.ReadAllText >> toMarkdown >> createPresentation
let writePresentation files =
files
|> Array.map(fun file -> sprintf "%s" file)
|> Array.map processFile
|> List.ofArray
|> List.map(fun (content,presentation) -> content,presentation.Title,presentation.Content)
|> List.map(fun (rawContent,title,content) ->
let filename = sprintf "%s.html" (getSlug title)
let template = __SOURCE_DIRECTORY__ + "/templates/presentation.html"
let compiledHTML =
init
|> add "title" title
|> add "content" rawContent
|> fromFile template
File.WriteAllText((sprintf "%s/%s" Config.getDestionationDirectory filename),compiledHTML,System.Text.Encoding.UTF8)
)