Skip to content

Commit f8ae203

Browse files
committed
Add view and edit links to static pages
Set cwd form generate*Documentation tasks to root project path
1 parent 470413c commit f8ae203

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

project/Build.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ object Build {
14581458
val projectVersion = version.value
14591459
val sourcesAndRevision = s"-s github://lampepfl/dotty --revision master --projectVersion $projectVersion"
14601460
run.in(Compile).toTask(
1461-
s""" -d output/$outDir -t $targets -n "$name" $sourcesAndRevision $params"""
1461+
s""" -d scala3doc/output/$outDir -t $targets -n "$name" $sourcesAndRevision $params"""
14621462
)
14631463
}
14641464

@@ -1492,11 +1492,12 @@ object Build {
14921492
Compile / mainClass := Some("dotty.dokka.Main"),
14931493
// There is a bug in dokka that prevents parallel tests withing the same jvm
14941494
fork.in(test) := true,
1495+
baseDirectory.in(run) := baseDirectory.in(ThisBuild).value,
14951496
generateSelfDocumentation := Def.taskDyn {
14961497
generateDocumentation(
14971498
classDirectory.in(Compile).value.getAbsolutePath,
14981499
"scala3doc", "self",
1499-
"-p documentation --projectLogo documentation/logo.svg",
1500+
"-p scala3doc/documentation --projectLogo scala3doc/documentation/logo.svg",
15001501
)
15011502
}.value,
15021503
generateScala3Documentation := Def.taskDyn {
@@ -1511,7 +1512,7 @@ object Build {
15111512
val roots = joinProducts(dottyJars)
15121513

15131514
if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
1514-
else generateDocumentation(roots, "Scala 3", "scala3", "-p scala3-docs --projectLogo scala3-docs/logo.svg")
1515+
else generateDocumentation(roots, "Scala 3", "scala3", "-p scala3doc/scala3-docs --projectLogo scala3doc/scala3-docs/logo.svg")
15151516
}.value,
15161517
generateTestcasesDocumentation := Def.taskDyn {
15171518
generateDocumentation(Build.testcasesOutputDir.in(Test).value, "Scala3doc testcases", "testcases")

scala3doc/scala3-docs/_layouts/doc-page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<header>
66
<h1>{{ page.title }}</h1>
77
<div class="byline">
8-
<a href="{{ site.projectUrl }}/edit/master/{{ site.root }}/{{ page.url }}">
8+
<a href="{{ urls.editSource }}">
99
<i class="far fa-edit"></i>
1010
Edit this page on GitHub
1111
</a>

scala3doc/src/dotty/dokka/DottyDokkaConfig.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ case class DottyDokkaConfig(docConfiguration: DocConfiguration) extends DokkaCon
1717
override def getModuleName(): String = "ModuleName"
1818
override def getModuleVersion(): String = ""
1919

20-
lazy val staticSiteContext = docConfiguration.args.docsRoot.map(path =>
21-
StaticSiteContext(File(path).getAbsoluteFile(), Set(mkSourceSet.asInstanceOf[SourceSetWrapper]), docConfiguration.args))
22-
2320
lazy val sourceLinks: SourceLinks = SourceLinks.load(docConfiguration)
2421

22+
lazy val staticSiteContext = docConfiguration.args.docsRoot.map(path => StaticSiteContext(
23+
File(path).getAbsoluteFile(),
24+
Set(mkSourceSet.asInstanceOf[SourceSetWrapper]),
25+
docConfiguration.args,
26+
sourceLinks
27+
))
28+
29+
2530
override def getPluginsConfiguration: JList[DokkaConfiguration.PluginConfiguration] = JList()
2631

2732
lazy val mkSourceSet: DokkaSourceSet =

scala3doc/src/dotty/dokka/site/LoadedTemplate.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package site
33

44
import java.io.File
55
import java.nio.file.Files
6+
import java.nio.file.Paths
67

78
import org.jetbrains.dokka.base.renderers.html.{NavigationNode, NavigationPage}
89
import org.jetbrains.dokka.model.Documentable
@@ -34,7 +35,12 @@ case class LoadedTemplate(templateFile: TemplateFile, children: List[LoadedTempl
3435
def resolveToHtml(ctx: StaticSiteContext): ResolvedPage =
3536
val posts = children.map(_.lazyTemplateProperties(ctx))
3637
val site = templateFile.settings.getOrElse("site", Map.empty).asInstanceOf[Map[String, Object]]
38+
val sourceLinks = if !file.exists() then Nil else
39+
val actualPath = Paths.get("").toAbsolutePath.relativize(file.toPath.toRealPath())
40+
ctx.sourceLinks.pathTo(actualPath).map("viewSource" -> _ ) ++
41+
ctx.sourceLinks.pathTo(actualPath, operation = "edit").map("editSource" -> _ )
3742

38-
val updatedSettings = templateFile.settings + ("site" -> (site + ("posts" -> posts))) ++ ctx.projectWideProperties
43+
val updatedSettings = templateFile.settings ++ ctx.projectWideProperties +
44+
("site" -> (site + ("posts" -> posts))) + ("urls" -> sourceLinks.toMap)
3945

4046
templateFile.resolveInner(RenderingContext(updatedSettings, ctx.layouts))

scala3doc/src/dotty/dokka/site/StaticSiteContext.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import util.Try
2020

2121
import scala.collection.JavaConverters._
2222

23-
class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], args: Args):
23+
class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper], args: Args, val sourceLinks: SourceLinks):
2424

2525
var memberLinkResolver: String => Option[DRI] = _ => None
2626

0 commit comments

Comments
 (0)