diff --git a/scaladoc/src/dotty/tools/scaladoc/site/common.scala b/scaladoc/src/dotty/tools/scaladoc/site/common.scala index c0c959cf205c..0811d217537f 100644 --- a/scaladoc/src/dotty/tools/scaladoc/site/common.scala +++ b/scaladoc/src/dotty/tools/scaladoc/site/common.scala @@ -63,11 +63,16 @@ def yamlParser(using ctx: StaticSiteContext): Parser = Parser.builder(defaultMar def loadTemplateFile(file: File, defaultTitle: Option[TemplateName] = None)(using ctx: StaticSiteContext): TemplateFile = { val lines = Files.readAllLines(file.toPath).asScala.toList - val (config, content) = if (lines.head == ConfigSeparator) { + val (config, content) = if (!lines.isEmpty && lines.head == ConfigSeparator) { // Taking the second occurrence of ConfigSeparator. // The rest may appear within the content. - val index = lines.drop(1).indexOf(ConfigSeparator) + 2 - (lines.take(index), lines.drop(index)) + val secondSeparatorIndex = lines.drop(1).indexOf(ConfigSeparator) + if secondSeparatorIndex != -1 then + (lines.take(secondSeparatorIndex + 2), lines.drop(secondSeparatorIndex + 2)) + else + // If there is no second occurrence of ConfigSeparator, we assume that the + // whole file is config. + (lines.tail, Nil) } else (Nil, lines) val configParsed = yamlParser.parse(config.mkString(LineSeparator)) diff --git a/scaladoc/test-documentations/emptyPage/_docs/hello.md b/scaladoc/test-documentations/emptyPage/_docs/hello.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/scaladoc/test-documentations/noConfigEnd/_docs/hello.md b/scaladoc/test-documentations/noConfigEnd/_docs/hello.md new file mode 100644 index 000000000000..3809c65bce02 --- /dev/null +++ b/scaladoc/test-documentations/noConfigEnd/_docs/hello.md @@ -0,0 +1,3 @@ +--- +title: My page +foo: bar diff --git a/scaladoc/test/dotty/tools/scaladoc/site/SiteGeneratationTest.scala b/scaladoc/test/dotty/tools/scaladoc/site/SiteGeneratationTest.scala index 7ce16933997a..e012044156cc 100644 --- a/scaladoc/test/dotty/tools/scaladoc/site/SiteGeneratationTest.scala +++ b/scaladoc/test/dotty/tools/scaladoc/site/SiteGeneratationTest.scala @@ -95,6 +95,22 @@ class SiteGeneratationTest extends BaseHtmlTest: testApiPages(mainTitle = projectName, parents = Nil, hasToplevelIndexIndex = false) } + @Test + def emptyPage() = withGeneratedSite(testDocPath.resolve("emptyPage")){ + withHtmlFile("docs/hello.html") { content => + // There should be no content as the page body is empty. + content.assertTextsIn("#content", Nil*) + } + } + + @Test + def noConfigEnd() = withGeneratedSite(testDocPath.resolve("noConfigEnd")){ + withHtmlFile("docs/hello.html") { content => + // There should be no content as the page body is empty. + content.assertTextsIn("#content", Nil*) + } + } + @Test def staticLinking() = withGeneratedSite(testDocPath.resolve("static-links")){