Skip to content

Commit a3cae29

Browse files
committed
Render pages outside sidebar as well
1 parent a046777 commit a3cae29

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

scala3doc/src/dotty/dokka/site/StaticSiteContext.scala

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package site
33

44
import java.io.File
55
import java.nio.file.Files
6+
import java.nio.file.FileVisitOption
67
import java.nio.file.Path
78
import java.nio.file.Paths
89

@@ -40,7 +41,28 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
4041

4142
lazy val templates: Seq[LoadedTemplate] = sideBarConfig.fold(loadAllFiles())(_.map(loadSidebarContent))
4243

43-
lazy val pages = templates.map(templateToPage)
44+
lazy val mainPages: Seq[StaticPageNode] = templates.map(templateToPage)
45+
46+
lazy val allPages: Seq[StaticPageNode] = sideBarConfig.fold(mainPages){ sidebar =>
47+
def flattenPages(p: StaticPageNode): Set[Path] =
48+
Set(p.template.file.toPath) ++ p.getChildren.asScala.collect { case p: StaticPageNode => flattenPages(p) }.flatten
49+
50+
val mainFiles = mainPages.toSet.flatMap(flattenPages)
51+
val docsPath = root.toPath.resolve("docs")
52+
val allPaths =
53+
if !Files.exists(docsPath) then Nil
54+
else Files.walk(docsPath, FileVisitOption.FOLLOW_LINKS).iterator().asScala.toList
55+
56+
val orphanedFiles = allPaths.filterNot(mainFiles.contains).filter { p =>
57+
val name = p.getFileName.toString
58+
name.endsWith(".md") || name.endsWith(".html")
59+
}
60+
61+
println(s"Rendering: $orphanedFiles")
62+
val orphanedTemplates = orphanedFiles.flatMap(p => loadTemplate(p.toFile, isBlog = false))
63+
64+
mainPages ++ orphanedTemplates.map(templateToPage)
65+
}
4466

4567
private def isValidTemplate(file: File): Boolean =
4668
(file.isDirectory && !file.getName.startsWith("_")) ||
@@ -88,10 +110,11 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
88110
case Sidebar.Page(title, url) =>
89111
val isBlog = title == "Blog"
90112
val path = if isBlog then "blog" else url.stripSuffix(".html") + ".md"
91-
val file = root.toPath.resolve(path) // Add support for.html files!
113+
val file = root.toPath.resolve(path) // Add support for .html files!
92114
val LoadedTemplate(template, children, tFile) = loadTemplate(file.toFile, isBlog).get // Add proper logging if file does not exisits
93115
LoadedTemplate(template.copy(settings = template.settings + ("title" -> List(title))), children, tFile)
94116
case Sidebar.Category(title, nested) =>
117+
// Add support for index.html/index.md files!
95118
val fakeFile = new File(root, title)
96119
LoadedTemplate(emptyTemplate(fakeFile), nested.map(loadSidebarContent), fakeFile)
97120

scala3doc/src/dotty/dokka/site/processors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class SitePagesCreator(ctx: Option[StaticSiteContext]) extends BaseStaticSitePro
9393
override def transform(input: RootPageNode, ctx: StaticSiteContext): RootPageNode =
9494
val (contentPage, others) = input.getChildren.asScala.toList.partition { _.isInstanceOf[ContentPage] }
9595
val modifiedModuleRoot = processRootPage(input, contentPage)
96-
val (indexes, children) = ctx.pages.partition(_.template.isIndexPage())
96+
val (indexes, children) = ctx.allPages.partition(_.template.isIndexPage())
9797
// TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
9898
if (indexes.size > 1) println("ERROR: Multiple index pages found $indexes}")
9999

@@ -134,7 +134,7 @@ class RootIndexPageCreator(ctx: Option[StaticSiteContext]) extends BaseStaticSit
134134
input.getName,
135135
docsRootDRI,
136136
root.getSourceSets,
137-
(ctx.pages.map(toNavigationNode) ++ api).asJava
137+
(ctx.mainPages.map(toNavigationNode) ++ api).asJava
138138
)
139139
)
140140
}

0 commit comments

Comments
 (0)