File tree Expand file tree Collapse file tree 3 files changed +33
-8
lines changed
scaladoc/src/dotty/tools/scaladoc Expand file tree Collapse file tree 3 files changed +33
-8
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import java.nio.file.Path
1313import java .nio .file .Files
1414import java .io .File
1515import scala .util .chaining ._
16+ import dotty .tools .scaladoc .util .Escape .escapeFilename
1617
1718case class ResolvedTemplate (template : LoadedTemplate , ctx : StaticSiteContext ):
1819 val resolved = template.resolveToHtml(ctx)
@@ -55,11 +56,16 @@ trait SiteRenderer(using DocContext) extends Locations:
5556 val staticSiteRootPath = content.ctx.root.toPath.toAbsolutePath
5657 def asValidURL : Option [String ] = Try (URI (str).toURL).toOption.map(_ => str)
5758 def asAsset : Option [String ] = Option .when(
58- Files .exists(staticSiteRootPath.resolve(" _assets" ).resolve(str.stripPrefix(" /" )))
59+ Try (
60+ Files .exists(staticSiteRootPath.resolve(" _assets" ).resolve(str.stripPrefix(" /" )))
61+ ).getOrElse(false )
5962 )(
6063 resolveLink(pageDri, str.stripPrefix(" /" ))
6164 )
62- def asStaticSite : Option [String ] = tryAsDriPlain(str).orElse(tryAsDri(str))
65+ def asStaticSite : Option [String ] =
66+ tryAsDriPlain(str)
67+ .orElse(tryAsDri(str))
68+ .orElse(tryAsDriPlain(escapeFilename(str)))
6369
6470 /* Link resolving checks performs multiple strategies with following priority:
6571 1. We check if the link is a valid URL e.g. http://dotty.epfl.ch
Original file line number Diff line number Diff line change @@ -7,9 +7,8 @@ import java.nio.file.FileVisitOption
77import java .nio .file .Path
88import java .nio .file .Paths
99
10- import scala .util .Try
1110import scala .jdk .CollectionConverters ._
12- import scala .annotation . static
11+ import scala .util . control . NonFatal
1312
1413class StaticSiteContext (
1514 val root : File ,
@@ -75,10 +74,13 @@ class StaticSiteContext(
7574 val templateSourceLocation = staticSiteRoot.reverseSiteMappings.get(templateDestLocation)
7675
7776 // Check if link is relative or absolute
78- if link.startsWith(" /" )
79- then Seq (root.toPath.resolve(link.drop(1 )))
80- else Seq (templateDestLocation.getParent.resolve(link).normalize) ++
81- templateSourceLocation.map(_.getParent.resolve(link).normalize)
77+ try
78+ if link.startsWith(" /" )
79+ then Seq (root.toPath.resolve(link.drop(1 )))
80+ else Seq (templateDestLocation.getParent.resolve(link).normalize) ++
81+ templateSourceLocation.map(_.getParent.resolve(link).normalize)
82+ catch
83+ case NonFatal (_) => Seq .empty
8284
8385 // Try to strip site extension and create all possible file paths
8486 val fileNames = if siteExtensions.exists(link.endsWith(_))
Original file line number Diff line number Diff line change @@ -5,7 +5,24 @@ object Escape:
55 .replace(" #" ," %23" )
66
77 def escapeFilename (filename : String ) =
8+ // from compiler/src/dotty/tools/dotc/util/NameTransformer.scala
89 val escaped = filename
10+ .replace(" ~" , " $tilde" )
11+ .replace(" =" , " $eq" )
12+ .replace(" <" , " $less" )
13+ .replace(" >" , " $greater" )
14+ .replace(" !" , " $bang" )
15+ .replace(" #" , " $hash" )
16+ .replace(" %" , " $percent" )
17+ .replace(" ^" , " $up" )
18+ .replace(" &" , " $amp" )
19+ .replace(" |" , " $bar" )
20+ .replace(" *" , " $times" )
921 .replace(" /" , " $div" )
22+ .replace(" +" , " $plus" )
23+ .replace(" -" , " $minus" )
24+ .replace(" :" , " $colon" )
1025 .replace(" \\ " , " $bslash" )
26+ .replace(" ?" , " $qmark" )
27+ .replace(" @" , " $at" )
1128 if escaped != filename then escaped + " $" else escaped
You can’t perform that action at this time.
0 commit comments