@@ -8,6 +8,7 @@ import scala.jdk.CollectionConverters._
8
8
import java .util .Optional
9
9
import scala .beans ._
10
10
import java .nio .file .{Files , Paths }
11
+ import scala .io .Source
11
12
12
13
enum Sidebar :
13
14
case Category (
@@ -31,6 +32,17 @@ object Sidebar:
31
32
32
33
private object RawInputTypeRef extends TypeReference [RawInput ]
33
34
35
+ private def pageWithNoTitle (content : String | java.io.File ): String =
36
+ val fileContent = content match {
37
+ case file : java.io.File => Source .fromFile(file).getLines().mkString(" \n " )
38
+ case str : String => str
39
+ }
40
+ val lines = fileContent.split(" \n " )
41
+ lines.zipWithIndex
42
+ .find { case (line, i) => line.trim.startsWith(" page:" ) && ! lines(i - 1 ).contains(" - title:" ) }
43
+ .map(_._1.trim.stripPrefix(" page:" ))
44
+ .getOrElse(" " )
45
+
34
46
private def toSidebar (r : RawInput , content : String | java.io.File )(using CompilerContext ): Sidebar = r match
35
47
case RawInput (title, page, index, subsection, dir, hidden) if page.nonEmpty && index.isEmpty && subsection.isEmpty() =>
36
48
val sidebarPath = content match
@@ -44,14 +56,15 @@ object Sidebar:
44
56
case RawInput (title, page, index, subsection, dir, hidden) if page.isEmpty && (! subsection.isEmpty() || ! index.isEmpty()) =>
45
57
Sidebar .Category (Option .when(title.nonEmpty)(title), Option .when(index.nonEmpty)(index), subsection.asScala.map(toSidebar(_, content)).toList, Option .when(dir.nonEmpty)(dir))
46
58
case RawInput (title, page, index, subsection, dir, hidden) =>
47
- if title.isEmpty() then
48
- val msg = s " Error parsing YAML configuration file: 'title' is not provided. "
59
+ if title.isEmpty() && index.isEmpty() then
60
+ val page = pageWithNoTitle(content).trim()
61
+ val msg = s " Error parsing YAML configuration file: 'title' is not provided for page ' $page'. "
49
62
report.error(s " $msg\n $schemaMessage" )
50
63
else if title.nonEmpty && (page.isEmpty() || index.isEmpty()) then
51
64
val msg = s " Error parsing YAML configuration file: 'index' or 'page' path is missing for title ' $title'. "
52
65
report.error(s " $msg\n $schemaMessage" )
53
66
else
54
- val msg = s " The parsing seems not to have been done correctly ."
67
+ val msg = s " Error parsing YAML configuration file ."
55
68
report.warning(s " $msg\n $schemaMessage" )
56
69
Sidebar .Page (None , page, hidden)
57
70
0 commit comments