@@ -7,6 +7,8 @@ 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 }
11
+ import scala .io .Source
10
12
11
13
enum Sidebar :
12
14
case Category (
@@ -30,16 +32,31 @@ object Sidebar:
30
32
31
33
private object RawInputTypeRef extends TypeReference [RawInput ]
32
34
33
- private def toSidebar (r : RawInput )(using CompilerContext ): Sidebar = r match
35
+ private def toSidebar (r : RawInput , content : String | java.io. File )(using CompilerContext ): Sidebar = r match
34
36
case RawInput (title, page, index, subsection, dir, hidden) if page.nonEmpty && index.isEmpty && subsection.isEmpty() =>
37
+ val sidebarPath = content match
38
+ case s : String => Paths .get(s)
39
+ case f : java.io.File => f.toPath()
40
+ val basePath = sidebarPath.getParent().resolve(" _docs" )
41
+ val pagePath = basePath.resolve(page)
42
+ if ! Files .exists(pagePath) then
43
+ report.error(s " Page $page does not exist. " )
35
44
Sidebar .Page (Option .when(title.nonEmpty)(title), page, hidden)
36
45
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))
46
+ Sidebar .Category (Option .when(title.nonEmpty)(title), Option .when(index.nonEmpty)(index), subsection.asScala.map(toSidebar(_, content) ).toList, Option .when(dir.nonEmpty)(dir))
38
47
case RawInput (title, page, index, subsection, dir, hidden) =>
39
- report.error(s " Error parsing YAML configuration file. \n $schemaMessage" )
48
+ if title.isEmpty() && index.isEmpty() then
49
+ val msg = " `title` property is missing for some page."
50
+ report.error(s " $msg\n $schemaMessage" )
51
+ else if title.nonEmpty && (page.isEmpty() || index.isEmpty()) then
52
+ val msg = s " Error parsing YAML configuration file: 'index' or 'page' path is missing for title ' $title'. "
53
+ report.error(s " $msg\n $schemaMessage" )
54
+ else
55
+ val msg = " Problem when parsing YAML configuration file."
56
+ report.warning(s " $msg\n $schemaMessage" )
40
57
Sidebar .Page (None , page, hidden)
41
58
42
- private def schemaMessage : String =
59
+ def schemaMessage : String =
43
60
s """ Static site YAML configuration file should comply with the following description:
44
61
|The root element of static site needs to be <subsection>
45
62
|`title` and `directory` properties are ignored in root subsection.
@@ -57,8 +74,7 @@ object Sidebar:
57
74
| hidden: <boolean> # optional - Default value is false.
58
75
|
59
76
|For more information visit:
60
- |https://docs.scala-lang.org/scala3/guides/scaladoc/static-site.html
61
- | """ .stripMargin
77
+ |https://docs.scala-lang.org/scala3/guides/scaladoc/static-site.html """ .stripMargin
62
78
63
79
def load (content : String | java.io.File )(using CompilerContext ): Sidebar .Category =
64
80
import scala .util .Try
@@ -75,7 +91,7 @@ object Sidebar:
75
91
},
76
92
identity
77
93
)
78
- toSidebar(root) match
94
+ toSidebar(root, content ) match
79
95
case c : Sidebar .Category => c
80
96
case _ =>
81
97
report.error(s " Root element is not a subsection. \n $schemaMessage" )
0 commit comments