@@ -9,24 +9,15 @@ import java.util.Optional
99import scala .beans ._
1010
1111enum Sidebar :
12- case Root (index : Option [String ], pages : List [Sidebar .Child ])
1312 case Category (
1413 title : Option [String ],
1514 indexPath : Option [String ],
16- nested : List [Sidebar . Child ],
15+ nested : List [Sidebar ],
1716 directory : Option [String ]
1817 )
1918 case Page (title : Option [String ], pagePath : String , hidden : Boolean )
2019
2120object Sidebar :
22-
23- type Child = Category | Page
24- case class RawRoot (var rootIndex : String , var pages : JList [RawInput ]):
25- def this () = this (" " , JList ())
26-
27- def setRootIndex (s : String ) = rootIndex = s
28- def setPages (l : JList [RawInput ]) = pages = l
29-
3021 case class RawInput (
3122 @ BeanProperty var title : String ,
3223 @ BeanProperty var page : String ,
@@ -37,9 +28,9 @@ object Sidebar:
3728 ):
3829 def this () = this (" " , " " , " " , JList (), " " , false )
3930
40- private object RootTypeRef extends TypeReference [RawRoot ]
31+ private object RawInputTypeRef extends TypeReference [RawInput ]
4132
42- private def toSidebar (r : RawInput )(using CompilerContext ): Sidebar . Child = r match
33+ private def toSidebar (r : RawInput )(using CompilerContext ): Sidebar = r match
4334 case RawInput (title, page, index, subsection, dir, hidden) if page.nonEmpty && index.isEmpty && subsection.isEmpty() =>
4435 Sidebar .Page (Option .when(title.nonEmpty)(title), page, hidden)
4536 case RawInput (title, page, index, subsection, dir, hidden) if page.isEmpty && (! subsection.isEmpty() || ! index.isEmpty()) =>
@@ -49,43 +40,43 @@ object Sidebar:
4940 Sidebar .Page (None , page, hidden)
5041
5142 private def schemaMessage : String =
52- s """ Static site YAML configuration file should comply to the following description:
53- |rootIndex: <string> # optional
54- |pages:
55- | - <subsection> | <page>
43+ s """ Static site YAML configuration file should comply with the following description:
44+ |The root element of static site needs to be <subsection>
45+ |`title` and `directory` properties are ignored in root subsection.
5646 |
5747 |<subsection>:
58- | title: <string> # optional
59- | index: <string> # optional
60- | directory: <string> # optional
61- | subsection: # optional
48+ | title: <string> # optional - Default value is file name. Title can be also set using front-matter.
49+ | index: <string> # optional - If not provided, default empty index template is generated.
50+ | directory: <string> # optional - By default, directory name is title name in kebab case.
51+ | subsection: # optional - If not provided, pages are loaded from the index directory
6252 | - <subsection> | <page>
6353 | # either index or subsection needs to be present
6454 |<page>:
65- | title: <string> # optional
55+ | title: <string> # optional - Default value is file name. Title can be also set using front-matter.
6656 | page: <string>
67- | hidden: <boolean> # optional
57+ | hidden: <boolean> # optional - Default value is false.
6858 |
6959 |For more information visit:
7060 |https://docs.scala-lang.org/scala3/guides/scaladoc/static-site.html
7161 | """ .stripMargin
7262
73- def load (content : String | java.io.File )(using CompilerContext ): Sidebar .Root =
63+ def load (content : String | java.io.File )(using CompilerContext ): Sidebar .Category =
7464 import scala .util .Try
7565 val mapper = ObjectMapper (YAMLFactory ())
7666 def readValue = content match
77- case s : String => mapper.readValue(s, RootTypeRef )
78- case f : java.io.File => mapper.readValue(f, RootTypeRef )
67+ case s : String => mapper.readValue(s, RawInputTypeRef )
68+ case f : java.io.File => mapper.readValue(f, RawInputTypeRef )
7969
80- val root : RawRoot = Try (readValue)
70+ val root : RawInput = Try (readValue)
8171 .fold(
8272 { e =>
8373 report.warn(schemaMessage, e)
84- RawRoot ( " " , java.util. Collections .emptyList() )
74+ new RawInput ( )
8575 },
8676 identity
8777 )
88-
89- val rootIndex : String = root.rootIndex
90- val pages : List [Sidebar .Child ] = root.pages.asScala.toList.map(toSidebar)
91- Sidebar .Root (Option .when(rootIndex.nonEmpty)(rootIndex), pages)
78+ toSidebar(root) match
79+ case c : Sidebar .Category => c
80+ case _ =>
81+ report.error(s " Root element is not a subsection. \n $schemaMessage" )
82+ Sidebar .Category (None , None , List .empty, None )
0 commit comments