@@ -3,6 +3,7 @@ package site
3
3
4
4
import java .io .File
5
5
import java .nio .file .Files
6
+ import java .nio .file .FileVisitOption
6
7
import java .nio .file .Path
7
8
import java .nio .file .Paths
8
9
@@ -40,7 +41,28 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
40
41
41
42
lazy val templates : Seq [LoadedTemplate ] = sideBarConfig.fold(loadAllFiles())(_.map(loadSidebarContent))
42
43
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
+ }
44
66
45
67
private def isValidTemplate (file : File ): Boolean =
46
68
(file.isDirectory && ! file.getName.startsWith(" _" )) ||
@@ -88,10 +110,11 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
88
110
case Sidebar .Page (title, url) =>
89
111
val isBlog = title == " Blog"
90
112
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!
92
114
val LoadedTemplate (template, children, tFile) = loadTemplate(file.toFile, isBlog).get // Add proper logging if file does not exisits
93
115
LoadedTemplate (template.copy(settings = template.settings + (" title" -> List (title))), children, tFile)
94
116
case Sidebar .Category (title, nested) =>
117
+ // Add support for index.html/index.md files!
95
118
val fakeFile = new File (root, title)
96
119
LoadedTemplate (emptyTemplate(fakeFile), nested.map(loadSidebarContent), fakeFile)
97
120
0 commit comments