Skip to content

Commit 2b835d7

Browse files
committed
Add the asApiLink function to verify if the API link is valid and if we trigger or not the warning
1 parent f28d708 commit 2b835d7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,26 @@ trait SiteRenderer(using DocContext) extends Locations:
4747
resolveLink(pageDri, str.stripPrefix("/"))
4848
)
4949
def asStaticSite: Option[String] = tryAsDri(str)
50+
def asApiLink: Option[String] =
51+
{
52+
val strWithoutHtml = str.stripSuffix(".html").stripPrefix("/")
53+
val sourceDir = Paths.get("src", "main", "scala")
54+
val scalaPath = sourceDir.resolve(s"$strWithoutHtml.scala")
55+
val scalaDirPath = sourceDir.resolve(strWithoutHtml)
56+
Option.when(Files.exists(scalaPath)|| Files.exists(scalaDirPath))(resolveLink(pageDri, str))
57+
}
5058

5159
/* Link resolving checks performs multiple strategies with following priority:
5260
1. We check if the link is a valid URL e.g. http://dotty.epfl.ch
5361
2. We check if the link leads to other static site
5462
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
5564
*/
5665

5766
asValidURL
5867
.orElse(asStaticSite)
5968
.orElse(asAsset)
69+
.orElse(asApiLink)
6070
.getOrElse {
6171
report.warn(s"Unable to resolve link '$str'", content.template.templateFile.file)
6272
str

0 commit comments

Comments
 (0)