Skip to content

Correctly link to docs from index page #10682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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" =>
Expand Down
4 changes: 2 additions & 2 deletions scala3doc/src/dotty/dokka/site/common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions scala3doc/test-documentations/basic/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ title: Basic test
---
# Header

[Link to docs](docs/index.html) [Link to docs2](docs/index.md)

And a text!
34 changes: 24 additions & 10 deletions scala3doc/test/dotty/dokka/site/SiteGeneratationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -51,21 +57,29 @@ 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))
checkFile("docs/dir/nested.html")(
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")
}
}