@@ -19,14 +19,17 @@ class StaticSiteContext(
1919
2020 var memberLinkResolver : String => Option [DRI ] = _ => None
2121
22- def indexTemplate (): Seq [ LoadedTemplate ] =
22+ def indexTemplate (): LoadedTemplate =
2323 val files = List (new File (root, " index.html" ), new File (root, " index.md" )).filter { _.exists() }
2424
2525 if files.size > 1 then
2626 val msg = s " ERROR: Multiple root index pages found: ${files.map(_.getAbsolutePath)}"
2727 report.error(msg)
2828
29- files.flatMap(loadTemplate(_, isBlog = false )).take(1 )
29+ files.flatMap(loadTemplate(_, isBlog = false )).headOption.getOrElse {
30+ val fakeFile = new File (root, " index.html" )
31+ LoadedTemplate (emptyTemplate(fakeFile, " index" ), List .empty, fakeFile)
32+ }
3033
3134 lazy val layouts : Map [String , TemplateFile ] =
3235 val layoutRoot = new File (root, " _layouts" )
@@ -39,7 +42,7 @@ class StaticSiteContext(
3942 else Some (Sidebar .load(Files .readAllLines(sidebarFile).asScala.mkString(" \n " )))
4043
4144 lazy val templates : Seq [LoadedTemplate ] =
42- sideBarConfig.fold(loadAllFiles().sortBy(_.templateFile.title))(_.map(loadSidebarContent))
45+ sideBarConfig.fold(loadAllFiles().sortBy(_.templateFile.title.name ))(_.map(loadSidebarContent))
4346
4447 lazy val orphanedTemplates : Seq [LoadedTemplate ] = {
4548 def doFlatten (t : LoadedTemplate ): Seq [Path ] =
@@ -93,7 +96,7 @@ class StaticSiteContext(
9396 val pageSettings = p.templateFile.settings.get(" page" ).collect{ case m : Map [String @ unchecked, _] => m }
9497 pageSettings.flatMap(_.get(" date" ).collect{ case s : String => s}).getOrElse(default) // blogs without date are last
9598
96- val processedChildren : Seq [LoadedTemplate ] = if ! isBlog then children.sortBy(_.templateFile.title) else
99+ val processedChildren : Seq [LoadedTemplate ] = if ! isBlog then children.sortBy(_.templateFile.title.name ) else
97100 children.sortBy(dateFrom(_)).reverse
98101
99102 processedChildren.foreach { child =>
@@ -108,10 +111,10 @@ class StaticSiteContext(
108111
109112 val processedTemplate = // Set provided name as arg in page for `docs`
110113 if from.getParentFile.toPath == docsPath && templateFile.isIndexPage() then
111- if templateFile.title != " index" then
114+ if templateFile.title.name != " index" then
112115 report.warn(" Property `title` will be overridden by project name" , from)
113116
114- templateFile.copy(title = args.name)
117+ templateFile.copy(title = TemplateName . FilenameDefined ( args.name) )
115118 else templateFile
116119
117120 Some (LoadedTemplate (processedTemplate, processedChildren.toList, from))
@@ -122,20 +125,31 @@ class StaticSiteContext(
122125 None
123126
124127 private def loadSidebarContent (entry : Sidebar ): LoadedTemplate = entry match
125- case Sidebar .Page (title , url) =>
126- val isBlog = title == " Blog"
128+ case Sidebar .Page (optionTitle , url) =>
129+ val isBlog = optionTitle == Some ( " Blog" )
127130 val path = if isBlog then " blog" else
128131 if Files .exists(root.toPath.resolve(url)) then url
129132 else url.stripSuffix(" .html" ) + " .md"
130133
131134 val file = root.toPath.resolve(path).toFile
132135 val LoadedTemplate (template, children, _) = loadTemplate(file, isBlog).get // Add proper logging if file does not exisits
133- LoadedTemplate (template.copy(settings = template.settings + (" title" -> title), file = file, title = title), children, file)
134-
135- case Sidebar .Category (title, nested) =>
136- // Add support for index.html/index.md files!
137- val fakeFile = new File (new File (root, " docs" ), title)
138- LoadedTemplate (emptyTemplate(fakeFile, title), nested.map(loadSidebarContent), fakeFile)
136+ optionTitle match
137+ case Some (title) =>
138+ val newTitle = template.title match
139+ case t : TemplateName .YamlDefined => t
140+ case _ : TemplateName .FilenameDefined => TemplateName .SidebarDefined (title)
141+ case t : TemplateName .SidebarDefined => t // should never reach this path
142+ LoadedTemplate (template.copy(settings = template.settings + (" title" -> title), file = file, title = newTitle), children, file)
143+ case None =>
144+ LoadedTemplate (template.copy(settings = template.settings, file = file), children, file)
145+
146+ case Sidebar .Category (title, optionUrl, nested) =>
147+ optionUrl match
148+ case Some (url) => // There is an index page for section, let's load it
149+ loadSidebarContent(Sidebar .Page (Some (title), url)).copy(children = nested.map(loadSidebarContent))
150+ case None => // No index page, let's create default fake file.
151+ val fakeFile = new File (new File (root, " docs" ), title)
152+ LoadedTemplate (emptyTemplate(fakeFile, title), nested.map(loadSidebarContent), fakeFile)
139153
140154 private def loadAllFiles () =
141155 def dir (name : String )= List (new File (root, name)).filter(_.isDirectory)
0 commit comments