Skip to content

Commit 91a39a4

Browse files
committed
working
1 parent f7d60e0 commit 91a39a4

File tree

6 files changed

+86
-109
lines changed

6 files changed

+86
-109
lines changed

fcs/docsrc/config.fsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ let config = {
1414
{Script = "page.fsx"; Trigger = OnFileExt ".md"; OutputFile = Custom customRename }
1515
{Script = "page.fsx"; Trigger = OnFilePredicate isScriptToParse; OutputFile = Custom customRename }
1616
{Script = "apiref.fsx"; Trigger = Once; OutputFile = MultipleFiles (sprintf "reference/%s.html") }
17-
1817
{Script = "lunr.fsx"; Trigger = Once; OutputFile = NewFileName "index.json" }
1918
]
2019
}

fcs/docsrc/generators/apiref.fsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,12 @@ let generate' (ctx : SiteContents) =
295295

296296
let generate (ctx : SiteContents) (projectRoot: string) (page: string) =
297297
try
298-
generate' ctx
299-
|> List.map (fun (n,b) -> n, (Layout.render ctx b))
298+
printfn "generate api ref pages"
299+
let results =
300+
generate' ctx
301+
|> List.map (fun (n,b) -> n, (Layout.render ctx b))
302+
printfn "generated api ref pages"
303+
results
300304
with
301305
| ex ->
302306
printfn "ERROR IN API REF GENERATION:\n%A" ex

fcs/docsrc/generators/lunr.fsx

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#r "../_lib/Fornax.Core.dll"
22
#r "../../packages/docs/Newtonsoft.Json/lib/netstandard2.0/Newtonsoft.Json.dll"
33
#r "../../packages/docs/FSharp.Formatting/lib/netstandard2.0/FSharp.MetadataFormat.dll"
4+
45
#if !FORNAX
56
#load "../loaders/contentloader.fsx"
67
#load "../loaders/apirefloader.fsx"
78
#load "../loaders/globalloader.fsx"
8-
99
#endif
1010

1111
open Apirefloader
@@ -17,67 +17,73 @@ type Entry = {
1717
title: string
1818
content: string
1919
}
20-
let generate (ctx : SiteContents) (projectRoot: string) (page: string) =
21-
let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo>().Value
22-
let rootUrl = siteInfo.root_url
2320

24-
let pages = ctx.TryGetValues<Contentloader.Post> () |> Option.defaultValue Seq.empty
25-
let entries =
26-
pages
27-
|> Seq.map (fun n ->
28-
{uri = rootUrl + "/" + n.link.Replace("content/", ""); title = n.title; content = n.text}
29-
)
30-
31-
let all = ctx.TryGetValues<AssemblyEntities>()
32-
let refs =
33-
match all with
34-
| None -> []
35-
| Some all ->
36-
all
37-
|> Seq.toList
38-
|> List.collect (fun n ->
39-
let generatorOutput = n.GeneratorOutput
40-
let allModules = n.Modules
41-
let allTypes = n.Types
21+
let generate (ctx : SiteContents) (projectRoot: string) (page: string) =
22+
printfn "generating search index"
23+
try
24+
let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo>().Value
25+
let rootUrl = siteInfo.root_url
26+
let pages = ctx.TryGetValues<Contentloader.Post> () |> Option.defaultValue Seq.empty
27+
let entries =
28+
pages
29+
|> Seq.map (fun n ->
30+
{uri = rootUrl + "/" + n.link.Replace("content/", ""); title = n.title; content = n.text}
31+
)
4232

43-
let gen =
44-
let ctn =
45-
sprintf "%s \n %s" generatorOutput.AssemblyGroup.Name (generatorOutput.AssemblyGroup.Namespaces |> Seq.map (fun n -> n.Name) |> String.concat " ")
46-
{uri = (rootUrl + sprintf "/reference/%s/index.html" n.Label ); title = sprintf "%s - API Reference" n.Label; content = ctn }
33+
let all = ctx.TryGetValues<AssemblyEntities>()
34+
let refs =
35+
match all with
36+
| None -> []
37+
| Some all ->
38+
all
39+
|> Seq.toList
40+
|> List.collect (fun n ->
41+
let generatorOutput = n.GeneratorOutput
42+
let allModules = n.Modules
43+
let allTypes = n.Types
4744

48-
let mdlsGen =
49-
allModules
50-
|> Seq.map (fun m ->
51-
let m = m.Info
52-
let cnt =
53-
sprintf "%s \n %s \n %s \n %s \n %s \n %s"
54-
m.Name
55-
m.Comment.FullText
56-
(m.NestedModules |> List.map (fun m -> m.Name + " " + m.Comment.FullText ) |> String.concat " ")
57-
(m.NestedTypes |> List.map (fun m -> m.Name + " " + m.Comment.FullText ) |> String.concat " ")
58-
(m.ValuesAndFuncs |> List.map (fun m -> m.Name + " " + m.Comment.FullText ) |> String.concat " ")
59-
(m.TypeExtensions |> List.map (fun m -> m.Name + " " + m.Comment.FullText ) |> String.concat " ")
45+
let gen =
46+
let ctn =
47+
sprintf "%s \n %s" generatorOutput.AssemblyGroup.Name (generatorOutput.AssemblyGroup.Namespaces |> Seq.map (fun n -> n.Name) |> String.concat " ")
48+
{uri = (rootUrl + sprintf "/reference/%s/index.html" n.Label ); title = sprintf "%s - API Reference" n.Label; content = ctn }
6049

50+
let mdlsGen =
51+
allModules
52+
|> Seq.map (fun m ->
53+
let m = m.Info
54+
let cnt =
55+
sprintf "%s \n %s \n %s \n %s \n %s \n %s"
56+
m.Name
57+
m.Comment.FullText
58+
(m.NestedModules |> List.map (fun m -> m.Name + " " + m.Comment.FullText ) |> String.concat " ")
59+
(m.NestedTypes |> List.map (fun m -> m.Name + " " + m.Comment.FullText ) |> String.concat " ")
60+
(m.ValuesAndFuncs |> List.map (fun m -> m.Name + " " + m.Comment.FullText ) |> String.concat " ")
61+
(m.TypeExtensions |> List.map (fun m -> m.Name + " " + m.Comment.FullText ) |> String.concat " ")
6162

62-
{uri = rootUrl + sprintf "/reference/%s/%s.html" n.Label m.UrlName ; title = m.Name; content = cnt }
63-
)
6463

65-
let tsGen =
66-
allTypes
67-
|> Seq.map (fun m ->
68-
let m = m.Info
69-
let cnt =
70-
sprintf "%s \n %s \n %s"
71-
m.Name
72-
m.Comment.FullText
73-
(m.AllMembers |> List.map (fun m -> m.Name + " " + m.Comment.FullText ) |> String.concat " ")
64+
{uri = rootUrl + sprintf "/reference/%s/%s.html" n.Label m.UrlName ; title = m.Name; content = cnt }
65+
)
7466

67+
let tsGen =
68+
allTypes
69+
|> Seq.map (fun m ->
70+
let m = m.Info
71+
let cnt =
72+
sprintf "%s \n %s \n %s"
73+
m.Name
74+
m.Comment.FullText
75+
(m.AllMembers |> List.map (fun m -> m.Name + " " + m.Comment.FullText ) |> String.concat " ")
7576

76-
{uri = rootUrl + sprintf "/reference/%s/%s.html" n.Label m.UrlName ; title = m.Name; content = cnt }
77-
)
78-
[yield! entries; gen; yield! mdlsGen; yield! tsGen]
79-
)
8077

81-
[|yield! entries; yield! refs|]
82-
|> Newtonsoft.Json.JsonConvert.SerializeObject
78+
{uri = rootUrl + sprintf "/reference/%s/%s.html" n.Label m.UrlName ; title = m.Name; content = cnt }
79+
)
80+
[yield! entries; gen; yield! mdlsGen; yield! tsGen]
81+
)
82+
printfn "generated search index"
83+
[|yield! entries; yield! refs|]
84+
|> Newtonsoft.Json.JsonConvert.SerializeObject
85+
with
86+
| e ->
87+
failwithf "error while generating index for %s\n%A" page e
88+
8389

fcs/docsrc/generators/page.fsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ let generate' (ctx : SiteContents) (page: string) =
1414

1515
match posts |> Map.tryFind page with
1616
| Some post ->
17-
Layout.layout ctx [ !! post.content ] post.title
17+
try
18+
Layout.layout ctx [ !! post.content ] post.title
19+
with
20+
| e -> failwithf "Error while generating page for post %s\n%A" page e
1821
| None ->
1922
let allPostPaths = posts |> Map.toList |> List.map (fst >> fun s -> "* " + s) |> List.sort |> String.concat "\n"
2023
failwithf "Couldn't find page '%s' in available posts. Known posts are:\n%s" page allPostPaths

fcs/docsrc/loaders/contentloader.fsx

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

15-
16-
1715
///This is following documentation structure described here https://documentation.divio.com/
1816
type PostCategory =
1917
| Tutorial
@@ -43,22 +41,6 @@ type Post = {
4341
language: string option
4442
}
4543

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-
6244
let tokenToCss (x: TokenKind) =
6345
match x with
6446
| TokenKind.Keyword -> "hljs-keyword"
@@ -130,7 +112,7 @@ let relative toPath fromPath =
130112
toUri.MakeRelativeUri(fromUri).OriginalString
131113

132114
let loadFile projectRoot n =
133-
printfn "reading markdown file %s" n
115+
134116
let text = System.IO.File.ReadAllText n
135117

136118
let config = (getConfig text).Split( '\n') |> List.ofArray
@@ -167,7 +149,8 @@ let loadFile projectRoot n =
167149
with
168150
| _ -> None
169151

170-
152+
printfn "read markdown file %s" n
153+
171154
{ file = file
172155
link = link
173156
title = title
@@ -181,13 +164,11 @@ let loadFile projectRoot n =
181164
let loader (projectRoot: string) (siteContent: SiteContents) =
182165
try
183166
let postsPath = System.IO.Path.Combine(projectRoot, "content")
184-
let posts =
185-
Directory.GetFiles(postsPath, "*", SearchOption.AllDirectories )
186-
|> Array.filter (fun n -> n.EndsWith ".md")
187-
|> Array.Parallel.map (loadFile projectRoot)
188167

189-
posts
190-
|> Array.iter (lockAdd siteContent)
168+
Directory.GetFiles(postsPath, "*", SearchOption.AllDirectories )
169+
|> Array.filter (fun n -> n.EndsWith ".md")
170+
|> Array.Parallel.map (loadFile projectRoot)
171+
|> Array.iter siteContent.Add
191172

192173
siteContent.Add {disableLiveRefresh = true}
193174
with

fcs/docsrc/loaders/literateloader.fsx

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,10 @@ open System
44
#r "../../packages/docs/FSharp.Formatting/lib/netstandard2.0/FSharp.Markdown.dll"
55
#r "../../packages/docs/FSharp.Formatting/lib/netstandard2.0/FSharp.Literate.dll"
66

7-
7+
#if !FORNAX
88
#load "./contentloader.fsx"
99
open Contentloader
10-
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-
)
10+
#endif
2511

2612
open System.IO
2713
open FSharp.Literate
@@ -97,7 +83,6 @@ let relative toPath fromPath =
9783
toUri.MakeRelativeUri(fromUri).OriginalString
9884

9985
let loadFile projectRoot n =
100-
printfn "reading literate file %s" n
10186
let text = System.IO.File.ReadAllText n
10287

10388
let config = (getConfig' text).Split( '\n') |> List.ofArray
@@ -134,6 +119,8 @@ let loadFile projectRoot n =
134119
with
135120
| _ -> None
136121

122+
printfn "read literate file %s" n
123+
137124
{ file = file
138125
link = link
139126
title = title
@@ -147,13 +134,10 @@ let loadFile projectRoot n =
147134
let loader (projectRoot: string) (siteContent: SiteContents) =
148135
try
149136
let postsPath = System.IO.Path.Combine(projectRoot, "content")
150-
let posts =
151-
Directory.GetFiles(postsPath, "*", SearchOption.AllDirectories )
152-
|> Array.filter (fun n -> n.EndsWith ".fsx")
153-
|> Array.Parallel.map (loadFile projectRoot)
154-
155-
posts
156-
|> Array.iter (lockAdd siteContent)
137+
Directory.GetFiles(postsPath, "*", SearchOption.AllDirectories )
138+
|> Array.filter (fun n -> n.EndsWith ".fsx")
139+
|> Array.Parallel.map (loadFile projectRoot)
140+
|> Array.iter siteContent.Add
157141

158142
siteContent.Add {disableLiveRefresh = true}
159143
with

0 commit comments

Comments
 (0)