@@ -3,6 +3,7 @@ package site
33
44import java .io .File
55import java .nio .file .Files
6+ import java .nio .file .FileVisitOption
67import java .nio .file .Path
78import 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
0 commit comments