@@ -100,10 +100,10 @@ class StaticSiteContext(
100
100
val (indexes, children) = allFiles.flatMap(loadTemplate(_, isBlog)).partition(_.templateFile.isIndexPage())
101
101
102
102
def loadIndexPage (): TemplateFile =
103
- val indexFiles = from.listFiles { file => file.getName == " index.md" || file.getName == " index.html" }
104
103
indexes match
105
- case Nil => emptyTemplate(from, from.getName)
106
- case Seq (loadedTemplate) => loadedTemplate.templateFile.copy(file = from)
104
+ case Nil =>
105
+ args.defaultTemplate.fold(emptyTemplate(from, from.getName))(layouts(_).copy(title = TemplateName .FilenameDefined (from.getName))).copy(file = File (from, " index.html" ))
106
+ case Seq (loadedTemplate) => loadedTemplate.templateFile
107
107
case _ =>
108
108
// TODO (https://github.com/lampepfl/scaladoc/issues/238): provide proper error handling
109
109
val msg = s " ERROR: Multiple index pages for $from found in ${indexes.map(_.file)}"
@@ -129,14 +129,14 @@ class StaticSiteContext(
129
129
}
130
130
131
131
val processedTemplate = // Set provided name as arg in page for `docs`
132
- if from .getParentFile.toPath == docsPath && templateFile.isIndexPage() then
132
+ if templateFile.file .getParentFile.toPath == docsPath && templateFile.isIndexPage() then
133
133
if templateFile.title.name != " index" then
134
134
report.warn(" Property `title` will be overridden by project name" , from)
135
135
136
136
templateFile.copy(title = TemplateName .FilenameDefined (args.name))
137
137
else templateFile
138
138
139
- Some (LoadedTemplate (processedTemplate, processedChildren.toList, from ))
139
+ Some (LoadedTemplate (processedTemplate, processedChildren.toList, processedTemplate.file ))
140
140
catch
141
141
case e : RuntimeException =>
142
142
// TODO (https://github.com/lampepfl/scaladoc/issues/238): provide proper error handling
@@ -150,8 +150,8 @@ class StaticSiteContext(
150
150
if Files .exists(root.toPath.resolve(pagePath)) then pagePath
151
151
else pagePath.stripSuffix(" .html" ) + " .md"
152
152
153
- val file = root.toPath.resolve(path).toFile
154
- val LoadedTemplate (template, children, _ ) = loadTemplate(file , isBlog).get // Add proper logging if file does not exisits
153
+ // val file = root.toPath.resolve(path).toFile
154
+ val LoadedTemplate (template, children, file ) = loadTemplate(root.toPath.resolve(path).toFile , isBlog).get // Add proper logging if file does not exisits
155
155
optionTitle match
156
156
case Some (title) =>
157
157
val newTitle = template.title match
@@ -170,10 +170,22 @@ class StaticSiteContext(
170
170
val title = optionTitle match
171
171
case Some (t) => t
172
172
case None => " index"
173
- val fakeFile = Paths .get(root.toString, " docs" , title, " index.html" ).toFile
173
+ val sidebarContent = nested.map(loadSidebarContent)
174
+ // Heuristic to add section index.html around its child pages. Otherwise we put it in directory named after title of section in top-level
175
+ def longestPrefix (s1 : String , s2 : String ): String = s1.zip(s2).takeWhile(Function .tupled(_ == _)).map(_._1).mkString
176
+ val sortedNames = sidebarContent.collect {
177
+ case t if t.file.getName.reverse.dropWhile(_ != '.' ).reverse != " index" =>
178
+ t.file.toPath.toString
179
+ }.sorted
180
+ def indexPathTemplate (s : String ) = Paths .get(root.toString, s, " index.html" ).toFile
181
+ val fakeFile = Option .when(sortedNames.nonEmpty)(sortedNames).map { s =>
182
+ indexPathTemplate(longestPrefix(s.head, s.last))
183
+ }.filter(_.exists).getOrElse {
184
+ indexPathTemplate(s " docs/ ${title.toLowerCase}" )
185
+ }
174
186
LoadedTemplate (
175
187
args.defaultTemplate.fold(emptyTemplate(fakeFile, title))(layouts(_).copy(title = TemplateName .FilenameDefined (title))),
176
- nested.map(loadSidebarContent) ,
188
+ sidebarContent ,
177
189
fakeFile
178
190
)
179
191
0 commit comments