@@ -9,24 +9,15 @@ import java.util.Optional
9
9
import scala .beans ._
10
10
11
11
enum Sidebar :
12
- case Root (index : Option [String ], pages : List [Sidebar .Child ])
13
12
case Category (
14
13
title : Option [String ],
15
14
indexPath : Option [String ],
16
- nested : List [Sidebar . Child ],
15
+ nested : List [Sidebar ],
17
16
directory : Option [String ]
18
17
)
19
18
case Page (title : Option [String ], pagePath : String , hidden : Boolean )
20
19
21
20
object 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
-
30
21
case class RawInput (
31
22
@ BeanProperty var title : String ,
32
23
@ BeanProperty var page : String ,
@@ -37,9 +28,9 @@ object Sidebar:
37
28
):
38
29
def this () = this (" " , " " , " " , JList (), " " , false )
39
30
40
- private object RootTypeRef extends TypeReference [RawRoot ]
31
+ private object RawInputTypeRef extends TypeReference [RawInput ]
41
32
42
- private def toSidebar (r : RawInput )(using CompilerContext ): Sidebar . Child = r match
33
+ private def toSidebar (r : RawInput )(using CompilerContext ): Sidebar = r match
43
34
case RawInput (title, page, index, subsection, dir, hidden) if page.nonEmpty && index.isEmpty && subsection.isEmpty() =>
44
35
Sidebar .Page (Option .when(title.nonEmpty)(title), page, hidden)
45
36
case RawInput (title, page, index, subsection, dir, hidden) if page.isEmpty && (! subsection.isEmpty() || ! index.isEmpty()) =>
@@ -49,43 +40,43 @@ object Sidebar:
49
40
Sidebar .Page (None , page, hidden)
50
41
51
42
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.
56
46
|
57
47
|<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
62
52
| - <subsection> | <page>
63
53
| # either index or subsection needs to be present
64
54
|<page>:
65
- | title: <string> # optional
55
+ | title: <string> # optional - Default value is file name. Title can be also set using front-matter.
66
56
| page: <string>
67
- | hidden: <boolean> # optional
57
+ | hidden: <boolean> # optional - Default value is false.
68
58
|
69
59
|For more information visit:
70
60
|https://docs.scala-lang.org/scala3/guides/scaladoc/static-site.html
71
61
| """ .stripMargin
72
62
73
- def load (content : String | java.io.File )(using CompilerContext ): Sidebar .Root =
63
+ def load (content : String | java.io.File )(using CompilerContext ): Sidebar .Category =
74
64
import scala .util .Try
75
65
val mapper = ObjectMapper (YAMLFactory ())
76
66
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 )
79
69
80
- val root : RawRoot = Try (readValue)
70
+ val root : RawInput = Try (readValue)
81
71
.fold(
82
72
{ e =>
83
73
report.warn(schemaMessage, e)
84
- RawRoot ( " " , java.util. Collections .emptyList() )
74
+ new RawInput ( )
85
75
},
86
76
identity
87
77
)
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