Skip to content

Commit da9afab

Browse files
authored
Merge pull request #10470 from romanowski/scala3doc/fix-links-in-docs
Make sure that we handle relative link correctly
2 parents 31c9ebe + cd18600 commit da9afab

7 files changed

+31
-15
lines changed

docs/blog/_posts/2017-07-12-second-dotty-milestone-release.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Today, we are excited to release Dotty version 0.2.0-RC1. This release
1010
serves as a technology preview that demonstrates new language features
1111
and the compiler supporting them.
1212

13-
This release is based on the [previous milestone](/blog/2017/05/31/first-dotty-milestone-release.html).
13+
This release is based on the [previous milestone](/blog/_posts/2017-05-31-first-dotty-milestone-release.html).
1414
The highlights of this release are:
1515
- substantial improvement of quality of generated code for pattern matching
1616
- improvements in VS Code IDE stability
@@ -24,7 +24,7 @@ The highlights of this release are:
2424
This is our second scheduled release according to our [6-week release schedule](https://dotty.epfl.ch/docs/usage/version-numbers.html).
2525

2626
## What’s in the 0.2.0-RC1 technology preview?
27-
The [previous technology preview](/blog/2017/05/31/first-dotty-milestone-release.html) has shipped new language features planned for Scala 3:
27+
The [previous technology preview](/blog/_posts/2017-05-31-first-dotty-milestone-release.html) has shipped new language features planned for Scala 3:
2828
[Intersection Types](https://dotty.epfl.ch/docs/reference/new-types/intersection-types.html),
2929
[Union Types](https://dotty.epfl.ch/docs/reference/new-types/union-types.html),
3030
[Trait Parameters](https://dotty.epfl.ch/docs/reference/other-new-features/trait-parameters.html),

docs/blog/_posts/2017-09-07-third-dotty-milestone-release.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You can learn more about Dotty on our [website](http://dotty.epfl.ch).
2020
<!--more-->
2121

2222
This is our third scheduled release according to our [6-week release schedule](https://dotty.epfl.ch/docs/usage/version-numbers.html).
23-
The [previous technology preview](/blog/2017/07/12/second-dotty-milestone-release.html) improved
23+
The [previous technology preview](/blog/_posts/2017-07-12-second-dotty-milestone-release.html) improved
2424
stability and reliability:
2525

2626
- substantial improvement of quality of generated code for pattern matching

docs/blog/_posts/2017-10-16-fourth-dotty-milestone-release.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You can learn more about Dotty on our [website](http://dotty.epfl.ch).
2020
<!--more-->
2121

2222
This is our fourth scheduled release according to our [6-week release schedule](https://dotty.epfl.ch/docs/usage/version-numbers.html).
23-
The [previous technology preview](/blog/2017/09/07/third-dotty-milestone-release.html) improved
23+
The [previous technology preview](/blog/_posts/2017-09-07-third-dotty-milestone-release.html) improved
2424
stability and reliability.
2525

2626
## What’s new in the 0.4.0-RC1 technology preview?

docs/blog/_posts/2017-12-01-fifth-dotty-milestone-release.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You can learn more about Dotty on our [website](http://dotty.epfl.ch).
2020
<!--more-->
2121

2222
This is our fifth scheduled release according to our [6-week release schedule](https://dotty.epfl.ch/docs/usage/version-numbers.html).
23-
The [previous technology preview](/blog/2017/10/16/fourth-dotty-milestone-release.html) added
23+
The [previous technology preview](/blog/_posts/2017-10-16-fourth-dotty-milestone-release.html) added
2424
support for Scala 2.12 and came with a brand new REPL.
2525

2626
## What’s new in the 0.5.0-RC1 technology preview?

docs/docs/reference/enums/desugarEnums.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ map into `case class`es or `val`s.
155155
case C(ps) extends P1, ..., Pn
156156
```
157157
are treated specially. A call `C(ts)` of the apply method is ascribed the underlying type
158-
`P1 & ... & Pn` (dropping any [super traits](../other-new-features/super-traits.html))
158+
`P1 & ... & Pn` (dropping any [super traits](../other-new-features/mixin-traits.md))
159159
as long as that type is still compatible with the expected type at the point of application.
160160
A call `t.copy(ts)` of `C`'s `copy` method is treated in the same way.
161161

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], val a
146146

147147
def driForLink(template: TemplateFile, link: String): Option[DRI] =
148148
val pathDri = Try {
149-
val path =
149+
val baseFile =
150150
if link.startsWith("/") then root.toPath.resolve(link.drop(1))
151-
else template.file.toPath.getParent().resolve(link)
152-
if Files.exists(path) then Some(driFor(path)) else None
151+
else template.file.toPath.getParent().resolve(link).normalize()
152+
153+
val baseFileName = baseFile.getFileName.toString
154+
val mdFile = baseFile.resolveSibling(baseFileName.stripSuffix(".html") + ".md")
155+
156+
Seq(baseFile, mdFile).find(Files.exists(_)).map(driFor)
153157
}.toOption.flatten
154158
pathDri.orElse(memberLinkResolver(link))
155159

scala3doc/src/dotty/renderers/ScalaHtmlRenderer.scala

+18-6
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,32 @@ class ScalaHtmlRenderer(ctx: DokkaContext, args: Args) extends HtmlRenderer(ctx)
245245
).toString()
246246
)
247247

248+
private val HashRegex = "([^#]+)(#.+)".r
249+
248250
override def buildPageContent(context: FlowContent, page: ContentPage): Unit =
249251
page match
250252
case s: StaticPageNode if !s.hasFrame() =>
251253
case _ => buildNavigation(context, page)
252254

253255
page.getContent match
254256
case prc: PartiallyRenderedContent =>
257+
def tryAsDri(str: String) =
258+
val (path, prefix) = str match
259+
case HashRegex(path, prefix) => (path, prefix)
260+
case _ => (str, "")
261+
262+
// TODO (https://github.com/lampepfl/scala3doc/issues/238) proper warnings about unresolved links
263+
prc.context.driForLink(prc.template.templateFile, path)
264+
.flatMap(dri => Option(getLocationProvider.resolve(dri, sourceSets, page)))
265+
.map(_ + prefix)
266+
.getOrElse {
267+
println(s"[WARN] ${prc.template.file}: Unable to resolve link '$str'")
268+
str
269+
}
270+
255271
def processLocalLink(str: String): String =
256-
Try(URL(str)).map(_ => str).getOrElse{
257-
// TODO (https://github.com/lampepfl/scala3doc/issues/238) error handling
258-
prc.context.driForLink(prc.template.templateFile, str)
259-
.flatMap(dri => Option(getLocationProvider.resolve(dri, sourceSets, page)))
260-
.getOrElse(str)
261-
}
272+
if str.startsWith("#") || str.isEmpty then str
273+
else Try(URL(str)).map(_ => str).getOrElse(tryAsDri(str))
262274

263275
val html = prc.procsesHtml(processLocalLink, resolveLink(page))
264276
withHtml(context, html)

0 commit comments

Comments
 (0)