@@ -13,6 +13,7 @@ import java.nio.file.Path
13
13
import java .nio .file .Files
14
14
import java .io .File
15
15
import scala .util .chaining ._
16
+ import javax .print .Doc
16
17
17
18
case class ResolvedTemplate (template : LoadedTemplate , ctx : StaticSiteContext ):
18
19
val resolved = template.resolveToHtml(ctx)
@@ -30,9 +31,15 @@ trait SiteRenderer(using DocContext) extends Locations:
30
31
def siteContent (pageDri : DRI , content : ResolvedTemplate ): PageContent =
31
32
import content .ctx
32
33
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
34
41
case HashRegex (path, prefix) => (path, prefix)
35
- case _ => (str , " " )
42
+ case _ => (newStr , " " )
36
43
37
44
val res = ctx.driForLink(content.template.file, path).filter(driExists)
38
45
res.headOption.map(pathToPage(pageDri, _) + prefix)
@@ -46,27 +53,16 @@ trait SiteRenderer(using DocContext) extends Locations:
46
53
resolveLink(pageDri, str.stripPrefix(" /" ))
47
54
)
48
55
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))
58
56
59
57
/* Link resolving checks performs multiple strategies with following priority:
60
58
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)
62
60
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
64
61
*/
65
62
66
63
asValidURL
67
64
.orElse(asStaticSite)
68
65
.orElse(asAsset)
69
- .orElse(asApiLink)
70
66
.getOrElse {
71
67
report.warn(s " Unable to resolve link ' $str' " , content.template.templateFile.file)
72
68
str
0 commit comments