@@ -7,6 +7,7 @@ import com.fasterxml.jackson.core.`type`.TypeReference;
7
7
import scala .jdk .CollectionConverters ._
8
8
import java .util .Optional
9
9
import scala .beans ._
10
+ import java .nio .file .{Files , Paths }
10
11
11
12
enum Sidebar :
12
13
case Category (
@@ -30,13 +31,26 @@ object Sidebar:
30
31
31
32
private object RawInputTypeRef extends TypeReference [RawInput ]
32
33
33
- private def toSidebar (r : RawInput )(using CompilerContext ): Sidebar = r match
34
+ private def toSidebar (r : RawInput , content : String | java.io. File )(using CompilerContext ): Sidebar = r match
34
35
case RawInput (title, page, index, subsection, dir, hidden) if page.nonEmpty && index.isEmpty && subsection.isEmpty() =>
36
+ val sidebarPath = content match
37
+ case s : String => Paths .get(s)
38
+ case f : java.io.File => f.toPath()
39
+ val basePath = sidebarPath.getParent().resolve(" _docs" )
40
+ val pagePath = basePath.resolve(page)
41
+ if ! Files .exists(pagePath) then
42
+ report.error(s " Page $page does not exist. " )
35
43
Sidebar .Page (Option .when(title.nonEmpty)(title), page, hidden)
36
44
case RawInput (title, page, index, subsection, dir, hidden) if page.isEmpty && (! subsection.isEmpty() || ! index.isEmpty()) =>
37
- Sidebar .Category (Option .when(title.nonEmpty)(title), Option .when(index.nonEmpty)(index), subsection.asScala.map(toSidebar).toList, Option .when(dir.nonEmpty)(dir))
45
+ Sidebar .Category (Option .when(title.nonEmpty)(title), Option .when(index.nonEmpty)(index), subsection.asScala.map(toSidebar(_, content) ).toList, Option .when(dir.nonEmpty)(dir))
38
46
case RawInput (title, page, index, subsection, dir, hidden) =>
39
- report.error(s " Error parsing YAML configuration file. \n $schemaMessage" )
47
+ val errors = (title.isEmpty(), page.isEmpty(), index.isEmpty(), subsection.isEmpty(), dir.isEmpty())
48
+ errors match
49
+ case (true , _, _, _, _) =>
50
+ report.error(s " Title is not provided. \n $schemaMessage" )
51
+ case (false , true , true , _, _) =>
52
+ report.error(s " Index or page path to at least one page is missing. \n $schemaMessage" )
53
+ case _ => report.error(s " Error parsing YAML configuration file. \n $schemaMessage" )
40
54
Sidebar .Page (None , page, hidden)
41
55
42
56
private def schemaMessage : String =
@@ -75,7 +89,7 @@ object Sidebar:
75
89
},
76
90
identity
77
91
)
78
- toSidebar(root) match
92
+ toSidebar(root, content ) match
79
93
case c : Sidebar .Category => c
80
94
case _ =>
81
95
report.error(s " Root element is not a subsection. \n $schemaMessage" )
0 commit comments