Skip to content

Commit 5e5b4d0

Browse files
committed
fix(docs): reference resolution and missing site info
1 parent 58c72ef commit 5e5b4d0

File tree

3 files changed

+106
-71
lines changed

3 files changed

+106
-71
lines changed

docs/generators/lunr.fsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ type Entry = {
1919
content: string
2020
}
2121
let generate (ctx : SiteContents) (projectRoot: string) (page: string) =
22-
let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo>().Value
23-
let rootUrl = siteInfo.root_url
22+
let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo>()
23+
let rootUrl =
24+
match siteInfo with
25+
| Some info -> info.root_url
26+
| None -> ""
2427

2528
let pages = ctx.TryGetValues<Contentloader.Post> () |> Option.defaultValue Seq.empty
2629
let entries =

docs/generators/partials/menu.fsx

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ open Html
1010

1111
let menu (ctx : SiteContents) (page: string) =
1212
let shortcuts = ctx.GetValues<Pageloader.Shortcut> ()
13-
let all = ctx.GetValues<Apirefloader.AssemblyEntities>()
13+
let all = ctx.TryGetValues<Apirefloader.AssemblyEntities>() |> Option.defaultValue Seq.empty
1414

1515
let content = ctx.GetValues<Contentloader.Post> ()
16-
let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo>().Value
17-
let rootUrl = siteInfo.root_url
16+
let siteInfo = ctx.TryGetValue<Globalloader.SiteInfo>()
17+
let rootUrl =
18+
match siteInfo with
19+
| Some info -> info.root_url
20+
| None -> ""
1821

1922
let group = content |> Seq.tryFind (fun n -> n.title = page) |> Option.map (fun n -> n.category)
2023

@@ -28,6 +31,25 @@ let menu (ctx : SiteContents) (page: string) =
2831
|> Seq.filter (fun n -> n.category = Contentloader.HowTo && not n.hide_menu )
2932
|> Seq.sortBy (fun n -> n.menu_order)
3033

34+
let apiReferencesSection =
35+
if Seq.isEmpty all then
36+
// If no API references are available, don't show the section
37+
[]
38+
else
39+
[
40+
li [Class "dd-item parent"] [
41+
a [if group = None then Class "active" else Class ""] [!! "API References"]
42+
ul [Class "child"] [
43+
for r in all ->
44+
li [Class "dd-item"] [
45+
a [Href (rootUrl + "/reference/" + r.Label + "/index.html"); if r.Label = page then Class "active" else Class "" ] [
46+
!! r.Label
47+
]
48+
]
49+
]
50+
]
51+
]
52+
3153
let menuHeader =
3254
[
3355
li [Class "dd-item"] [
@@ -44,17 +66,7 @@ let menu (ctx : SiteContents) (page: string) =
4466
]
4567
]
4668
]
47-
li [Class "dd-item parent"] [
48-
a [if group = None then Class "active" else Class ""] [!! "API References"]
49-
ul [Class "child"] [
50-
for r in all ->
51-
li [Class "dd-item"] [
52-
a [Href (rootUrl + "/reference/" + r.Label + "/index.html"); if r.Label = page then Class "active" else Class "" ] [
53-
!! r.Label
54-
]
55-
]
56-
]
57-
]
69+
yield! apiReferencesSection
5870
]
5971

6072
let renderShortcuts =
@@ -77,11 +89,15 @@ let menu (ctx : SiteContents) (page: string) =
7789
!! """<p>Built with <a href="https://github.com/ionide/Fornax">Fornax</a>"""
7890
]
7991

92+
let title =
93+
match siteInfo with
94+
| Some info -> info.title
95+
| None -> "FSharpLint"
8096

8197
nav [Id "sidebar"] [
8298
div [Id "header-wrapper"] [
8399
div [Id "header"] [
84-
h2 [Id "logo"] [!! siteInfo.title]
100+
h2 [Id "logo"] [!! title]
85101
]
86102
div [Class "searchbox"] [
87103
label [HtmlProperties.Custom ("for", "search-by")] [i [Class "fas fa-search"] []]

docs/loaders/apirefloader.fsx

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,64 +30,80 @@ let rec collectModules pn pu nn nu (m: ApiDocEntity) =
3030

3131
let loader (projectRoot: string) (siteContet: SiteContents) =
3232
try
33-
// Try to find FSharpLint.Core.dll in the project build output
33+
// Try multiple possible locations for the assembly
3434
let projectDir = Path.Combine(projectRoot, "..", "src", "FSharpLint.Core")
35-
let binDir = Path.Combine(projectDir, "bin", "Release", "net9.0")
36-
let dllPath = Path.Combine(binDir, "FSharpLint.Core.dll")
35+
let possiblePaths = [
36+
// Release build
37+
Path.Combine(projectDir, "bin", "Release", "net9.0", "FSharpLint.Core.dll")
38+
// Debug build
39+
Path.Combine(projectDir, "bin", "Debug", "net9.0", "FSharpLint.Core.dll")
40+
// Default build output (no custom output path)
41+
Path.Combine(projectDir, "bin", "Release", "FSharpLint.Core.dll")
42+
Path.Combine(projectDir, "bin", "Debug", "FSharpLint.Core.dll")
43+
]
3744

38-
let dlls =
39-
[
40-
"FSharpLint.Core", dllPath
41-
]
42-
let libs =
43-
[
44-
binDir
45-
]
46-
for (label, dll) in dlls do
47-
if File.Exists dll then
48-
let inputs = [ApiDocInput.FromFile(dll)]
49-
let output = ApiDocs.GenerateModel(inputs, label, [], libDirs = libs)
50-
51-
let allModules =
52-
output.Collection.Namespaces
53-
|> List.collect (fun n ->
54-
List.collect (collectModules n.Name n.Name n.Name n.Name) n.Entities
55-
)
45+
let foundDll = possiblePaths |> List.tryFind File.Exists
46+
47+
match foundDll with
48+
| Some dllPath ->
49+
let binDir = Path.GetDirectoryName(dllPath)
50+
printfn "Found assembly at: %s" dllPath
51+
printfn "Using lib directory: %s" binDir
52+
53+
let libs = [binDir]
54+
55+
// Try to load with minimal dependencies first
56+
let inputs = [ApiDocInput.FromFile(dllPath)]
57+
try
58+
let output = ApiDocs.GenerateModel(inputs, "FSharpLint.Core", [], libDirs = libs)
59+
60+
let allModules =
61+
output.Collection.Namespaces
62+
|> List.collect (fun n ->
63+
List.collect (collectModules n.Name n.Name n.Name n.Name) n.Entities
64+
)
5665

57-
let allTypes =
58-
[
59-
yield!
60-
output.Collection.Namespaces
61-
|> List.collect (fun n ->
62-
n.Entities |> List.choose (fun t ->
63-
if t.IsTypeDefinition then
64-
Some {ParentName = n.Name; ParentUrlName = n.Name; NamespaceName = n.Name; NamespaceUrlName = n.Name; Info = t}
65-
else
66-
None)
67-
)
68-
yield!
69-
allModules
70-
|> List.collect (fun n ->
71-
// Get nested types from nested entities
72-
n.Info.NestedEntities
73-
|> List.choose (fun e ->
74-
if e.IsTypeDefinition then
75-
Some {ParentName = n.Info.Name; ParentUrlName = n.Info.UrlBaseName; NamespaceName = n.NamespaceName; NamespaceUrlName = n.NamespaceUrlName; Info = e}
76-
else
77-
None)
78-
)
79-
]
80-
let entities = {
81-
Label = label
82-
Modules = allModules
83-
Types = allTypes
84-
GeneratorOutput = output
85-
}
86-
siteContet.Add entities
87-
else
88-
printfn "Warning: Could not find assembly at %s" dll
66+
let allTypes =
67+
[
68+
yield!
69+
output.Collection.Namespaces
70+
|> List.collect (fun n ->
71+
n.Entities |> List.choose (fun t ->
72+
if t.IsTypeDefinition then
73+
Some {ParentName = n.Name; ParentUrlName = n.Name; NamespaceName = n.Name; NamespaceUrlName = n.Name; Info = t}
74+
else
75+
None)
76+
)
77+
yield!
78+
allModules
79+
|> List.collect (fun n ->
80+
// Get nested types from nested entities
81+
n.Info.NestedEntities
82+
|> List.choose (fun e ->
83+
if e.IsTypeDefinition then
84+
Some {ParentName = n.Info.Name; ParentUrlName = n.Info.UrlBaseName; NamespaceName = n.NamespaceName; NamespaceUrlName = n.NamespaceUrlName; Info = e}
85+
else
86+
None)
87+
)
88+
]
89+
let entities = {
90+
Label = "FSharpLint.Core"
91+
Modules = allModules
92+
Types = allTypes
93+
GeneratorOutput = output
94+
}
95+
siteContet.Add entities
96+
printfn "Successfully loaded API documentation for FSharpLint.Core"
97+
with
98+
| ex ->
99+
printfn "Failed to generate API docs from %s: %A" dllPath ex
100+
printfn "Continuing without API documentation..."
101+
| None ->
102+
printfn "Warning: Could not find FSharpLint.Core.dll in any of the expected locations:"
103+
possiblePaths |> List.iter (printfn " - %s")
104+
printfn "API documentation will not be generated."
89105
with
90106
| ex ->
91-
printfn "%A" ex
107+
printfn "Error in API reference loader: %A" ex
92108

93109
siteContet

0 commit comments

Comments
 (0)