Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaladoc features parity with old scaladoc/docs.scala-lang #13954

Merged
merged 15 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
86 changes: 19 additions & 67 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ object Build {
"-project-footer", s"Copyright (c) 2002-$currentYear, LAMP/EPFL",
"-author",
"-groups",
"-default-template", "doc-page"
"-default-template", "static-site-main"
) ++ extMap
}

Expand Down Expand Up @@ -1257,7 +1257,16 @@ object Build {
dependsOn(`scala3-compiler-bootstrapped`).
settings(commonBootstrappedSettings)

lazy val `scaladoc-js-common` = project.in(file("scaladoc-js/common")).

/**
* Collection of projects building targets for scaladoc, these are:
* - common - common module for javascript shared among html and markdown outpu
* - main - main target for default scaladoc producing html webpage
* - markdown - companion js for preprocessing features. Can be later used with some templating engine
* - contributors - not related project to any of forementioned modules. Used for presenting contributors for static site.
* Made as an indepented project to be scaladoc-agnostic.
*/
lazy val `scaladoc-js-common` = project.in(file("scaladoc-js/common")).
enablePlugins(DottyJSPlugin).
dependsOn(`scala3-library-bootstrappedJS`).
settings(libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13))
Expand All @@ -1270,7 +1279,7 @@ object Build {
Test / fork := false
)

lazy val `scaladoc-js-markdown` = project.in(file("scaladoc-js/markdown")).
lazy val `scaladoc-js-markdown` = project.in(file("scaladoc-js/markdown")).
enablePlugins(DottyJSPlugin).
dependsOn(`scaladoc-js-common`).
settings(
Expand Down Expand Up @@ -1338,70 +1347,13 @@ object Build {
).
settings(
Compile / resourceGenerators += Def.task {
val contributorsFile = (`scaladoc-js-contributors` / Compile / fullOptJS).value.data
val contributorsDestinationFile = Paths.get("docs-for-dotty-page", "js", "contributors.js").toFile
sbt.IO.copyFile(contributorsFile, contributorsDestinationFile)

val mainFile = (`scaladoc-js-main` / Compile / fullOptJS).value.data
val mainDestinationFile = (Compile / resourceManaged).value / "dotty_res" / "scripts" / "scaladoc-scalajs.js"
sbt.IO.copyFile(mainFile, mainDestinationFile)

Seq(mainDestinationFile, contributorsDestinationFile)
}.taskValue,
Compile / resourceGenerators += Def.task {
{
val cssDesitnationFile = (Compile / resourceManaged).value / "dotty_res" / "styles" / "code-snippets.css"
val cssSourceFile = (`scaladoc-js-common` / Compile / resourceDirectory).value / "code-snippets.css"
sbt.IO.copyFile(cssSourceFile, cssDesitnationFile)
Seq(cssDesitnationFile)
} ++ {
val cssDesitnationFile = Paths.get("docs-for-dotty-page", "css", "content-contributors.css").toFile
val cssSourceFile = (`scaladoc-js-contributors` / Compile / resourceDirectory).value / "content-contributors.css"
sbt.IO.copyFile(cssSourceFile, cssDesitnationFile)
Seq(cssDesitnationFile)
} ++ Seq("searchbar.css", "social-links.css", "ux.css", "versions-dropdown.css").map { file =>
val cssDesitnationFile = (Compile / resourceManaged).value / "dotty_res" / "styles" / file
val cssSourceFile = (`scaladoc-js-main` / Compile / resourceDirectory).value / file
sbt.IO.copyFile(cssSourceFile, cssDesitnationFile)
cssDesitnationFile
}
}.taskValue,
Compile / resourceGenerators += Def.task {
import _root_.scala.sys.process._
import _root_.scala.concurrent._
import _root_.scala.concurrent.duration.Duration
import ExecutionContext.Implicits.global
val inkuireVersion = "1.0.0-M3"
val inkuireLink = s"https://github.com/VirtusLab/Inkuire/releases/download/$inkuireVersion/inkuire.js"
val inkuireDestinationFile = (Compile / resourceManaged).value / "dotty_res" / "scripts" / "inkuire.js"
sbt.IO.touch(inkuireDestinationFile)

def tryFetch(retries: Int, timeout: Duration): Unit = {
val downloadProcess = (new java.net.URL(inkuireLink) #> inkuireDestinationFile).run()
val result: Future[Int] = Future(blocking(downloadProcess.exitValue()))
try {
Await.result(result, timeout) match {
case 0 =>
case res if retries > 0 =>
println(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res. $retries retries left")
tryFetch(retries - 1, timeout)
case res => throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res")
}
} catch {
case e: TimeoutException =>
downloadProcess.destroy()
if (retries > 0) {
println(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout. $retries retries left")
tryFetch(retries - 1, timeout)
}
else {
throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout")
}
}
}

tryFetch(5, Duration(60, "s"))
Seq(inkuireDestinationFile)
DocumentationWebsite.generateStaticAssets(
(`scaladoc-js-contributors` / Compile / fullOptJS).value.data,
(`scaladoc-js-main` / Compile / fullOptJS).value.data,
(`scaladoc-js-contributors` / Compile / baseDirectory).value / "css",
(`scaladoc-js-common` / Compile / baseDirectory).value / "css",
(Compile / resourceManaged).value,
)
}.taskValue,
libraryDependencies ++= Dependencies.flexmarkDeps ++ Seq(
"nl.big-o" % "liqp" % "0.6.8",
Expand Down
85 changes: 85 additions & 0 deletions project/DocumentationWebsite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import java.io.File
import java.nio.file.Paths
import sbt._
import Build._

object DocumentationWebsite {
def generateStaticAssets(
contributorsFile: File,
mainFile: File,
cssContentContributorsSourceBaseFile: File,
cssSourceFileBase: File,
baseDest: File
): Seq[File] = {


val contributorsTestcasesDestinationFile = Paths.get("scaladoc-testcases", "docs", "js", "contributors.js").toFile
val contributorsDestinationFile = Paths.get("docs-for-dotty-page", "js", "contributors.js").toFile
sbt.IO.copyFile(contributorsFile, contributorsTestcasesDestinationFile)
sbt.IO.copyFile(contributorsFile, contributorsDestinationFile)

val mainDestinationFile = baseDest / "dotty_res" / "scripts" / "scaladoc-scalajs.js"
sbt.IO.copyFile(mainFile, mainDestinationFile)

val cssCodeSnippetsDesitnationFile = baseDest / "dotty_res" / "styles" / "code-snippets.css"
val cssCodeSnippetsSourceFile = cssSourceFileBase / "code-snippets.css"
sbt.IO.copyFile(cssCodeSnippetsSourceFile, cssCodeSnippetsDesitnationFile)

val cssContentContributorsTestcasesDesitnationFile = Paths.get("docs-for-dotty-page", "css", "content-contributors.css").toFile
val cssContentContributorsDesitnationFile = Paths.get("scaladoc-testcases", "docs", "css", "content-contributors.css").toFile
val cssContentContributorsSourceFile = cssContentContributorsSourceBaseFile / "content-contributors.css"
sbt.IO.copyFile(cssContentContributorsSourceFile, cssContentContributorsTestcasesDesitnationFile)
sbt.IO.copyFile(cssContentContributorsSourceFile, cssContentContributorsDesitnationFile)

val dests = Seq("searchbar.css", "social-links.css", "ux.css", "versions-dropdown.css").map { file =>
val cssDesitnationFile = baseDest / "dotty_res" / "styles" / file
val cssSourceFile = cssSourceFileBase / file
sbt.IO.copyFile(cssSourceFile, cssDesitnationFile)
cssDesitnationFile
}

import _root_.scala.sys.process._
import _root_.scala.concurrent._
import _root_.scala.concurrent.duration.Duration
import ExecutionContext.Implicits.global
val inkuireVersion = "1.0.0-M3"
val inkuireLink = s"https://github.com/VirtusLab/Inkuire/releases/download/$inkuireVersion/inkuire.js"
val inkuireDestinationFile = baseDest / "dotty_res" / "scripts" / "inkuire.js"
sbt.IO.touch(inkuireDestinationFile)

def tryFetch(retries: Int, timeout: Duration): Unit = {
val downloadProcess = (new java.net.URL(inkuireLink) #> inkuireDestinationFile).run()
val result: Future[Int] = Future(blocking(downloadProcess.exitValue()))
try {
Await.result(result, timeout) match {
case 0 =>
case res if retries > 0 =>
println(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res. $retries retries left")
tryFetch(retries - 1, timeout)
case res => throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res")
}
} catch {
case e: TimeoutException =>
downloadProcess.destroy()
if (retries > 0) {
println(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout. $retries retries left")
tryFetch(retries - 1, timeout)
}
else {
throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout")
}
}
}

tryFetch(5, Duration(60, "s"))
Seq(
inkuireDestinationFile,
mainDestinationFile,
contributorsDestinationFile,
cssContentContributorsDesitnationFile,
cssCodeSnippetsDesitnationFile,
) ++ dests
}
}


File renamed without changes.
14 changes: 14 additions & 0 deletions scaladoc-testcases/docs/_layouts/redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
hasFrame: false
---
<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8">
<title>Redirecting&hellip;</title>
<link rel="canonical" href="{{ redirectTo }}">
<script>location="{{ redirectTo }}"</script>
<meta http-equiv="refresh" content="0; url={{ redirectTo }}">
<meta name="robots" content="noindex">
<h1>Redirecting&hellip;</h1>
<a href="{{ redirectTo }}">Click here if you were not redirected.</a>
</html>
22 changes: 22 additions & 0 deletions scaladoc-testcases/docs/_layouts/static-site-main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
extraJS:
- js/contributors.js
extraCSS:
- css/bootstrap.min.css
- css/content-contributors.css
---
<div class="container">
{{ content }}
<nav class="arrows-wrapper" aria-label="Page navigation">
{% if page.previous %}
<a rel="prev" href="{{ page.previous }}" class="arrows previous" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
{% endif %}
{% if page.next %}
<a rel="next" href="{{ page.next }}" class="arrows next" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
{% endif %}
</nav>
</div>
1 change: 1 addition & 0 deletions scaladoc-testcases/docs/css/bootstrap.min.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions scaladoc-testcases/docs/docs/docs/f1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
layout: static-site-main
redirectFrom:
- docs/fr.html
- docs/my-custom-link
---
julienrf marked this conversation as resolved.
Show resolved Hide resolved
F1
4 changes: 4 additions & 0 deletions scaladoc-testcases/docs/docs/docs/f2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: static-site-main
---
F2
4 changes: 4 additions & 0 deletions scaladoc-testcases/docs/docs/docs/f3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: static-site-main
---
F3
4 changes: 4 additions & 0 deletions scaladoc-testcases/docs/docs/docs/f4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: static-site-main
---
F4
7 changes: 7 additions & 0 deletions scaladoc-testcases/docs/sidebar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sidebar:
- title: Docs
subsection:
- page: docs/docs/f1.md
- page: docs/docs/f2.md
- page: docs/docs/f3.md
- page: docs/docs/f4.md
5 changes: 4 additions & 1 deletion scaladoc/src/dotty/tools/scaladoc/SourceLinks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ class SourceLinks(private val sourceLinks: PathBased[SourceLink]):
sourceLinks.get(path).map(_.elem.repoSummary)

def fullPath(path: Path): Option[Path] =
sourceLinks.get(path).map(_.path)
sourceLinks.get(path).map { case PathBased.Result(path, elem) => elem match
case e: WebBasedSourceLink => Paths.get(e.subPath, path.toString)
case _ => path
}

object SourceLinks:
val usage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do
val path = loadedTemplate.file.toPath
ctx.sourceLinks.repoSummary(path) match
case Some(DefinedRepoSummary("github", org, repo)) =>
script(raw(s"""var githubContributorsUrl = "https://api.github.com/repos/$org/$repo/commits?path=docs/${relativePath(path).toString.stripPrefix("docs-for-dotty-page/")}";"""))
val tag: TagArg = ctx.sourceLinks.fullPath(relativePath(path)).fold("") { githubContributors =>
script(raw(s"""var githubContributorsUrl = "https://api.github.com/repos/$org/$repo/commits?path=$githubContributors";"""))
}
tag // for some reason inference fails so had to state the type explicitly
case _ => ""
case _ => ""),
ctx.args.versionsDictionaryUrl match
Expand Down