Skip to content

Commit 4c5fd8e

Browse files
committed
Correction: Use the DRI instead of the regular path
1 parent cd95561 commit 4c5fd8e

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java.nio.file.Path
1313
import java.nio.file.Files
1414
import java.io.File
1515
import scala.util.chaining._
16+
import javax.print.Doc
1617

1718
case class ResolvedTemplate(template: LoadedTemplate, ctx: StaticSiteContext):
1819
val resolved = template.resolveToHtml(ctx)
@@ -30,9 +31,15 @@ trait SiteRenderer(using DocContext) extends Locations:
3031
def siteContent(pageDri: DRI, content: ResolvedTemplate): PageContent =
3132
import content.ctx
3233
def tryAsDri(str: String): Option[String] =
33-
val (path, prefix) = str match
34+
val newStr =
35+
str.dropWhile(c => c == '.' || c == '/').replaceAll("/", ".") match
36+
case str if str.endsWith("$.html") => str.stripSuffix("$.html")
37+
case str if str.endsWith(".html") => str.stripSuffix(".html")
38+
case _ => str
39+
40+
val (path, prefix) = newStr match
3441
case HashRegex(path, prefix) => (path, prefix)
35-
case _ => (str, "")
42+
case _ => (newStr, "")
3643

3744
val res = ctx.driForLink(content.template.file, path).filter(driExists)
3845
res.headOption.map(pathToPage(pageDri, _) + prefix)
@@ -46,27 +53,16 @@ trait SiteRenderer(using DocContext) extends Locations:
4653
resolveLink(pageDri, str.stripPrefix("/"))
4754
)
4855
def asStaticSite: Option[String] = tryAsDri(str)
49-
def asApiLink: Option[String] =
50-
val strWithoutHtml = if str.endsWith("$.html") then
51-
str.stripSuffix("$.html")
52-
else
53-
str.stripSuffix(".html")
54-
val sourceDir = Paths.get("src", "main", "scala")
55-
val scalaPath = sourceDir.resolve(s"$strWithoutHtml.scala")
56-
val scalaDirPath = sourceDir.resolve(strWithoutHtml)
57-
Option.when(Files.exists(scalaPath)|| Files.exists(scalaDirPath))(resolveLink(pageDri, str))
5856

5957
/* Link resolving checks performs multiple strategies with following priority:
6058
1. We check if the link is a valid URL e.g. http://dotty.epfl.ch
61-
2. We check if the link leads to other static site
59+
2. We check if the link leads to other static site or API pages, example: [[exemple.scala.Foo]] || [Foo](../exemple/scala/Foo.html)
6260
3. We check if the link leads to existing asset e.g. images/logo.svg -> <static-site-root>/_assets/images/logo.svg
63-
4. We check if the link leads to existing API page
6461
*/
6562

6663
asValidURL
6764
.orElse(asStaticSite)
6865
.orElse(asAsset)
69-
.orElse(asApiLink)
7066
.getOrElse {
7167
report.warn(s"Unable to resolve link '$str'", content.template.templateFile.file)
7268
str

0 commit comments

Comments
 (0)