Skip to content

Commit cf5fcc2

Browse files
committed
Sidebar is able to accept directories
1 parent 659f186 commit cf5fcc2

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,23 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], args:
4444

4545
lazy val mainPages: Seq[StaticPageNode] = templates.map(templateToPage)
4646

47+
val docsPath = root.toPath.resolve("docs")
48+
4749
lazy val allPages: Seq[StaticPageNode] = sideBarConfig.fold(mainPages){ sidebar =>
4850
def flattenPages(p: StaticPageNode): Set[Path] =
4951
Set(p.template.file.toPath) ++ p.getChildren.asScala.collect { case p: StaticPageNode => flattenPages(p) }.flatten
5052

5153
val mainFiles = mainPages.toSet.flatMap(flattenPages)
52-
val docsPath = root.toPath.resolve("docs")
54+
5355
val allPaths =
5456
if !Files.exists(docsPath) then Nil
5557
else Files.walk(docsPath, FileVisitOption.FOLLOW_LINKS).iterator().asScala.toList
5658

5759
val orphanedFiles = allPaths.filterNot(mainFiles.contains).filter { p =>
5860
val name = p.getFileName.toString
59-
name.endsWith(".md") || name.endsWith(".html")
61+
def isSupported = name.endsWith(".md") || name.endsWith(".html")
62+
def notIndex = name == "index.md" || name == "index.html"
63+
isSupported && notIndex
6064
}
6165

6266
val orphanedTemplates = orphanedFiles.flatMap(p => loadTemplate(p.toFile, isBlog = false))
@@ -114,10 +118,14 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], args:
114118
private def loadSidebarContent(entry: Sidebar): LoadedTemplate = entry match
115119
case Sidebar.Page(title, url) =>
116120
val isBlog = title == "Blog"
117-
val path = if isBlog then "blog" else url.stripSuffix(".html") + ".md"
118-
val file = root.toPath.resolve(path) // Add support for .html files!
119-
val LoadedTemplate(template, children, tFile) = loadTemplate(file.toFile, isBlog).get // Add proper logging if file does not exisits
120-
LoadedTemplate(template.copy(settings = template.settings + ("title" -> title)), children, tFile)
121+
val path = if isBlog then "blog" else
122+
if Files.exists(root.toPath.resolve(url)) then url
123+
else url.stripSuffix(".html") + ".md"
124+
125+
val file = root.toPath.resolve(path).toFile
126+
val LoadedTemplate(template, children, _) = loadTemplate(file, isBlog).get // Add proper logging if file does not exisits
127+
LoadedTemplate(template.copy(settings = template.settings + ("title" -> title), file = file), children, file)
128+
121129
case Sidebar.Category(title, nested) =>
122130
// Add support for index.html/index.md files!
123131
val fakeFile = new File(root, title)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ class SitePagesCreator(ctx: Option[StaticSiteContext]) extends BaseStaticSitePro
9292
override def transform(input: RootPageNode, ctx: StaticSiteContext): RootPageNode =
9393
val (contentPage, others) = input.getChildren.asScala.toList.partition { _.isInstanceOf[ContentPage] }
9494
val modifiedModuleRoot = processRootPage(input, contentPage)
95-
val (indexes, children) = ctx.allPages.partition(_.template.isIndexPage())
95+
val (indexes, children) = ctx.allPages.partition(f =>
96+
f.template.isIndexPage() && f.template.file.toPath.getParent() == ctx.docsPath )
9697
// TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
97-
if (indexes.size > 1) println("ERROR: Multiple index pages found $indexes}")
98+
if (indexes.size > 1) println(s"ERROR: Multiple index pages found ${indexes.map(_.template.file)}")
9899

99100
val rootContent = indexes.headOption.fold(ctx.asContent(Text(), mkDRI(extra = "root_content")).get(0))(_.getContent)
100101

0 commit comments

Comments
 (0)