Skip to content

Commit 00de3af

Browse files
committed
docs/index page has proper title
1 parent d3698ee commit 00de3af

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

docs/docs/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
layout: doc-page
3-
title: "Dotty Documentation"
43
---
54

65
Dotty is the project name for technologies that are considered for inclusion in Scala 3. Scala has

scala3doc/src/dotty/dokka/site/LoadedTemplate.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ case class LoadedTemplate(templateFile: TemplateFile, children: List[LoadedTempl
4141

4242
def resolveToHtml(ctx: StaticSiteContext): ResolvedPage =
4343
val posts = children.map(_.lazyTemplateProperties(ctx))
44-
val site = templateFile.settings.getOrElse("site", Map.empty).asInstanceOf[Map[String, Object]]
44+
def getMap(key: String) = templateFile.settings.getOrElse(key, Map.empty).asInstanceOf[Map[String, Object]]
4545
val sourceLinks = if !file.exists() then Nil else
4646
// TODO (https://github.com/lampepfl/scala3doc/issues/240): configure source root
4747
// toRealPath is used to turn symlinks into proper paths
@@ -50,6 +50,7 @@ case class LoadedTemplate(templateFile: TemplateFile, children: List[LoadedTempl
5050
ctx.sourceLinks.pathTo(actualPath, operation = "edit").map("editSource" -> _ )
5151

5252
val updatedSettings = templateFile.settings ++ ctx.projectWideProperties +
53-
("site" -> (site + ("posts" -> posts))) + ("urls" -> sourceLinks.toMap)
53+
("site" -> (getMap("site") + ("posts" -> posts))) + ("urls" -> sourceLinks.toMap) +
54+
("page" -> (getMap("page") + ("title" -> templateFile.title)))
5455

5556
templateFile.resolveInner(RenderingContext(updatedSettings, ctx.layouts))

scala3doc/src/dotty/dokka/site/StaticSiteContext.scala

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import util.Try
2020

2121
import scala.collection.JavaConverters._
2222

23-
class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], args: Args, val sourceLinks: SourceLinks):
23+
class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], val args: Args, val sourceLinks: SourceLinks):
2424

2525
var memberLinkResolver: String => Option[DRI] = _ => None
2626

@@ -81,16 +81,15 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], args:
8181
val topLevelFiles = if isBlog then Seq(from, new File(from, "_posts")) else Seq(from)
8282
val allFiles = topLevelFiles.filter(_.isDirectory).flatMap(_.listFiles())
8383
val (indexes, children) = allFiles.flatMap(loadTemplate(_)).partition(_.templateFile.isIndexPage())
84-
if (indexes.size > 1)
85-
// TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
86-
println(s"ERROR: Multiple index pages for $from found in ${indexes.map(_.file)}")
84+
8785
def loadIndexPage(): TemplateFile =
88-
val indexFiles = from.listFiles { file =>file.getName == "index.md" || file.getName == "index.html" }
89-
indexFiles.size match
90-
case 0 => emptyTemplate(from, from.getName)
91-
case 1 => loadTemplateFile(indexFiles.head).copy(file = from)
86+
val indexFiles = from.listFiles { file => file.getName == "index.md" || file.getName == "index.html" }
87+
indexes match
88+
case Nil => emptyTemplate(from, from.getName)
89+
case Seq(loadedTemplate) => loadedTemplate.templateFile.copy(file = from)
9290
case _ =>
93-
val msg = s"ERROR: Multiple index pages found under ${from.toPath}"
91+
// TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
92+
val msg = s"ERROR: Multiple index pages for $from found in ${indexes.map(_.file)}"
9493
throw new java.lang.RuntimeException(msg)
9594

9695
val templateFile = if (from.isDirectory) loadIndexPage() else loadTemplateFile(from)
@@ -101,7 +100,15 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], args:
101100
pageSettings.flatMap(_.get("date").collect{ case s: String => s}).getOrElse("1900-01-01") // blogs without date are last
102101
children.sortBy(dateFrom).reverse
103102

104-
Some(LoadedTemplate(templateFile, processedChildren.toList, from))
103+
val processedTemplate = // Set provided name as arg in page for `docs`
104+
if from.getParentFile.toPath == docsPath && templateFile.isIndexPage() then
105+
// TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
106+
if templateFile.title != "index" then println(s"[WARN] title in $from will be overriden")
107+
val projectTitle = args.projectTitle.getOrElse(args.name)
108+
templateFile.copy(title = projectTitle)
109+
else templateFile
110+
111+
Some(LoadedTemplate(processedTemplate, processedChildren.toList, from))
105112
catch
106113
case e: RuntimeException =>
107114
// TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling

scala3doc/src/dotty/dokka/site/common.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def loadTemplateFile(file: File): TemplateFile = {
7474
def getSettingValue(k: String, v: JList[String]): String | List[String] =
7575
if v.size == 1 then v.get(0) else v.asScala.toList
7676

77-
val globalKeys = Set("extraJS", "extraCSS", "layout", "hasFrame", "name")
77+
val globalKeys = Set("extraJS", "extraCSS", "layout", "hasFrame", "name", "title")
7878
val allSettings = yamlCollector.getData.asScala.toMap.transform(getSettingValue)
7979
val (global, inner) = allSettings.partition((k,_) => globalKeys.contains(k))
8080
val settings = Map("page" -> inner)

scala3doc/src/dotty/dokka/site/processors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class SitePagesCreator(ctx: Option[StaticSiteContext]) extends BaseStaticSitePro
100100
val rootContent = indexes.headOption.fold(ctx.asContent(Text(), mkDRI(extra = "root_content")).get(0))(_.getContent)
101101

102102
val root = AContentPage(
103-
input.getName,
103+
ctx.args.projectTitle.getOrElse(ctx.args.name),
104104
(List(modifiedModuleRoot.modified("API", modifiedModuleRoot.getChildren)) ++ children).asJava,
105105
rootContent,
106106
JSet(docsDRI),

0 commit comments

Comments
 (0)