diff --git a/scala3doc/src/dotty/dokka/site/StaticSiteLocationProvider.scala b/scala3doc/src/dotty/dokka/site/StaticSiteLocationProvider.scala index 1d5cdd68c642..f392c3f0eeb0 100644 --- a/scala3doc/src/dotty/dokka/site/StaticSiteLocationProvider.scala +++ b/scala3doc/src/dotty/dokka/site/StaticSiteLocationProvider.scala @@ -30,6 +30,10 @@ class StaticSiteLocationProvider(pageNode: RootPageNode)(using ctx: DokkaContext extends DokkaLocationProvider(pageNode, ctx, ".html"): private def updatePageEntry(page: PageNode, jpath: JList[String]): JList[String] = page match + case page: ContentPage if page.getDri.contains(docsDRI) => + JList("docs", "index") + case page: ContentPage if page.getDri.contains(docsRootDRI) => + JList("index") case page: StaticPageNode => summon[DocContext].staticSiteContext.fold(jpath) { context => val rawFilePath = context.root.toPath.relativize(page.template.file.toPath) @@ -55,8 +59,6 @@ class StaticSiteLocationProvider(pageNode: RootPageNode)(using ctx: DokkaContext } } - case page: ContentPage if page.getDri.contains(docsDRI) => - JList("docs", "index") case page: ContentPage if page.getDri.contains(apiPageDRI) => JList("api", "index") case _ if jpath.size() > 1 && jpath.get(0) == "--root--" && jpath.get(1) == "-a-p-i" => diff --git a/scala3doc/src/dotty/dokka/site/common.scala b/scala3doc/src/dotty/dokka/site/common.scala index c6b571288222..b2e0354d2f5d 100644 --- a/scala3doc/src/dotty/dokka/site/common.scala +++ b/scala3doc/src/dotty/dokka/site/common.scala @@ -22,8 +22,8 @@ import org.jetbrains.dokka.pages._ import scala.collection.JavaConverters._ -val docsRootDRI: DRI = mkDRI("_.docs") -val docsDRI: DRI = mkDRI(extra = "_docs_level_index") +val docsRootDRI: DRI = mkDRI("_.index.md") +val docsDRI: DRI = mkDRI("_.docs/index.md") val apiPageDRI: DRI = mkDRI(packageName = "api", extra = "__api__") val defaultMarkdownOptions: DataHolder = diff --git a/scala3doc/test-documentations/basic/index.md b/scala3doc/test-documentations/basic/index.md index 705503bfeb5b..e192044e06f8 100644 --- a/scala3doc/test-documentations/basic/index.md +++ b/scala3doc/test-documentations/basic/index.md @@ -3,4 +3,6 @@ title: Basic test --- # Header +[Link to docs](docs/index.html) [Link to docs2](docs/index.md) + And a text! \ No newline at end of file diff --git a/scala3doc/test/dotty/dokka/site/SiteGeneratationTest.scala b/scala3doc/test/dotty/dokka/site/SiteGeneratationTest.scala index 9180fd2f7bdf..06999b1fe721 100644 --- a/scala3doc/test/dotty/dokka/site/SiteGeneratationTest.scala +++ b/scala3doc/test/dotty/dokka/site/SiteGeneratationTest.scala @@ -41,6 +41,12 @@ class SiteGeneratationTest: val found = d.select(selector).eachText.asScala assertEquals(niceMsg(s"Context does not match for '$selector'"), expected.toList, found.toList) + def assertAttr(selector: String, attr: String, expected: String*) = + assertFalse(niceMsg("Selector not found"), d.select(selector).isEmpty) + val found = d.select(selector).eachAttr(attr).asScala + assertEquals(niceMsg(s"Attribute $attr does not match for '$selector'"), expected.toList, found.toList) + + def withHtmlFile(path: Path)(op: DocumentContext => Unit) = { assertTrue(s"File at $path does not exisits!", Files.exists(path)) val content = new String(Files.readAllBytes(path), Charset.defaultCharset()) @@ -51,16 +57,24 @@ class SiteGeneratationTest: @Test def basicTest() = withGeneratedSite(testDocPath.resolve("basic")){ dest => - def checkFile(path: String)(title: String, header: String, parents: Seq[String] = Nil) = - withHtmlFile(dest.resolve(path)){ content => - content.assertTextsIn(".projectName", projectName) - content.assertTextsIn(".projectVersion", projectVersion) - content.assertTextsIn("h1", header) - content.assertTextsIn("title", title) - content.assertTextsIn(".breadcrumbs a", (parents :+ title):_*) - } + def checkFile(path: String)( + title: String, + header: String, + parents: Seq[String] = Nil, + checks: DocumentContext => Unit = _ => ()) = + withHtmlFile(dest.resolve(path)){ content => + content.assertTextsIn(".projectName", projectName) + content.assertTextsIn(".projectVersion", projectVersion) + content.assertTextsIn("h1", header) + content.assertTextsIn("title", title) + content.assertTextsIn(".breadcrumbs a", (parents :+ title):_*) + checks(content) + } - checkFile("index.html")(title = "Basic test", header = "Header", parents = Seq(projectName)) + def indexLinks(content: DocumentContext) = + content.assertAttr("p a","href", "docs/index.html","docs/index.html" ) + + checkFile("index.html")(title = "Basic test", header = "Header", parents = Seq(projectName), indexLinks) checkFile("docs/Adoc.html")(title = "Adoc", header = "Header in Adoc", parents = Seq(projectName)) checkFile("docs/Adoc.html")(title = "Adoc", header = "Header in Adoc", parents = Seq(projectName)) checkFile("docs/dir/index.html")(title = "A directory", header = "A directory", parents = Seq(projectName)) @@ -68,4 +82,4 @@ class SiteGeneratationTest: title = "Nested in a directory", header = "Nested in a directory", parents = Seq(projectName, "A directory")) checkFile("docs/index.html")(title = projectName, header = s"$projectName in header") - } \ No newline at end of file + }