Skip to content

Commit

Permalink
Try to fix doc rendering for old versions of docsite (#3700)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi authored Oct 9, 2024
1 parent 45161b5 commit bbec010
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions docs/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,31 @@ object `package` extends RootModule {
createFolders = true
)

// Walk all files al render graphviz templates ourselves because the only Antora graphviz
expandDiagramsInDirectoryAdocFile(T.dest, mill.main.VisualizeModule.classpath().map(_.path))

PathRef(T.dest)
}

def expandDiagramsInDirectoryAdocFile(dest: os.Path,
visualizeClassPath: Agg[os.Path])
(implicit ctx: mill.api.Ctx) = {

// Walk all files to render graphviz templates ourselves because the only Antora graphviz
// plugin (Kroki) relies on an online web service that is super slow and flaky
def walkAllFiles(inputs: Map[(os.Path, Int), String]): Map[(os.Path, Int), String] = {
val output = collection.mutable.Map.empty[(os.Path, Int), String]
for (p <- os.walk(T.dest) if p.ext == "adoc"){
for (p <- os.walk(dest) if p.ext == "adoc"){
val outputLines = collection.mutable.ArrayDeque.empty[String]
val graphvizLines = collection.mutable.ArrayDeque.empty[String]
var isGraphViz = false
var isGraphViz0 = false

for((line, i) <- os.read.lines(p).zipWithIndex){
line match{
case "[graphviz]" => isGraphViz0 = true
case "...." if isGraphViz0 => isGraphViz0 = false; isGraphViz = true
case "```graphviz" => isGraphViz = true
case "```" if isGraphViz =>
case "```" | "...." if isGraphViz =>
isGraphViz = false
if (inputs.isEmpty) output((p, i)) = graphvizLines.mkString("\n")
else {
Expand All @@ -129,16 +141,14 @@ object `package` extends RootModule {

mill.util.Jvm.runSubprocess(
"mill.main.graphviz.GraphvizTools",
mill.main.VisualizeModule.classpath().map(_.path),
visualizeClassPath,
mainArgs = orderedDiagrams.map{case (p, i, src, dest) => s"$src;$dest;svg"}
)

walkAllFiles(orderedDiagrams.map{case (p, i, src, dest) => ((p, i), os.read(dest / "out.svg"))}.toMap)

PathRef(T.dest)
}


def supplementalFiles = T.source(millSourcePath / "supplemental-ui")

/**
Expand Down Expand Up @@ -232,6 +242,7 @@ object `package` extends RootModule {
os.proc("git", "checkout", oldVersion).call(cwd = checkout, stdout = os.Inherit)
val outputFolder = checkout / "out" / "docs" / "source.dest"
os.proc("./mill", "-i", "docs.source").call(cwd = checkout, stdout = os.Inherit)
expandDiagramsInDirectoryAdocFile(outputFolder, mill.main.VisualizeModule.classpath().map(_.path))
sanitizeAntoraYml(outputFolder, oldVersion, oldVersion, oldVersion)
PathRef(outputFolder)
}
Expand Down

0 comments on commit bbec010

Please sign in to comment.