diff options
Diffstat (limited to 'doc-tool')
3 files changed, 12 insertions, 9 deletions
diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala index 556818007..965ded4f8 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Page.scala @@ -9,7 +9,7 @@ import dotc.config.Printers.dottydoc import com.vladsch.flexmark.html.HtmlRenderer import com.vladsch.flexmark.parser.Parser import com.vladsch.flexmark.ext.front.matter.AbstractYamlFrontMatterVisitor -import _root_.java.util.{ Map => JMap } +import _root_.java.util.{ Map => JMap, List => JList } case class IllegalFrontMatter(message: String) extends Exception(message) @@ -20,7 +20,7 @@ trait Page { def pageContent: String def params: Map[String, AnyRef] - def yaml(implicit ctx: Context): Map[String, String] = { + def yaml(implicit ctx: Context): Map[String, AnyRef] = { if (_yaml eq null) initFields() _yaml } @@ -30,7 +30,7 @@ trait Page { _html } - protected[this] var _yaml: Map[String, String] = _ + protected[this] var _yaml: Map[String, AnyRef /* String | JList[String] */] = _ protected[this] var _html: String = _ protected[this] def initFields()(implicit ctx: Context) = { val md = Parser.builder(ctx.docbase.markdownOptions).build.parse(pageContent) @@ -40,7 +40,10 @@ trait Page { _yaml = updatedYaml { yamlCollector .getData().asScala - .mapValues(_.asScala.headOption.getOrElse("")) + .mapValues { + case xs if xs.size == 1 => xs.get(0) + case xs => xs + } .toMap } @@ -67,11 +70,11 @@ trait Page { * removes "layout" from the parameters if it exists. We don't want to * preserve the layout from the previously expanded template */ - private def updatedYaml(newYaml: Map[String, String]): Map[String, String] = + private def updatedYaml(newYaml: Map[String, AnyRef]): Map[String, AnyRef] = params .get("page") .flatMap { - case page: Map[String, String] @unchecked => + case page: Map[String, AnyRef] @unchecked => Some(page - "layout" ++ newYaml) case _ => None } diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala index 8aee6f346..f2ecc6350 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala @@ -262,7 +262,7 @@ case class Site(val root: JFile, val docs: JList[_]) extends ResourceFinder { * expansion of the template with all its layouts and includes. */ def render(page: Page, params: Map[String, AnyRef] = Map.empty)(implicit ctx: Context): String = - page.yaml.get("layout").flatMap(layouts.get(_)) match { + page.yaml.get("layout").flatMap(xs => layouts.get(xs.toString)) match { case None => page.html case Some(layout) => diff --git a/doc-tool/test/dotty/tools/dottydoc/staticsite/PageTests.scala b/doc-tool/test/dotty/tools/dottydoc/staticsite/PageTests.scala index 6f20e28c2..3dab4f02c 100644 --- a/doc-tool/test/dotty/tools/dottydoc/staticsite/PageTests.scala +++ b/doc-tool/test/dotty/tools/dottydoc/staticsite/PageTests.scala @@ -20,7 +20,7 @@ class PageTests extends DottyDocTest { ) assert( - page.yaml == Map("key" -> ""), + page.yaml == Map("key" -> List.empty.asJava), s"""incorrect yaml, expected "key:" without key in: ${page.yaml}""" ) @@ -39,7 +39,7 @@ class PageTests extends DottyDocTest { ) assert( - page1.yaml == Map("key" -> ""), + page1.yaml == Map("key" -> List.empty.asJava), s"""incorrect yaml, expected "key:" without key in: ${page1.yaml}""" ) |