Skip to content

Commit ad5f3c9

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 7aab896 commit ad5f3c9

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
@@ -46,16 +46,26 @@ trait SiteRenderer(using DocContext) extends Locations:
4646
resolveLink(pageDri, str.stripPrefix("/"))
4747
)
4848
def asStaticSite: Option[String] = tryAsDri(str)
49+
def asApiLink: Option[String] =
50+
{
51+
val strWithoutHtml = str.stripSuffix(".html").stripPrefix("/")
52+
val sourceDir = Paths.get("src", "main", "scala")
53+
val scalaPath = sourceDir.resolve(s"$strWithoutHtml.scala")
54+
val scalaDirPath = sourceDir.resolve(strWithoutHtml)
55+
Option.when(Files.exists(scalaPath)|| Files.exists(scalaDirPath))(resolveLink(pageDri, str))
56+
}
4957

5058
/* Link resolving checks performs multiple strategies with following priority:
5159
1. We check if the link is a valid URL e.g. http://dotty.epfl.ch
5260
2. We check if the link leads to other static site
5361
3. We check if the link leads to existing asset e.g. images/logo.svg -> <static-site-root>/_assets/images/logo.svg
62+
4. We check if the link leads to existing API page
5463
*/
5564

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

0 commit comments

Comments
 (0)