Skip to content

Commit 1158b15

Browse files
authored
Merge pull request #12043 from BarkingBad/scaladoc/fix-static-site-names
Fix shipping static resources for static site
2 parents 08be314 + 2655389 commit 1158b15

File tree

12 files changed

+53
-39
lines changed

12 files changed

+53
-39
lines changed

docs/docs/reference/experimental/erased-defs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ object Machine:
158158
// State must be Off
159159
```
160160

161-
Note that in [Inline](./inline.md) we discussed `erasedValue` and inline
161+
Note that in [Inline](../metaprogramming/inline.md) we discussed `erasedValue` and inline
162162
matches. `erasedValue` is implemented with `erased`, so the state machine above
163163
can be encoded as follows:
164164

docs/docs/reference/features-classification.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ These constructs replace existing constructs with the aim of making the language
4545
- [Export clauses](other-new-features/export.md)
4646
provide a simple and general way to express aggregation, which can replace the
4747
previous facade pattern of package objects inheriting from classes.
48-
- [Vararg patterns](changed-features/vararg-patterns.md) now use the form `: _*` instead of `@ _*`, mirroring vararg expressions,
48+
- [Vararg splices](changed-features/vararg-splices.md) now use the form `*` instead of `@ _*`, mirroring vararg expressions,
4949
- [Creator applications](other-new-features/creator-applications.md) allow using simple function call syntax
5050
instead of `new` expressions. `new` expressions stay around as a fallback for
5151
the cases where creator applications cannot be used.
5252

53-
With the exception of early initializers and old-style vararg patterns, all superseded constructs continue to be available in Scala 3.0. The plan is to deprecate and phase them out later.
53+
With the exception of early initializers and old-style vararg splices, all superseded constructs continue to be available in Scala 3.0. The plan is to deprecate and phase them out later.
5454

5555
Value classes (superseded by opaque type aliases) are a special case. There are currently no deprecation plans for value classes, since we might bring them back in a more general form if they are supported natively by the JVM as is planned by project Valhalla.
5656

@@ -70,7 +70,7 @@ For the next several versions, old features will remain available and deprecatio
7070
These constructs are restricted to make the language safer.
7171

7272
- [Implicit Conversions](contextual/conversions.md): there is only one way to define implicit conversions instead of many, and potentially surprising implicit conversions require a language import.
73-
- [Given Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible.
73+
- [Given Imports](contextual/given-imports.md): implicits now require a special form of import, to make the import clearly visible.
7474
- [Type Projection](dropped-features/type-projection.md): only classes can be used as prefix `C` of a type projection `C#A`. Type projection on abstract types is no longer supported since it is unsound.
7575
- [Multiversal equality](contextual/multiversal-equality.md) implements an "opt-in" scheme to rule out nonsensical comparisons with `==` and `!=`.
7676
- [infix](https://github.com/lampepfl/dotty/pull/5975)
@@ -173,7 +173,7 @@ To enable porting most uses of macros, we are experimenting with the advanced la
173173
by itself a straightforward implementation of some simple macros and is at the same time an essential building block for the implementation of complex macros.
174174
- [Quotes and splices](metaprogramming/macros.md) provide a principled way to express macros and staging with a unified set of abstractions.
175175
- [Type class derivation](contextual/derivation.md) provides an in-language implementation of the `Gen` macro in Shapeless and other foundational libraries. The new implementation is more robust, efficient and easier to use than the macro.
176-
- [Implicit by-name parameters](contextual/implicit-by-name-parameters.md) provide a more robust in-language implementation of the `Lazy` macro in Shapeless.
176+
- [Implicit by-name parameters](contextual/by-name-context-parameters.md) provide a more robust in-language implementation of the `Lazy` macro in Shapeless.
177177

178178
**Status: not yet settled**
179179

docs/docs/reference/other-new-features/explicit-nulls.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ When explicit nulls are enabled, the type hierarchy changes so that `Null` is on
3535

3636
This is the new type hierarchy:
3737

38-
!["Type Hierarchy for Explicit Nulls"](../../../images/explicit-nulls/explicit-nulls-type-hierarchy.png)
38+
!["Type Hierarchy for Explicit Nulls"](/images/explicit-nulls/explicit-nulls-type-hierarchy.png)
3939

4040
After erasure, `Null` remains a subtype of all reference types (as forced by the JVM).
4141

docs/docs/release-notes/0.1.2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ This release ships with the following features:
8080
[4]: ../reference/new-types/union-types.html
8181
[5]: ../reference/enums/adts.html
8282
[6]: ../reference/enums/desugarEnums.html
83-
[7]: ../reference/other-new-features/implicit-by-name-parameters.html
83+
[7]: ../reference/contextual/by-name-context-parameters.html
8484
[8]: https://infoscience.epfl.ch/record/228518
8585
[9]: http://docs.scala-lang.org/sips/pending/static-members.html
8686
[10]: http://docs.scala-lang.org/sips/pending/improved-lazy-val-initialization.html
@@ -103,7 +103,7 @@ This release ships with the following features:
103103
[27]: https://github.com/lampepfl/dotty/pull/2513
104104
[28]: https://github.com/lampepfl/dotty/pull/2361
105105
[29]: https://github.com/lampepfl/dotty/pull/1453
106-
[30]: ../reference/contextual/implicit-function-types.html
106+
[30]: ../reference/contextual/context-functions.html
107107
[31]: https://github.com/lampepfl/dotty/pull/2136
108108
[32]: https://github.com/lampepfl/dotty/pull/1758
109109
[33]: ../reference/metaprogramming/inline.html

docs/docs/usage/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Start using the Dotty IDE in any Dotty project by following the
3838
### Standalone installation
3939
Releases are available for download on the [Releases Section](https://github.com/lampepfl/dotty/releases)
4040
of the Dotty repository. Releases include three executables: `scalac` the Dotty compiler,
41-
`scaladoc` the [Scaladoc](scaladoc.md) and `scala` the Dotty REPL.
41+
`scaladoc` the [Scaladoc](./scaladoc/index.md) and `scala` the Dotty REPL.
4242

4343
```
4444
.

docs/docs/usage/worksheet-mode.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ evaluate the code of the worksheet. Each line of output is printed on the right
2929
of the expression that produced it. The worksheets run with the classes of your
3030
project and its dependencies on their classpath.
3131

32-
![](../../images/worksheets/worksheet-run.png "Run worksheet")
32+
![](images/worksheets/worksheet-run.png "Run worksheet")
3333

3434
By default, the worksheets are also run when the file is saved. This can be
3535
configured in VSCode preferences:
3636

37-
![](../../images/worksheets/config-autorun.png "Configure run on save")
37+
![](images/worksheets/config-autorun.png "Configure run on save")
3838

3939
Note that the worksheet are fully integrated with the rest of Dotty IDE: While
4040
typing, errors are shown, completions are suggested, and you can use all the
4141
other features of Dotty IDE such as go to definition, find all references, etc.
4242

43-
![](../../images/worksheets/worksheet-help.png "IDE features in the worksheet")
43+
![](images/worksheets/worksheet-help.png "IDE features in the worksheet")
4444

4545
Implementation details
4646
======================

scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,19 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
102102
def siteRoot = staticSite.get.root.toPath
103103
def pathToResource(p: String) = Resource.File(p, siteRoot.resolve(p))
104104

105-
val siteImages = staticSite.toSeq.flatMap { _ =>
106-
val siteImgPath = siteRoot.resolve("images")
105+
def harvestResources(path: String) =
106+
val siteImgPath = siteRoot.resolve(path)
107107
if !Files.exists(siteImgPath) then Nil
108108
else
109109
val allPaths = Files.walk(siteImgPath, FileVisitOption.FOLLOW_LINKS)
110110
val files = allPaths.filter(Files.isRegularFile(_)).iterator().asScala
111111
files.map(p => siteRoot.relativize(p).toString).toList
112+
113+
val staticResources = staticSite.toSeq.flatMap { _ =>
114+
harvestResources("images") ++ harvestResources("resources")
112115
}
113116

114-
val siteResourcesPaths = allPages.toSet.flatMap(specificResources) ++ siteImages
117+
val siteResourcesPaths = allPages.toSet.flatMap(specificResources) ++ staticResources
115118

116119
val resources = siteResourcesPaths.toSeq.map(pathToResource) ++ allResources(allPages)
117120
resources.flatMap(renderResource)

scaladoc/src/dotty/tools/scaladoc/renderers/Locations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ trait Locations(using ctx: DocContext):
8181
case Nil => ""
8282
case seq => seq.mkString("", "/", "/")
8383

84-
def driExisits(dri: DRI) = true // TODO implement checks!
84+
def driExists(dri: DRI) = effectiveMembers.get(dri).isDefined || dri.isStaticFile

scaladoc/src/dotty/tools/scaladoc/renderers/SiteRenderer.scala

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,39 @@ trait SiteRenderer(using DocContext) extends Locations:
2828

2929
def siteContent(pageDri: DRI, content: ResolvedTemplate): AppliedTag =
3030
import content.ctx
31-
def tryAsDri(str: String) =
31+
def tryAsDri(str: String): Option[String] =
3232
val (path, prefix) = str match
3333
case HashRegex(path, prefix) => (path, prefix)
3434
case _ => (str, "")
3535

36-
val res = ctx.driForLink(content.template.templateFile, path).filter(driExisits)
37-
if res.isEmpty then report.warn(s"Unable to resolve link '$str'", content.template.file)
38-
res.headOption.fold(str)(pathToPage(pageDri, _) + prefix)
36+
val res = ctx.driForLink(content.template.templateFile, path).filter(driExists)
37+
res.headOption.map(pathToPage(pageDri, _) + prefix)
3938

4039
def processLocalLink(str: String): String =
41-
if str.startsWith("#") || str.isEmpty then str
42-
else Try(URL(str)).map(_ => str).getOrElse(tryAsDri(str))
40+
Try(URL(str)).map(_ => str).toOption.orElse {
41+
tryAsDri(str)
42+
}.orElse {
43+
Option.when(
44+
Files.exists(Paths.get(content.ctx.root.toPath.toAbsolutePath.toString, str))
45+
)(
46+
resolveLink(pageDri, str.stripPrefix("/"))
47+
)
48+
}.getOrElse {
49+
report.warn(s"Unable to resolve link '$str'", content.template.file)
50+
str
51+
}
52+
53+
def processLocalLinkWithGuard(str: String): String =
54+
if str.startsWith("#") || str.isEmpty then
55+
str
56+
else
57+
processLocalLink(str)
4358

4459
val document = Jsoup.parse(content.resolved.code)
4560
document.select("a").forEach(element =>
46-
element.attr("href", processLocalLink(element.attr("href")))
61+
element.attr("href", processLocalLinkWithGuard(element.attr("href")))
4762
)
4863
document.select("img").forEach { element =>
49-
val link = element.attr("src")
50-
Try(new URL(link)).getOrElse {
51-
if(link.startsWith("/")) element.attr("src", resolveLink(pageDri, link.drop(1)))
52-
}
53-
}// foreach does not work here
64+
element.attr("src", processLocalLink(element.attr("src")))
65+
} // foreach does not work here. Why?
5466
raw(document.outerHtml())

scaladoc/src/dotty/tools/scaladoc/site/StaticSiteContext.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ class StaticSiteContext(
6868
file.getName.endsWith(".html")
6969

7070

71-
private def loadTemplate(from: File, isBlog: Boolean = false): Option[LoadedTemplate] =
71+
private def loadTemplate(from: File, isBlog: Boolean): Option[LoadedTemplate] =
7272
if (!isValidTemplate(from)) None else
7373
try
7474
val topLevelFiles = if isBlog then Seq(from, new File(from, "_posts")) else Seq(from)
7575
val allFiles = topLevelFiles.filter(_.isDirectory).flatMap(_.listFiles())
76-
val (indexes, children) = allFiles.flatMap(loadTemplate(_)).partition(_.templateFile.isIndexPage())
76+
val (indexes, children) = allFiles.flatMap(loadTemplate(_, isBlog)).partition(_.templateFile.isIndexPage())
7777

7878
def loadIndexPage(): TemplateFile =
7979
val indexFiles = from.listFiles { file => file.getName == "index.md" || file.getName == "index.html" }
@@ -135,13 +135,13 @@ class StaticSiteContext(
135135
if link.startsWith("/") then root.toPath.resolve(link.drop(1))
136136
else template.file.toPath.getParent().resolve(link).normalize()
137137

138-
val baseFileName = baseFile.getFileName.toString
139-
val mdFile = baseFile.resolveSibling(baseFileName.stripSuffix(".html") + ".md")
140-
def trySuffix(pref: String) =
141-
if baseFileName == pref then Seq(baseFile.getParent) else Nil
142-
val strippedIndexes = trySuffix("index.html") ++ trySuffix("index.md")
143-
144-
(Seq(baseFile, mdFile) ++ strippedIndexes).filter(Files.exists(_)).map(driFor)
138+
baseFile.getFileName.toString.split("\\.").headOption.toSeq.flatMap { baseFileName =>
139+
Seq(
140+
Some(baseFile.resolveSibling(baseFileName + ".html")),
141+
Some(baseFile.resolveSibling(baseFileName + ".md")),
142+
Option.when(baseFileName == "index")(baseFile.getParent)
143+
).flatten.filter(Files.exists(_)).map(driFor)
144+
}
145145
}.toOption.filter(_.nonEmpty)
146146
pathsDri.getOrElse(memberLinkResolver(link).toList)
147147

scaladoc/src/dotty/tools/scaladoc/site/common.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ val apiPageDRI: DRI = DRI(location = "api")
2323

2424
val defaultMarkdownOptions: DataHolder =
2525
new MutableDataSet()
26-
.setFrom(ParserEmulationProfile.KRAMDOWN.getOptions)
26+
.setFrom(ParserEmulationProfile.COMMONMARK.getOptions)
2727
.set(AnchorLinkExtension.ANCHORLINKS_WRAP_TEXT, false)
2828
.set(AnchorLinkExtension.ANCHORLINKS_ANCHOR_CLASS, "anchor")
2929
.set(EmojiExtension.ROOT_IMAGE_PATH, "https://github.global.ssl.fastly.net/images/icons/emoji/")

scaladoc/src/dotty/tools/scaladoc/site/templates.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ case class TemplateFile(
7676
val code = if (isHtml || layoutTemplate.exists(!_.isHtml)) rendered else
7777
val parser: Parser = Parser.builder(defaultMarkdownOptions).build()
7878
HtmlRenderer.builder(defaultMarkdownOptions).build().render(parser.parse(rendered))
79-
8079
layoutTemplate match
8180
case None => ResolvedPage(code, resources ++ ctx.resources)
8281
case Some(layoutTemplate) =>

0 commit comments

Comments
 (0)