Skip to content

Commit f7d60e0

Browse files
committed
logging around multi-page generation
1 parent 9edac35 commit f7d60e0

File tree

8 files changed

+78
-37
lines changed

8 files changed

+78
-37
lines changed

fcs/build.fsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ open Fake.Core.TargetOperators
199199
"Build"
200200
==> "GenerateDocs"
201201

202-
"Build"
203-
==> "GenerateDocs"
204-
205202
"GenerateDocs"
206203
==> "Release"
207204

fcs/docsrc/generators/page.fsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#r "../_lib/Fornax.Core.dll"
2-
#load "partials/layout.fsx"
2+
3+
#load "./partials/layout.fsx"
34

45
open Html
56

@@ -8,8 +9,15 @@ let generate' (ctx : SiteContents) (page: string) =
89
let posts =
910
ctx.TryGetValues<Contentloader.Post> ()
1011
|> Option.defaultValue Seq.empty
11-
let post = posts |> Seq.find (fun n -> "content/" + n.file = page)
12-
Layout.layout ctx [ !! post.content ] post.title
12+
|> Seq.map (fun post -> sprintf "content/%s" post.file, post)
13+
|> Map.ofSeq
14+
15+
match posts |> Map.tryFind page with
16+
| Some post ->
17+
Layout.layout ctx [ !! post.content ] post.title
18+
| None ->
19+
let allPostPaths = posts |> Map.toList |> List.map (fst >> fun s -> "* " + s) |> List.sort |> String.concat "\n"
20+
failwithf "Couldn't find page '%s' in available posts. Known posts are:\n%s" page allPostPaths
1321

1422
let generate (ctx : SiteContents) (projectRoot: string) (page: string) =
1523
generate' ctx page

fcs/docsrc/loaders/apirefloader.fsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let rec collectModules pn pu nn nu (m: Module) =
2727
]
2828

2929

30-
let loader (projectRoot: string) (siteContet: SiteContents) =
30+
let loader (projectRoot: string) (siteContent: SiteContents) =
3131
try
3232
let dlls =
3333
[
@@ -38,6 +38,8 @@ let loader (projectRoot: string) (siteContet: SiteContents) =
3838
Path.Combine(projectRoot, "..", "..", "artifacts", "bin", "fcs", "Release", "netcoreapp3.0")
3939
]
4040
for (label, dll) in dlls do
41+
printfn "generating api ref for %s at %s" label dll
42+
4143
let output = MetadataFormat.Generate(dll, markDownComments = true, publicOnly = true, libDirs = libs)
4244

4345
let allModules =
@@ -64,9 +66,9 @@ let loader (projectRoot: string) (siteContet: SiteContents) =
6466
Types = allTypes
6567
GeneratorOutput = output
6668
}
67-
siteContet.Add entities
69+
siteContent.Add entities
6870
with
6971
| ex ->
7072
printfn "%A" ex
7173

72-
siteContet
74+
siteContent

fcs/docsrc/loaders/contentloader.fsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type PostConfig = {
1212
disableLiveRefresh: bool
1313
}
1414

15+
16+
1517
///This is following documentation structure described here https://documentation.divio.com/
1618
type PostCategory =
1719
| Tutorial
@@ -41,6 +43,22 @@ type Post = {
4143
language: string option
4244
}
4345

46+
47+
let printPosts (sc: SiteContents) =
48+
sc.TryGetValues<Post> ()
49+
|> Option.defaultValue Seq.empty
50+
|> Seq.map (fun post -> sprintf "* content/%s" post.file)
51+
|> String.concat "\n"
52+
|> printfn "known posts:\n%s"
53+
54+
let lockAdd (sc: SiteContents) (item: Post) =
55+
lock sc (fun () ->
56+
printfn "Adding post %s" item.file
57+
printPosts sc
58+
sc.Add(item)
59+
printPosts sc
60+
)
61+
4462
let tokenToCss (x: TokenKind) =
4563
match x with
4664
| TokenKind.Keyword -> "hljs-keyword"
@@ -112,6 +130,7 @@ let relative toPath fromPath =
112130
toUri.MakeRelativeUri(fromUri).OriginalString
113131

114132
let loadFile projectRoot n =
133+
printfn "reading markdown file %s" n
115134
let text = System.IO.File.ReadAllText n
116135

117136
let config = (getConfig text).Split( '\n') |> List.ofArray
@@ -159,20 +178,21 @@ let loadFile projectRoot n =
159178
category = category
160179
language = language }
161180

162-
let loader (projectRoot: string) (siteContet: SiteContents) =
181+
let loader (projectRoot: string) (siteContent: SiteContents) =
163182
try
164183
let postsPath = System.IO.Path.Combine(projectRoot, "content")
165184
let posts =
166185
Directory.GetFiles(postsPath, "*", SearchOption.AllDirectories )
167186
|> Array.filter (fun n -> n.EndsWith ".md")
168-
|> Array.map (loadFile projectRoot)
187+
|> Array.Parallel.map (loadFile projectRoot)
169188

170189
posts
171-
|> Array.iter (fun p -> siteContet.Add p)
190+
|> Array.iter (lockAdd siteContent)
172191

173-
siteContet.Add({disableLiveRefresh = true})
192+
siteContent.Add {disableLiveRefresh = true}
174193
with
175-
| ex -> printfn "EX: %A" ex
194+
| ex ->
195+
printfn "EX: %A" ex
176196

177-
siteContet
197+
siteContent
178198

fcs/docsrc/loaders/copyloader.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
open System.IO
44

55

6-
let loader (projectRoot: string) (siteContet: SiteContents) =
6+
let loader (projectRoot: string) (siteContent: SiteContents) =
77
let intputPath = Path.Combine(projectRoot, "static")
88
let outputPath = Path.Combine(projectRoot, "_public", "static")
99
if Directory.Exists outputPath then Directory.Delete(outputPath, true)
@@ -15,4 +15,4 @@ let loader (projectRoot: string) (siteContet: SiteContents) =
1515
for filePath in Directory.GetFiles(intputPath, "*.*", SearchOption.AllDirectories) do
1616
File.Copy(filePath, filePath.Replace(intputPath, outputPath), true)
1717

18-
siteContet
18+
siteContent

fcs/docsrc/loaders/globalloader.fsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let config = {
1919
#endif
2020
}
2121

22-
let loader (projectRoot: string) (siteContet: SiteContents) =
23-
siteContet.Add(config)
22+
let loader (projectRoot: string) (siteContent: SiteContents) =
23+
siteContent.Add(config)
2424

25-
siteContet
25+
siteContent
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,26 @@ open System
33
#r "../../packages/docs/FSharp.Formatting/lib/netstandard2.0/FSharp.CodeFormat.dll"
44
#r "../../packages/docs/FSharp.Formatting/lib/netstandard2.0/FSharp.Markdown.dll"
55
#r "../../packages/docs/FSharp.Formatting/lib/netstandard2.0/FSharp.Literate.dll"
6-
#if !FORNAX
7-
#load "contentloader.fsx"
6+
7+
8+
#load "./contentloader.fsx"
89
open Contentloader
9-
#endif
1010

11+
let printPosts (sc: SiteContents) =
12+
sc.TryGetValues<Post> ()
13+
|> Option.defaultValue Seq.empty
14+
|> Seq.map (fun post -> sprintf "* content/%s" post.file)
15+
|> String.concat "\n"
16+
|> printfn "known posts:\n%s"
17+
18+
let lockAdd (sc: SiteContents) (item: Post) =
19+
lock sc (fun () ->
20+
printfn "Adding post %s" item.file
21+
printPosts sc
22+
sc.Add(item)
23+
printPosts sc
24+
)
25+
1126
open System.IO
1227
open FSharp.Literate
1328
open FSharp.CodeFormat
@@ -39,8 +54,6 @@ let tokenToCss (x: TokenKind) =
3954
| TokenKind.Escaped -> "hljs-regexp"
4055
| TokenKind.Default -> ""
4156

42-
43-
4457
let isSeparator (input : string) =
4558
input.StartsWith "---"
4659

@@ -84,6 +97,7 @@ let relative toPath fromPath =
8497
toUri.MakeRelativeUri(fromUri).OriginalString
8598

8699
let loadFile projectRoot n =
100+
printfn "reading literate file %s" n
87101
let text = System.IO.File.ReadAllText n
88102

89103
let config = (getConfig' text).Split( '\n') |> List.ofArray
@@ -130,20 +144,20 @@ let loadFile projectRoot n =
130144
category = category
131145
language = language }
132146

133-
let loader (projectRoot: string) (siteContet: SiteContents) =
147+
let loader (projectRoot: string) (siteContent: SiteContents) =
134148
try
135149
let postsPath = System.IO.Path.Combine(projectRoot, "content")
136150
let posts =
137151
Directory.GetFiles(postsPath, "*", SearchOption.AllDirectories )
138152
|> Array.filter (fun n -> n.EndsWith ".fsx")
139-
|> Array.map (loadFile projectRoot)
153+
|> Array.Parallel.map (loadFile projectRoot)
140154

141155
posts
142-
|> Array.iter (fun p -> siteContet.Add p)
156+
|> Array.iter (lockAdd siteContent)
143157

144-
siteContet.Add({disableLiveRefresh = true})
158+
siteContent.Add {disableLiveRefresh = true}
145159
with
146160
| ex -> printfn "EX: %A" ex
147161

148-
siteContet
162+
siteContent
149163

fcs/docsrc/loaders/pageloader.fsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ type Shortcut = {
77
icon: string
88
}
99

10-
let loader (projectRoot: string) (siteContet: SiteContents) =
11-
siteContet.Add({title = "Home"; link = "/"; icon = "fas fa-home"})
12-
siteContet.Add({title = "F# Software Foundation"; link = "https://fsharp.org"; icon = "fas fa-globe"})
13-
siteContet.Add({title = "GitHub repo"; link = "https://github.com/fsharp/FSharp.Compiler.Service"; icon = "fab fa-github"})
14-
siteContet.Add({title = "License"; link = "https://github.com/fsharp/FSharp.Compiler.Service/blob/master/LICENSE"; icon = "far fa-file"})
15-
siteContet.Add({title = "Release Notes"; link = "https://github.com/fsharp/FSharp.Compiler.Service/blob/master/RELEASE_NOTES.md"; icon = "far fa-file-alt"})
16-
siteContet
10+
let loader (projectRoot: string) (siteContent: SiteContents) =
11+
siteContent.Add({title = "Home"; link = "/"; icon = "fas fa-home"})
12+
siteContent.Add({title = "F# Software Foundation"; link = "https://fsharp.org"; icon = "fas fa-globe"})
13+
siteContent.Add({title = "GitHub repo"; link = "https://github.com/fsharp/FSharp.Compiler.Service"; icon = "fab fa-github"})
14+
siteContent.Add({title = "License"; link = "https://github.com/fsharp/FSharp.Compiler.Service/blob/master/LICENSE"; icon = "far fa-file"})
15+
siteContent.Add({title = "Release Notes"; link = "https://github.com/fsharp/FSharp.Compiler.Service/blob/master/RELEASE_NOTES.md"; icon = "far fa-file-alt"})
16+
siteContent

0 commit comments

Comments
 (0)