feat: show versions in index HTML

main
Henrik Böving 2023-03-09 21:37:13 +01:00
parent 8cb5a2ead4
commit 720e1acf81
5 changed files with 22 additions and 10 deletions

View File

@ -81,7 +81,7 @@ def htmlOutputDeclarationDatas (result : AnalyzerResult) : HtmlT IO Unit := do
def htmlOutputResults (baseConfig : SiteBaseContext) (result : AnalyzerResult) (ws : Lake.Workspace) (ink : Bool) : IO Unit := do def htmlOutputResults (baseConfig : SiteBaseContext) (result : AnalyzerResult) (ws : Lake.Workspace) (ink : Bool) : IO Unit := do
let config : SiteContext := { let config : SiteContext := {
result := result, result := result,
sourceLinker := ←sourceLinker ws sourceLinker := ← SourceLinker.sourceLinker ws
leanInkEnabled := ink leanInkEnabled := ink
} }
@ -114,11 +114,13 @@ def htmlOutputResults (baseConfig : SiteBaseContext) (result : AnalyzerResult) (
let baseConfig := {baseConfig with depthToRoot := modName.components.length } let baseConfig := {baseConfig with depthToRoot := modName.components.length }
Process.LeanInk.runInk inputPath |>.run config baseConfig Process.LeanInk.runInk inputPath |>.run config baseConfig
def getSimpleBaseContext (hierarchy : Hierarchy) : SiteBaseContext := def getSimpleBaseContext (hierarchy : Hierarchy) : IO SiteBaseContext := do
{ return {
depthToRoot := 0, depthToRoot := 0,
currentName := none, currentName := none,
hierarchy hierarchy
projectGithubUrl := ← SourceLinker.getProjectGithubUrl
projectCommit := ← SourceLinker.getProjectCommit
} }
def htmlOutputIndex (baseConfig : SiteBaseContext) : IO Unit := do def htmlOutputIndex (baseConfig : SiteBaseContext) : IO Unit := do
@ -141,7 +143,7 @@ The main entrypoint for outputting the documentation HTML based on an
`AnalyzerResult`. `AnalyzerResult`.
-/ -/
def htmlOutput (result : AnalyzerResult) (hierarchy : Hierarchy) (ws : Lake.Workspace) (ink : Bool) : IO Unit := do def htmlOutput (result : AnalyzerResult) (hierarchy : Hierarchy) (ws : Lake.Workspace) (ink : Bool) : IO Unit := do
let baseConfig := getSimpleBaseContext hierarchy let baseConfig getSimpleBaseContext hierarchy
htmlOutputResults baseConfig result ws ink htmlOutputResults baseConfig result ws ink
htmlOutputIndex baseConfig htmlOutputIndex baseConfig

View File

@ -33,6 +33,14 @@ structure SiteBaseContext where
pages that don't have a module name. pages that don't have a module name.
-/ -/
currentName : Option Name currentName : Option Name
/--
The Github URL of the project that we are building docs for.
-/
projectGithubUrl : String
/--
The commit of the project that we are building docs for.
-/
projectCommit : String
/-- /--
The context used in the `HtmlM` monad for HTML templating. The context used in the `HtmlM` monad for HTML templating.
@ -86,6 +94,8 @@ def getCurrentName : BaseHtmlM (Option Name) := do return (← read).currentName
def getResult : HtmlM AnalyzerResult := do return (← read).result def getResult : HtmlM AnalyzerResult := do return (← read).result
def getSourceUrl (module : Name) (range : Option DeclarationRange): HtmlM String := do return (← read).sourceLinker module range def getSourceUrl (module : Name) (range : Option DeclarationRange): HtmlM String := do return (← read).sourceLinker module range
def leanInkEnabled? : HtmlM Bool := do return (← read).leanInkEnabled def leanInkEnabled? : HtmlM Bool := do return (← read).leanInkEnabled
def getProjectGithubUrl : BaseHtmlM String := do return (← read).projectGithubUrl
def getProjectCommit : BaseHtmlM String := do return (← read).projectCommit
/-- /--
If a template is meant to be extended because it for example only provides the If a template is meant to be extended because it for example only provides the

View File

@ -16,7 +16,7 @@ def index : BaseHtmlM Html := do templateExtends (baseHtml "Index") <|
<main> <main>
<a id="top"></a> <a id="top"></a>
<h1> Welcome to the documentation page </h1> <h1> Welcome to the documentation page </h1>
What is up? <p>This was built for commit <a href={s!"{← getProjectGithubUrl}/tree/{← getProjectCommit}"}>{s!"{← getProjectCommit} "}</a> using Lean 4 at commit <a href={s!"https://github.com/leanprover/lean4/tree/{Lean.githash}"}>{Lean.githash}</a></p>
</main> </main>
end Output end Output

View File

@ -6,7 +6,7 @@ Authors: Henrik Böving
import Lean import Lean
import Lake.Load import Lake.Load
namespace DocGen4.Output namespace DocGen4.Output.SourceLinker
open Lean open Lean
@ -86,4 +86,4 @@ def sourceLinker (ws : Lake.Workspace) : IO (Name → Option DeclarationRange
| some range => s!"{basic}#L{range.pos.line}-L{range.endPos.line}" | some range => s!"{basic}#L{range.pos.line}-L{range.endPos.line}"
| none => basic | none => basic
end DocGen4.Output end DocGen4.Output.SourceLinker

View File

@ -17,14 +17,14 @@ def runSingleCmd (p : Parsed) : IO UInt32 := do
| Except.ok ws => | Except.ok ws =>
let (doc, hierarchy) ← load <| .loadAllLimitAnalysis relevantModules let (doc, hierarchy) ← load <| .loadAllLimitAnalysis relevantModules
IO.println "Outputting HTML" IO.println "Outputting HTML"
let baseConfig := getSimpleBaseContext hierarchy let baseConfig getSimpleBaseContext hierarchy
htmlOutputResults baseConfig doc ws (p.hasFlag "ink") htmlOutputResults baseConfig doc ws (p.hasFlag "ink")
return 0 return 0
| Except.error rc => pure rc | Except.error rc => pure rc
def runIndexCmd (_p : Parsed) : IO UInt32 := do def runIndexCmd (_p : Parsed) : IO UInt32 := do
let hierarchy ← Hierarchy.fromDirectory Output.basePath let hierarchy ← Hierarchy.fromDirectory Output.basePath
let baseConfig := getSimpleBaseContext hierarchy let baseConfig getSimpleBaseContext hierarchy
htmlOutputIndex baseConfig htmlOutputIndex baseConfig
return 0 return 0
@ -34,7 +34,7 @@ def runGenCoreCmd (_p : Parsed) : IO UInt32 := do
| Except.ok ws => | Except.ok ws =>
let (doc, hierarchy) ← loadCore let (doc, hierarchy) ← loadCore
IO.println "Outputting HTML" IO.println "Outputting HTML"
let baseConfig := getSimpleBaseContext hierarchy let baseConfig getSimpleBaseContext hierarchy
htmlOutputResults baseConfig doc ws (ink := False) htmlOutputResults baseConfig doc ws (ink := False)
return 0 return 0
| Except.error rc => pure rc | Except.error rc => pure rc