Skip to content

Commit 600aef8

Browse files
committed
Walk in order and collect previous/next
1 parent cc6d3e6 commit 600aef8

File tree

9 files changed

+121
-70
lines changed

9 files changed

+121
-70
lines changed

docs/_layouts/blog-page.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: main
33
---
4-
<main class="container">
4+
<main>
55
<header>
66
<h1>{{ page.title }}</h1>
77
<div class="byline">
@@ -32,4 +32,8 @@ <h1>{{ page.title }}</h1>
3232
</span>
3333
</div>
3434
{% endif %}
35+
<div class="two-columns">
36+
<a href="{{ page.previous }}"><strong>previous</strong></a>
37+
<a href="{{ page.next }}"><strong>next</strong></a>
38+
</div>
3539
</main>

docs/_layouts/doc-page.html

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,14 @@
11
---
22
layout: main
33
---
4-
<main class="container">
5-
<nav class="doc-navigation" role="menu">
6-
<div class="navigation-ellipsis">
7-
<i class="fa fa-ellipsis-v"></i>
8-
</div>
9-
<ul class="navigation-menu">
10-
<li class="navigation-menu-item">
11-
<a href="https://scala-lang.org/scala3/getting-started.html" id="getting started">Getting Started</a>
12-
</li>
13-
<li class="navigation-menu-item">
14-
<a href="#" id="learn">Learn</a>
15-
<ul class="navigation-dropdown">
16-
<li>
17-
<a href="https://scala-lang.org/scala3/new-in-scala3.html">New in Scala 3</a>
18-
</li>
19-
<li>
20-
<a href="https://scala-lang.org/scala3/book/introduction.html">Scala 3 Book</a>
21-
</li>
22-
</ul>
23-
</li>
24-
<li class="navigation-menu-item">
25-
<a href="https://scala-lang.org/scala3/guides/migration/compatibility-intro.html" id="migrate">Migrate</a>
26-
</li>
27-
<li class="navigation-menu-item">
28-
<a href="#" id="reference">Reference</a>
29-
<ul class="navigation-dropdown">
30-
<li>
31-
<a href="https://scala-lang.org/scala3/guides.html">Guides</a>
32-
</li>
33-
<li>
34-
<a href="https://scala-lang.org/scala3/reference/overview.html">Language Specification</a>
35-
</li>
36-
<li>
37-
<a href="https://scala-lang.org/api/3.x/">Scala Library API</a>
38-
</li>
39-
</ul>
40-
</li>
41-
<li class="navigation-menu-item">
42-
<a href="https://scala-lang.org/scala3/guides/contribution/contribution-intro.html" id="contributing guide">Contributing Guide</a>
43-
</li>
44-
</ul>
45-
</nav>
4+
<main>
465
<header>
476
<h1>{{ page.title }}</h1>
487
</header>
498
{{ content }}
509
<div class="two-columns">
51-
<a href="/scala3/reference/overview.html"><strong>previous</strong></a>
52-
<a href="/scala3/reference/new-types/intersection-types.html"><strong>next</strong></a>
10+
<a href="{{ page.previous }}"><strong>previous</strong></a>
11+
<a href="{{ page.next }}"><strong>next</strong></a>
5312
</div>
5413
</main>
5514

docs/_layouts/main.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,41 @@
22
layout: base
33
---
44
<div id="content-wrapper">
5+
<div class="container">
6+
<header id="site-header">
7+
<div class="wrap">
8+
<nav class="navigation" role="menu">
9+
<ul class="navigation-menu">
10+
<li class="navigation-menu-item">
11+
<a href="/" class="active">Documentation</a>
12+
</li>
13+
<li class="navigation-menu-item">
14+
<a href="https://www.scala-lang.org/download/">Download</a>
15+
</li>
16+
<li class="navigation-menu-item">
17+
<a href="https://www.scala-lang.org/community/">Community</a>
18+
</li>
19+
<li class="navigation-menu-item">
20+
<a href="https://index.scala-lang.org">Libraries</a>
21+
</li>
22+
<li class="navigation-menu-item">
23+
<a href="https://www.scala-lang.org/contribute/">Contribute</a>
24+
</li>
25+
<li class="navigation-menu-item">
26+
<a href="https://www.scala-lang.org/blog/">Blog</a>
27+
</li>
28+
</ul>
29+
</nav>
30+
</div>
31+
</header>
32+
533
{% if page.movedTo %}
634
<aside class="warning">
735
The content of this page is outdated. Click <a href="{{ page.movedTo }}">here</a> to find the up to date version of this page.
836
</aside>
937
{% endif %}
1038
{{ content }}
39+
</div>
1140
</div>
1241
<script>
1342
((window.gitter = {}).chat = {}).options = {

project/Build.scala

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ object Build {
339339
"-skip-by-id:scala.runtime.MatchCase",
340340
"-project-footer", s"Copyright (c) 2002-$currentYear, LAMP/EPFL",
341341
"-author",
342-
"-groups"
342+
"-groups",
343+
"-default-template", "doc-page"
343344
)
344345

345346
// Settings used when compiling dotty with a non-bootstrapped dotty
@@ -1338,27 +1339,27 @@ object Build {
13381339
sbt.IO.touch(inkuireDestinationFile)
13391340

13401341
def tryFetch(retries: Int, timeout: Duration): Unit = {
1341-
val downloadProcess = (new java.net.URL(inkuireLink) #> inkuireDestinationFile).run()
1342-
val result: Future[Int] = Future(blocking(downloadProcess.exitValue()))
1343-
try {
1344-
Await.result(result, timeout) match {
1345-
case 0 =>
1346-
case res if retries > 0 =>
1347-
println(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res. $retries retries left")
1348-
tryFetch(retries - 1, timeout)
1349-
case res => throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res")
1350-
}
1351-
} catch {
1352-
case e: TimeoutException =>
1353-
downloadProcess.destroy()
1354-
if (retries > 0) {
1355-
println(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout. $retries retries left")
1356-
tryFetch(retries - 1, timeout)
1357-
}
1358-
else {
1359-
throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout")
1360-
}
1361-
}
1342+
// val downloadProcess = (new java.net.URL(inkuireLink) #> inkuireDestinationFile).run()
1343+
// val result: Future[Int] = Future(blocking(downloadProcess.exitValue()))
1344+
// try {
1345+
// Await.result(result, timeout) match {
1346+
// case 0 =>
1347+
// case res if retries > 0 =>
1348+
// println(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res. $retries retries left")
1349+
// tryFetch(retries - 1, timeout)
1350+
// case res => throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res")
1351+
// }
1352+
// } catch {
1353+
// case e: TimeoutException =>
1354+
// downloadProcess.destroy()
1355+
// if (retries > 0) {
1356+
// println(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout. $retries retries left")
1357+
// tryFetch(retries - 1, timeout)
1358+
// }
1359+
// else {
1360+
// throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout")
1361+
// }
1362+
// }
13621363
}
13631364

13641365
tryFetch(5, Duration(60, "s"))

project/CopyDocs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object CopyDocs {
6565
),
6666

6767
"docs/docs/usage/scaladoc/" -> (commonTransformations +
68-
(titlePattern -> s"---\ntitle: $$1\n---"),
68+
(titlePattern -> s"---\nlayout: doc-page\ntitle: $$1\n---"),
6969
),
7070
)
7171

scaladoc/src/dotty/tools/scaladoc/Scaladoc.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ object Scaladoc:
6161
apiSubdirectory : Boolean = false,
6262
scastieConfiguration: String = "",
6363
projectFormat: String = "html",
64+
defaultTemplate: Option[String] = None,
6465
)
6566

6667
def run(args: Array[String], rootContext: CompilerContext): Reporter =
@@ -239,6 +240,7 @@ object Scaladoc:
239240
apiSubdirectory.get,
240241
scastieConfiguration.get,
241242
projectFormat.get,
243+
defaultTemplate.nonDefault
242244
)
243245
(Some(docArgs), newContext)
244246
}

scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,14 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings:
139139
"html"
140140
)
141141

142+
val defaultTemplate: Setting[String] =
143+
StringSetting(
144+
"-default-template",
145+
"default template used by static site",
146+
"The static site is generating empty files for indexes that haven't been provided explicitly. User can specify what template should be used for such generic indexes (note it can still interpolate some general settings)",
147+
""
148+
)
149+
150+
142151
def scaladocSpecificSettings: Set[Setting[_]] =
143152
Set(sourceLinks, legacySourceLink, syntax, revision, externalDocumentationMappings, socialLinks, skipById, skipByRegex, deprecatedSkipPackages, docRootContent, snippetCompiler, generateInkuire, scastieConfiguration)

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,50 @@ abstract class Renderer(rootPackage: Member, val members: Map[DRI, Member], prot
4545
val msg = s"ERROR: Multiple index pages for doc found ${indexes.map(_.file)}"
4646
report.error(msg)
4747

48-
val templatePages = templates.map(templateToPage(_, siteContext))
48+
// Below code is for walking in order the tree and modifing its nodes basing on its neighbours
49+
50+
// First we flatten templates to get them sorted in-order
51+
def flattenedTemplates(template: LoadedTemplate): Seq[LoadedTemplate] =
52+
template +: template.children.flatMap(flattenedTemplates)
53+
54+
// We add dummy guards
55+
val allTemplates: Seq[Option[LoadedTemplate]] = None +: templates.flatMap(flattenedTemplates).map(Some(_)) :+ None
56+
57+
// Let's gather the list of maps for each template with its in-order neighbours
58+
val newSettings: Seq[Map[String, Object]] = allTemplates.sliding(size = 3, step = 1).map {
59+
case prev :: mid :: next :: Nil =>
60+
val currDri = siteContext.driFor(mid.get.file.toPath)
61+
def dri(sibling: Option[LoadedTemplate]) =
62+
sibling.map(n => siteContext.driFor(n.file.toPath)).flatMap { dri =>
63+
Some(pathToPage(currDri, dri)).filter(_ != UnresolvedLocationLink)
64+
}.getOrElse("")
65+
Map(
66+
"previous" -> dri(prev), "next" -> dri(next)
67+
)
68+
}.toSeq
69+
70+
// We update the immutable tree of templates by walking in-order
71+
def updateSettings(template: LoadedTemplate, additionalSettings: Seq[Map[String, Object]]): (LoadedTemplate, Seq[Map[String, Object]]) =
72+
val head :: tail = additionalSettings
73+
val (newChildren, newAdditionalSettings): (List[LoadedTemplate], List[Seq[Map[String, Object]]]) = template.children.scanLeft((null: LoadedTemplate, tail: Seq[Map[String, Object]])) { case ((_, aS), template) =>
74+
updateSettings(template, aS)
75+
}.unzip
76+
val newLoadedTemplate = template.copy(
77+
templateFile = template.templateFile.copy(settings = template.templateFile.settings.updated("page", template.templateFile.settings("page").asInstanceOf[Map[String, Object]] ++ head)),
78+
children = newChildren.drop(1) // We drop trailing null from the first `scanLeft` output collection
79+
)
80+
81+
(newLoadedTemplate, newAdditionalSettings.last)
82+
end updateSettings
83+
84+
// We run the above function for the templates. We could do some temporary parent template so it would be just `updatedSettings(...)` but we would eventually post-process it so it has no difference
85+
val (newTemplates, _): (List[LoadedTemplate], List[Seq[Map[String, Object]]]) = templates.scanLeft((null: LoadedTemplate, newSettings)) {
86+
case ((_, aS), template) =>
87+
updateSettings(template, aS)
88+
}.unzip
89+
90+
// We finally obtain updated template pages. Once again we drop first null from `scanLeft` and map it using `templateToPage`
91+
val templatePages = newTemplates.drop(1).map(templateToPage(_, siteContext))
4992

5093
indexes.headOption match
5194
case None if templatePages.isEmpty=>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ class StaticSiteContext(
158158
case Some(t) => t
159159
case None => "index"
160160
val fakeFile = new File(new File(root, "docs"), title)
161-
LoadedTemplate(emptyTemplate(fakeFile, title), nested.map(loadSidebarContent), fakeFile)
161+
LoadedTemplate(
162+
args.defaultTemplate.fold(emptyTemplate(fakeFile, title))(layouts(_).copy(title = TemplateName.FilenameDefined(title))),
163+
nested.map(loadSidebarContent),
164+
fakeFile
165+
)
162166

163167
private def loadAllFiles() =
164168
def dir(name: String)= List(new File(root, name)).filter(_.isDirectory)

0 commit comments

Comments
 (0)