File tree 4 files changed +27
-3
lines changed
src/dotty/tools/scaladoc/site
test/dotty/tools/scaladoc/site 4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -63,11 +63,16 @@ def yamlParser(using ctx: StaticSiteContext): Parser = Parser.builder(defaultMar
63
63
def loadTemplateFile (file : File , defaultTitle : Option [TemplateName ] = None )(using ctx : StaticSiteContext ): TemplateFile = {
64
64
val lines = Files .readAllLines(file.toPath).asScala.toList
65
65
66
- val (config, content) = if (lines.head == ConfigSeparator ) {
66
+ val (config, content) = if (! lines.isEmpty && lines.head == ConfigSeparator ) {
67
67
// Taking the second occurrence of ConfigSeparator.
68
68
// The rest may appear within the content.
69
- val index = lines.drop(1 ).indexOf(ConfigSeparator ) + 2
70
- (lines.take(index), lines.drop(index))
69
+ val secondSeparatorIndex = lines.drop(1 ).indexOf(ConfigSeparator )
70
+ if secondSeparatorIndex != - 1 then
71
+ (lines.take(secondSeparatorIndex + 2 ), lines.drop(secondSeparatorIndex + 2 ))
72
+ else
73
+ // If there is no second occurrence of ConfigSeparator, we assume that the
74
+ // whole file is config.
75
+ (lines.tail, Nil )
71
76
} else (Nil , lines)
72
77
73
78
val configParsed = yamlParser.parse(config.mkString(LineSeparator ))
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : My page
3
+ foo : bar
Original file line number Diff line number Diff line change @@ -95,6 +95,22 @@ class SiteGeneratationTest extends BaseHtmlTest:
95
95
testApiPages(mainTitle = projectName, parents = Nil , hasToplevelIndexIndex = false )
96
96
}
97
97
98
+ @ Test
99
+ def emptyPage () = withGeneratedSite(testDocPath.resolve(" emptyPage" )){
100
+ withHtmlFile(" docs/hello.html" ) { content =>
101
+ // There should be no content as the page body is empty.
102
+ content.assertTextsIn(" #content" , Nil * )
103
+ }
104
+ }
105
+
106
+ @ Test
107
+ def noConfigEnd () = withGeneratedSite(testDocPath.resolve(" noConfigEnd" )){
108
+ withHtmlFile(" docs/hello.html" ) { content =>
109
+ // There should be no content as the page body is empty.
110
+ content.assertTextsIn(" #content" , Nil * )
111
+ }
112
+ }
113
+
98
114
@ Test
99
115
def staticLinking () = withGeneratedSite(testDocPath.resolve(" static-links" )){
100
116
You can’t perform that action at this time.
0 commit comments