Skip to content

Commit 1a382cf

Browse files
committed
URL in documentaion now matches files layout
1 parent dd2c092 commit 1a382cf

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

scala3doc/scala3-docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</a>
2121
</li>
2222
<li class="nav-item">
23-
<a class="nav-link" href="docs/blog/index.html">
23+
<a class="nav-link" href="blog/index.html">
2424
Blog
2525
</a>
2626
</li>

scala3doc/src/dotty/dokka/DottyDokkaPlugin.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
168168
.overrideExtension(dokkaBase.getLocationProvider)
169169
)
170170

171-
extension (ctx: DokkaContext):
172-
def siteContext: Option[StaticSiteContext] = ctx.getConfiguration.asInstanceOf[DottyDokkaConfig].staticSiteContext
173-
def args: Args = ctx.getConfiguration.asInstanceOf[DottyDokkaConfig].docConfiguration.args
171+
extension (ctx: DokkaContext):
172+
def siteContext: Option[StaticSiteContext] = ctx.getConfiguration.asInstanceOf[DottyDokkaConfig].staticSiteContext
173+
def args: Args = ctx.getConfiguration.asInstanceOf[DottyDokkaConfig].docConfiguration.args
174174

175175
// TODO (https://github.com/lampepfl/scala3doc/issues/232): remove once problem is fixed in Dokka
176176
extension [T] (builder: ExtensionBuilder[T]):

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], args:
128128

129129
case Sidebar.Category(title, nested) =>
130130
// Add support for index.html/index.md files!
131-
val fakeFile = new File(root, title)
131+
val fakeFile = new File(new File(root, "docs"), title)
132132
LoadedTemplate(emptyTemplate(fakeFile, title), nested.map(loadSidebarContent), fakeFile)
133133

134134
private def loadAllFiles() =

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,40 @@ class StaticSiteLocationProvider(ctx: DokkaContext, pageNode: RootPageNode)
2020
private def updatePageEntry(page: PageNode, jpath: JList[String]): JList[String] =
2121
page match
2222
case page: StaticPageNode =>
23-
if (page.getDri.contains(docsRootDRI)) JList("index")
24-
else {
25-
val path = jpath.asScala.toList
26-
val start = if (path.head == "--root--") List("docs") else path.take(1)
27-
// Dokka has a bug in location provider that does not properly handles relative paths for leaf nodes
28-
// This forces us to not change default paths on non-leaf nodes
29-
val newName = if page.getChildren.size() > 0 then path.last else
30-
val pageName = page.template.file.getName
31-
val dotIndex = pageName.lastIndexOf('.')
32-
if (dotIndex < 0) pageName else pageName.substring(0, dotIndex)
33-
34-
println(s"Using $newName for ${page.template.file} orignally: $path")
35-
36-
(start ++ path.drop(1).dropRight(1) ++ List(newName)).asJava
23+
ctx.siteContext.fold(jpath) { context =>
24+
val rawFilePath = context.root.toPath.relativize(page.template.file.toPath)
25+
val pageName = page.template.file.getName
26+
val dotIndex = pageName.lastIndexOf('.')
27+
val newPath =
28+
if (dotIndex < 0) rawFilePath.resolve("index")
29+
else rawFilePath.resolveSibling(pageName.substring(0, dotIndex))
30+
31+
newPath.iterator.asScala.map(_.toString).toList.asJava
3732
}
33+
3834
case page: ContentPage if page.getDri.contains(docsDRI) =>
39-
JList("docs")
35+
JList("docs", "index")
4036
case page: ContentPage if page.getDri.contains(apiPageDRI) =>
4137
JList("api", "index")
4238
case _ if jpath.size() > 1 && jpath.get(0) == "--root--" && jpath.get(1) == "-a-p-i" =>
4339
(List("api") ++ jpath.asScala.drop(2)).asJava
40+
41+
case _: org.jetbrains.dokka.pages.ModulePage if ctx.siteContext.isEmpty =>
42+
JList("index")
4443
case _ =>
4544
jpath
4645

4746
override val getPathsIndex: JMap[PageNode, JList[String]] =
4847
super.getPathsIndex.asScala.mapValuesInPlace(updatePageEntry).asJava
48+
49+
50+
override def pathTo(node: PageNode, context: PageNode): String =
51+
val nodePaths = getPathsIndex.get(node).asScala
52+
val contextPaths = Option(context).fold(Nil)(getPathsIndex.get(_).asScala.dropRight(1))
53+
val commonPaths = nodePaths.zip(contextPaths).takeWhile{ case (a, b) => a == b }.size
54+
55+
val contextPath = contextPaths.drop(commonPaths).map(_ => "..")
56+
val nodePath = nodePaths.drop(commonPaths) match
57+
case l if l.isEmpty => Seq("index")
58+
case l => l
59+
(contextPath ++ nodePath).mkString("/")

0 commit comments

Comments
 (0)