@@ -7,6 +7,8 @@ import com.fasterxml.jackson.core.`type`.TypeReference;
77import scala .jdk .CollectionConverters ._
88import java .util .Optional
99import scala .beans ._
10+ import java .nio .file .{Files , Paths }
11+ import scala .io .Source
1012
1113enum Sidebar :
1214 case Category (
@@ -30,16 +32,31 @@ object Sidebar:
3032
3133 private object RawInputTypeRef extends TypeReference [RawInput ]
3234
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
3436 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. " )
3544 Sidebar .Page (Option .when(title.nonEmpty)(title), page, hidden)
3645 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))
3847 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" )
4057 Sidebar .Page (None , page, hidden)
4158
42- private def schemaMessage : String =
59+ def schemaMessage : String =
4360 s """ Static site YAML configuration file should comply with the following description:
4461 |The root element of static site needs to be <subsection>
4562 |`title` and `directory` properties are ignored in root subsection.
@@ -57,8 +74,7 @@ object Sidebar:
5774 | hidden: <boolean> # optional - Default value is false.
5875 |
5976 |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
6278
6379 def load (content : String | java.io.File )(using CompilerContext ): Sidebar .Category =
6480 import scala .util .Try
@@ -75,7 +91,7 @@ object Sidebar:
7591 },
7692 identity
7793 )
78- toSidebar(root) match
94+ toSidebar(root, content ) match
7995 case c : Sidebar .Category => c
8096 case _ =>
8197 report.error(s " Root element is not a subsection. \n $schemaMessage" )
0 commit comments