Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian3k committed May 3, 2024
1 parent 084ab1a commit bed92d3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/_docs/reference/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In this reference, we discuss design decisions and present important differences

## Goals

The language redesign was guided by three main goals:
The language [[foo.Bar.<]] redesign was guided by three main goals:

- Strengthen Scala's foundations.
Make the full programming language compatible with the foundational work on the
Expand Down
12 changes: 10 additions & 2 deletions scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import java.nio.file.Path
import java.nio.file.Files
import java.io.File
import scala.util.chaining._
import dotty.tools.scaladoc.util.Escape.escapeFilename
import scala.util.control.NonFatal

case class ResolvedTemplate(template: LoadedTemplate, ctx: StaticSiteContext):
val resolved = template.resolveToHtml(ctx)
Expand Down Expand Up @@ -55,11 +57,17 @@ trait SiteRenderer(using DocContext) extends Locations:
val staticSiteRootPath = content.ctx.root.toPath.toAbsolutePath
def asValidURL: Option[String] = Try(URI(str).toURL).toOption.map(_ => str)
def asAsset: Option[String] = Option.when(
Files.exists(staticSiteRootPath.resolve("_assets").resolve(str.stripPrefix("/")))
try
Files.exists(staticSiteRootPath.resolve("_assets").resolve(str.stripPrefix("/")))
catch
case NonFatal(_) => false
)(
resolveLink(pageDri, str.stripPrefix("/"))
)
def asStaticSite: Option[String] = tryAsDriPlain(str).orElse(tryAsDri(str))
def asStaticSite: Option[String] =
tryAsDriPlain(str)
.orElse(tryAsDri(str))
.orElse(tryAsDriPlain(escapeFilename(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
Expand Down
13 changes: 8 additions & 5 deletions scaladoc/src/dotty/tools/scaladoc/site/StaticSiteContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.nio.file.FileVisitOption
import java.nio.file.Path
import java.nio.file.Paths

import scala.util.Try
import scala.util.control.NonFatal
import scala.jdk.CollectionConverters._
import scala.annotation.static

Expand Down Expand Up @@ -75,10 +75,13 @@ class StaticSiteContext(
val templateSourceLocation = staticSiteRoot.reverseSiteMappings.get(templateDestLocation)

// Check if link is relative or absolute
if link.startsWith("/")
then Seq(root.toPath.resolve(link.drop(1)))
else Seq(templateDestLocation.getParent.resolve(link).normalize) ++
templateSourceLocation.map(_.getParent.resolve(link).normalize)
try
if link.startsWith("/")
then Seq(root.toPath.resolve(link.drop(1)))
else Seq(templateDestLocation.getParent.resolve(link).normalize) ++
templateSourceLocation.map(_.getParent.resolve(link).normalize)
catch
case NonFatal(_) => Seq.empty

// Try to strip site extension and create all possible file paths
val fileNames = if siteExtensions.exists(link.endsWith(_))
Expand Down
17 changes: 17 additions & 0 deletions scaladoc/src/dotty/tools/scaladoc/util/escape.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@ object Escape:
.replace("#","%23")

def escapeFilename(filename: String) =
// from compiler/src/dotty/tools/dotc/util/NameTransformer.scala
val escaped = filename
.replace("~", "$tilde")
.replace("=", "$eq")
.replace("<", "$less")
.replace(">", "$greater")
.replace("!", "$bang")
.replace("#", "$hash")
.replace("%", "$percent")
.replace("^", "$up")
.replace("&", "$amp")
.replace("|", "$bar")
.replace("*", "$times")
.replace("/", "$div")
.replace("+", "$plus")
.replace("-", "$minus")
.replace(":", "$colon")
.replace("\\", "$bslash")
.replace("?", "$qmark")
.replace("@", "$at")
if escaped != filename then escaped + "$" else escaped

0 comments on commit bed92d3

Please sign in to comment.