@@ -20,7 +20,7 @@ import util.Try
2020
2121import scala .collection .JavaConverters ._
2222
23- class StaticSiteContext (val root : File , sourceSets : Set [SourceSetWrapper ], args : Args , val sourceLinks : SourceLinks ):
23+ class StaticSiteContext (val root : File , sourceSets : Set [SourceSetWrapper ], val args : Args , val sourceLinks : SourceLinks ):
2424
2525 var memberLinkResolver : String => Option [DRI ] = _ => None
2626
@@ -81,16 +81,15 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], args:
8181 val topLevelFiles = if isBlog then Seq (from, new File (from, " _posts" )) else Seq (from)
8282 val allFiles = topLevelFiles.filter(_.isDirectory).flatMap(_.listFiles())
8383 val (indexes, children) = allFiles.flatMap(loadTemplate(_)).partition(_.templateFile.isIndexPage())
84- if (indexes.size > 1 )
85- // TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
86- println(s " ERROR: Multiple index pages for $from found in ${indexes.map(_.file)}" )
84+
8785 def loadIndexPage (): TemplateFile =
88- val indexFiles = from.listFiles { file => file.getName == " index.md" || file.getName == " index.html" }
89- indexFiles.size match
90- case 0 => emptyTemplate(from, from.getName)
91- case 1 => loadTemplateFile(indexFiles.head) .copy(file = from)
86+ val indexFiles = from.listFiles { file => file.getName == " index.md" || file.getName == " index.html" }
87+ indexes match
88+ case Nil => emptyTemplate(from, from.getName)
89+ case Seq (loadedTemplate) => loadedTemplate.templateFile .copy(file = from)
9290 case _ =>
93- val msg = s " ERROR: Multiple index pages found under ${from.toPath}"
91+ // TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
92+ val msg = s " ERROR: Multiple index pages for $from found in ${indexes.map(_.file)}"
9493 throw new java.lang.RuntimeException (msg)
9594
9695 val templateFile = if (from.isDirectory) loadIndexPage() else loadTemplateFile(from)
@@ -101,7 +100,15 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], args:
101100 pageSettings.flatMap(_.get(" date" ).collect{ case s : String => s}).getOrElse(" 1900-01-01" ) // blogs without date are last
102101 children.sortBy(dateFrom).reverse
103102
104- Some (LoadedTemplate (templateFile, processedChildren.toList, from))
103+ val processedTemplate = // Set provided name as arg in page for `docs`
104+ if from.getParentFile.toPath == docsPath && templateFile.isIndexPage() then
105+ // TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
106+ if templateFile.title != " index" then println(s " [WARN] title in $from will be overriden " )
107+ val projectTitle = args.projectTitle.getOrElse(args.name)
108+ templateFile.copy(title = projectTitle)
109+ else templateFile
110+
111+ Some (LoadedTemplate (processedTemplate, processedChildren.toList, from))
105112 catch
106113 case e : RuntimeException =>
107114 // TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
0 commit comments