From ad5f3c96ec9df1c1ea51a5bed255f6fa83f4f6be Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 14 Mar 2023 15:21:58 +0100 Subject: [PATCH 1/3] Add the asApiLink function to verify if the API link is valid and if we trigger or not the warning --- .../dotty/tools/scaladoc/renderers/SiteRenderer.scala | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala index ef7c06416e27..6d1f17d5f7cf 100644 --- a/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala @@ -46,16 +46,26 @@ trait SiteRenderer(using DocContext) extends Locations: resolveLink(pageDri, str.stripPrefix("/")) ) def asStaticSite: Option[String] = tryAsDri(str) + def asApiLink: Option[String] = + { + val strWithoutHtml = str.stripSuffix(".html").stripPrefix("/") + val sourceDir = Paths.get("src", "main", "scala") + val scalaPath = sourceDir.resolve(s"$strWithoutHtml.scala") + val scalaDirPath = sourceDir.resolve(strWithoutHtml) + Option.when(Files.exists(scalaPath)|| Files.exists(scalaDirPath))(resolveLink(pageDri, str)) + } /* Link resolving checks performs multiple strategies with following priority: 1. We check if the link is a valid URL e.g. http://dotty.epfl.ch 2. We check if the link leads to other static site 3. We check if the link leads to existing asset e.g. images/logo.svg -> /_assets/images/logo.svg + 4. We check if the link leads to existing API page */ asValidURL .orElse(asStaticSite) .orElse(asAsset) + .orElse(asApiLink) .getOrElse { report.warn(s"Unable to resolve link '$str'", content.template.templateFile.file) str From cd955615464d776adacf7f76e547ee6d0daea38b Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 16 May 2023 17:27:12 +0200 Subject: [PATCH 2/3] Try a correction to scala3 and for link to Object --- .../src/dotty/tools/scaladoc/renderers/SiteRenderer.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala index 6d1f17d5f7cf..830e297bc338 100644 --- a/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala @@ -47,13 +47,14 @@ trait SiteRenderer(using DocContext) extends Locations: ) def asStaticSite: Option[String] = tryAsDri(str) def asApiLink: Option[String] = - { - val strWithoutHtml = str.stripSuffix(".html").stripPrefix("/") + val strWithoutHtml = if str.endsWith("$.html") then + str.stripSuffix("$.html") + else + str.stripSuffix(".html") val sourceDir = Paths.get("src", "main", "scala") val scalaPath = sourceDir.resolve(s"$strWithoutHtml.scala") val scalaDirPath = sourceDir.resolve(strWithoutHtml) Option.when(Files.exists(scalaPath)|| Files.exists(scalaDirPath))(resolveLink(pageDri, str)) - } /* Link resolving checks performs multiple strategies with following priority: 1. We check if the link is a valid URL e.g. http://dotty.epfl.ch From 9c19d1c6347c96eeb5d13e5ca0982be9fb75bd59 Mon Sep 17 00:00:00 2001 From: Lucas Date: Wed, 7 Jun 2023 14:42:42 +0200 Subject: [PATCH 3/3] Correction: Use the DRI instead of the regular path --- .../scaladoc/renderers/SiteRenderer.scala | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala index 830e297bc338..1b82412cd724 100644 --- a/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala @@ -30,9 +30,15 @@ trait SiteRenderer(using DocContext) extends Locations: def siteContent(pageDri: DRI, content: ResolvedTemplate): PageContent = import content.ctx def tryAsDri(str: String): Option[String] = - val (path, prefix) = str match + val newStr = + str.dropWhile(c => c == '.' || c == '/').replaceAll("/", ".") match + case str if str.endsWith("$.html") => str.stripSuffix("$.html") + case str if str.endsWith(".html") => str.stripSuffix(".html") + case _ => str + + val (path, prefix) = newStr match case HashRegex(path, prefix) => (path, prefix) - case _ => (str, "") + case _ => (newStr, "") val res = ctx.driForLink(content.template.file, path).filter(driExists) res.headOption.map(pathToPage(pageDri, _) + prefix) @@ -46,27 +52,16 @@ trait SiteRenderer(using DocContext) extends Locations: resolveLink(pageDri, str.stripPrefix("/")) ) def asStaticSite: Option[String] = tryAsDri(str) - def asApiLink: Option[String] = - val strWithoutHtml = if str.endsWith("$.html") then - str.stripSuffix("$.html") - else - str.stripSuffix(".html") - val sourceDir = Paths.get("src", "main", "scala") - val scalaPath = sourceDir.resolve(s"$strWithoutHtml.scala") - val scalaDirPath = sourceDir.resolve(strWithoutHtml) - Option.when(Files.exists(scalaPath)|| Files.exists(scalaDirPath))(resolveLink(pageDri, str)) /* Link resolving checks performs multiple strategies with following priority: 1. We check if the link is a valid URL e.g. http://dotty.epfl.ch - 2. We check if the link leads to other static site + 2. We check if the link leads to other static site or API pages, example: [[exemple.scala.Foo]] || [Foo](../exemple/scala/Foo.html) 3. We check if the link leads to existing asset e.g. images/logo.svg -> /_assets/images/logo.svg - 4. We check if the link leads to existing API page */ asValidURL .orElse(asStaticSite) .orElse(asAsset) - .orElse(asApiLink) .getOrElse { report.warn(s"Unable to resolve link '$str'", content.template.templateFile.file) str