File tree Expand file tree Collapse file tree 4 files changed +27
-3
lines changed
src/dotty/tools/scaladoc/site
test/dotty/tools/scaladoc/site Expand file tree Collapse file tree 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
6363def loadTemplateFile (file : File , defaultTitle : Option [TemplateName ] = None )(using ctx : StaticSiteContext ): TemplateFile = {
6464 val lines = Files .readAllLines(file.toPath).asScala.toList
6565
66- val (config, content) = if (lines.head == ConfigSeparator ) {
66+ val (config, content) = if (! lines.isEmpty && lines.head == ConfigSeparator ) {
6767 // Taking the second occurrence of ConfigSeparator.
6868 // 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 )
7176 } else (Nil , lines)
7277
7378 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:
9595 testApiPages(mainTitle = projectName, parents = Nil , hasToplevelIndexIndex = false )
9696 }
9797
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+
98114 @ Test
99115 def staticLinking () = withGeneratedSite(testDocPath.resolve(" static-links" )){
100116
You can’t perform that action at this time.
0 commit comments