2021-12-12 12:21:53 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2021 Henrik Böving. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
Authors: Henrik Böving
|
|
|
|
-/
|
|
|
|
import Lean
|
2022-03-06 17:51:06 +00:00
|
|
|
import Lake
|
2021-12-12 12:21:53 +00:00
|
|
|
import DocGen4.Process
|
2021-12-15 08:24:49 +00:00
|
|
|
import DocGen4.Output.Base
|
|
|
|
import DocGen4.Output.Index
|
|
|
|
import DocGen4.Output.Module
|
|
|
|
import DocGen4.Output.NotFound
|
2022-02-13 14:42:15 +00:00
|
|
|
import DocGen4.Output.Find
|
2022-05-19 18:48:26 +00:00
|
|
|
import DocGen4.Output.SourceLinker
|
2022-06-19 22:31:09 +00:00
|
|
|
import DocGen4.LeanInk.Output
|
2022-07-20 23:40:04 +00:00
|
|
|
import Std.Data.HashMap
|
2021-12-12 12:21:53 +00:00
|
|
|
|
|
|
|
namespace DocGen4
|
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
open Lean IO System Output Process Std
|
2021-12-13 12:00:53 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
def htmlOutputSetup (config : SiteBaseContext) : IO Unit := do
|
2022-02-19 17:15:43 +00:00
|
|
|
let basePath := FilePath.mk "." / "build" / "doc"
|
2022-06-19 22:31:09 +00:00
|
|
|
let srcBasePath := basePath / "src"
|
2022-07-20 23:40:04 +00:00
|
|
|
let declarationDataPath := basePath / "declaration-data.bmp"
|
2022-06-19 22:31:09 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
-- Base structure
|
2022-02-13 14:42:15 +00:00
|
|
|
FS.createDirAll basePath
|
|
|
|
FS.createDirAll (basePath / "find")
|
2022-06-19 22:31:09 +00:00
|
|
|
FS.createDirAll srcBasePath
|
2022-02-13 14:42:15 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
-- The three HTML files we always need
|
|
|
|
let indexHtml := ReaderT.run index config
|
2021-12-12 12:21:53 +00:00
|
|
|
FS.writeFile (basePath / "index.html") indexHtml.toString
|
2022-07-20 23:40:04 +00:00
|
|
|
|
|
|
|
let notFoundHtml := ReaderT.run notFound config
|
2021-12-13 12:00:53 +00:00
|
|
|
FS.writeFile (basePath / "404.html") notFoundHtml.toString
|
2022-02-22 04:40:14 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
let findHtml := ReaderT.run find { config with depthToRoot := 1 }
|
|
|
|
FS.writeFile (basePath / "find" / "index.html") findHtml.toString
|
2022-02-22 04:40:14 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
-- The root JSON for find
|
|
|
|
let topLevelModules := config.hierarchy.getChildren.toArray.map (Json.str ∘ toString ∘ Prod.fst)
|
|
|
|
FS.writeFile declarationDataPath (Json.arr topLevelModules).compress
|
2022-02-22 04:40:14 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
-- All the static stuff
|
|
|
|
FS.writeFile (basePath / "style.css") styleCss
|
2022-02-22 04:40:14 +00:00
|
|
|
FS.writeFile (basePath / "declaration-data.js") declarationDataCenterJs
|
2021-12-13 20:36:21 +00:00
|
|
|
FS.writeFile (basePath / "nav.js") navJs
|
2022-02-22 04:40:14 +00:00
|
|
|
FS.writeFile (basePath / "find" / "find.js") findJs
|
|
|
|
FS.writeFile (basePath / "how-about.js") howAboutJs
|
2022-02-13 13:25:37 +00:00
|
|
|
FS.writeFile (basePath / "search.js") searchJs
|
2022-02-17 19:27:00 +00:00
|
|
|
FS.writeFile (basePath / "mathjax-config.js") mathjaxConfigJs
|
2022-07-20 23:40:04 +00:00
|
|
|
|
|
|
|
-- All the static stuff for LeanInk
|
2022-06-20 16:39:55 +00:00
|
|
|
FS.writeFile (srcBasePath / "alectryon.css") alectryonCss
|
|
|
|
FS.writeFile (srcBasePath / "alectryon.js") alectryonJs
|
|
|
|
FS.writeFile (srcBasePath / "docutils_basic.css") docUtilsCss
|
2022-06-20 20:06:24 +00:00
|
|
|
FS.writeFile (srcBasePath / "pygments.css") pygmentsCss
|
2022-02-20 17:12:49 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
|
|
|
|
def htmlOutputResults (baseConfig : SiteBaseContext) (result : AnalyzerResult) (ws : Lake.Workspace) (leanHash: String) (inkPath : Option System.FilePath) : IO Unit := do
|
|
|
|
let config : SiteContext := {
|
|
|
|
result := result,
|
|
|
|
sourceLinker := ←sourceLinker ws leanHash
|
|
|
|
leanInkEnabled := inkPath.isSome
|
|
|
|
}
|
|
|
|
let basePath := FilePath.mk "." / "build" / "doc"
|
|
|
|
let srcBasePath := basePath / "src"
|
|
|
|
-- Rendering the entire lean compiler takes time....
|
|
|
|
--let sourceSearchPath := ((←Lean.findSysroot) / "src" / "lean") :: ws.root.srcDir :: ws.leanSrcPath
|
|
|
|
let sourceSearchPath := ws.root.srcDir :: ws.leanSrcPath
|
|
|
|
|
|
|
|
let mut declMap := HashMap.empty
|
|
|
|
for (_, mod) in result.moduleInfo.toArray do
|
|
|
|
let topLevelMod := mod.name.getRoot
|
|
|
|
let mut jsonDecls := #[]
|
|
|
|
for decl in filterMapDocInfo mod.members do
|
|
|
|
let name := decl.getName.toString
|
|
|
|
let doc := decl.getDocString.getD ""
|
|
|
|
let docLink := declNameToLink decl.getName |>.run config baseConfig
|
|
|
|
IO.println s!"DOC: {docLink}"
|
|
|
|
let sourceLink := getSourceUrl mod.name decl.getDeclarationRange |>.run config baseConfig
|
|
|
|
let json := Json.mkObj [("name", name), ("doc", doc), ("docLink", docLink), ("sourceLink", sourceLink)]
|
|
|
|
jsonDecls := jsonDecls.push json
|
|
|
|
let currentModDecls := declMap.findD topLevelMod #[]
|
|
|
|
declMap := declMap.insert topLevelMod (currentModDecls ++ jsonDecls)
|
|
|
|
|
|
|
|
for (topLevelMod, decls) in declMap.toList do
|
|
|
|
FS.writeFile (basePath / s!"declaration-data-{topLevelMod}.bmp") (Json.arr decls).compress
|
|
|
|
|
2022-06-20 16:39:55 +00:00
|
|
|
for (modName, module) in result.moduleInfo.toArray do
|
|
|
|
let fileDir := moduleNameToDirectory basePath modName
|
|
|
|
let filePath := moduleNameToFile basePath modName
|
2022-02-15 11:12:17 +00:00
|
|
|
-- path: 'basePath/module/components/till/last.html'
|
|
|
|
-- The last component is the file name, so we drop it from the depth to root.
|
2022-07-20 23:40:04 +00:00
|
|
|
let baseConfig := { baseConfig with depthToRoot := modName.components.dropLast.length }
|
|
|
|
let moduleHtml := moduleToHtml module |>.run config baseConfig
|
2022-02-15 11:12:17 +00:00
|
|
|
FS.createDirAll $ fileDir
|
|
|
|
FS.writeFile filePath moduleHtml.toString
|
2022-06-20 16:39:55 +00:00
|
|
|
if let some inkPath := inkPath then
|
|
|
|
if let some inputPath ← Lean.SearchPath.findModuleWithExt sourceSearchPath "lean" module.name then
|
|
|
|
IO.println s!"Inking: {modName.toString}"
|
|
|
|
-- path: 'basePath/src/module/components/till/last.html'
|
|
|
|
-- The last component is the file name, however we are in src/ here so dont drop it this time
|
2022-07-20 23:40:04 +00:00
|
|
|
let baseConfig := { baseConfig with depthToRoot := modName.components.length }
|
|
|
|
let srcHtml ← LeanInk.moduleToHtml module inkPath inputPath |>.run config baseConfig
|
2022-06-20 16:39:55 +00:00
|
|
|
let srcDir := moduleNameToDirectory srcBasePath modName
|
|
|
|
let srcPath := moduleNameToFile srcBasePath modName
|
|
|
|
FS.createDirAll srcDir
|
|
|
|
FS.writeFile srcPath srcHtml.toString
|
2021-12-12 12:21:53 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
def getSimpleBaseContext (hierarchy : Hierarchy) : SiteBaseContext :=
|
|
|
|
{
|
|
|
|
depthToRoot := 0,
|
|
|
|
currentName := none,
|
|
|
|
hierarchy
|
|
|
|
}
|
|
|
|
|
|
|
|
/--
|
|
|
|
The main entrypoint for outputting the documentation HTML based on an
|
|
|
|
`AnalyzerResult`.
|
|
|
|
-/
|
|
|
|
def htmlOutput (result : AnalyzerResult) (hierarchy : Hierarchy) (ws : Lake.Workspace) (leanHash: String) (inkPath : Option System.FilePath) : IO Unit := do
|
|
|
|
let baseConfig := getSimpleBaseContext hierarchy
|
|
|
|
htmlOutputSetup baseConfig
|
|
|
|
htmlOutputResults baseConfig result ws leanHash inkPath
|
|
|
|
|
2021-12-12 12:21:53 +00:00
|
|
|
end DocGen4
|
|
|
|
|