Skip to content

Commit fec033a

Browse files
committed
Polish gathering the contributors. CSSes fixes.
1 parent 47fe99d commit fec033a

File tree

10 files changed

+163
-58
lines changed

10 files changed

+163
-58
lines changed

docs/_layouts/blog-page.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,4 @@ <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>
3935
</main>

docs/_layouts/doc-page.html

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,18 @@
33
---
44
<main>
55
<header>
6+
<h1>{{ page.title }}</h1>
67
<div class="byline">
78
<a href="{{ urls.editSource }}">
89
<i class="far fa-edit"></i>
910
Edit this page on GitHub
1011
</a>
1112
</div>
12-
<h1>{{ page.title }}</h1>
1313
</header>
1414
{{ content }}
15-
<div class="two-columns">
16-
{% if page.previous %}
17-
<a href="{{ page.previous }}"><strong>previous</strong></a>
18-
{% endif %}
19-
{% if page.next %}
20-
<a href="{{ page.next }}"><strong>next</strong></a>
21-
{% endif %}
22-
</div>
23-
<div class="content-contributors">
24-
<h3>Contributors to this page:</h3>
25-
<div id="contributors" class="contributors-container"></div>
15+
<div class="content-contributors hidden">
16+
<h5>Contributors to this page:</h5>
17+
<div id="documentation-contributors" class="contributors-container"></div>
2618
</div>
2719
</main>
2820

docs/_layouts/main.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
---
44
<div id="content-wrapper">
55
<div class="container">
6-
<header id="site-header">
6+
<div id="site-header">
77
<div class="wrap">
88
<nav class="navigation" role="menu">
99
<ul class="navigation-menu">
@@ -28,8 +28,20 @@
2828
</ul>
2929
</nav>
3030
</div>
31-
</header>
31+
</div>
3232
{{ content }}
33+
<nav class="nav-wide-wrapper" aria-label="Page navigation">
34+
{% if page.previous %}
35+
<a rel="prev" href="{{ page.previous }}" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
36+
<i class="fa fa-angle-left"></i>
37+
</a>
38+
{% endif %}
39+
{% if page.next %}
40+
<a rel="next" href="{{ page.next }}" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
41+
<i class="fa fa-angle-right"></i>
42+
</a>
43+
{% endif %}
44+
</nav>
3345
</div>
3446
</div>
3547
<script>

docs/css/dottydoc.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ main > h1 {
2525
margin-bottom: 20px;
2626
}
2727

28+
.byline {
29+
font-size: 14px;
30+
}
31+
2832
.byline, .byline a {
2933
color: grey;
3034
}
@@ -265,4 +269,4 @@ aside.success {
265269
header {
266270
position: static !important;
267271
width: 100% !important;
268-
}
272+
}

scaladoc-js/resources/content-contributors.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
.content-contributors.hidden {
2+
display: none;
3+
}
14
.content-contributors .contributors-container {
25
display: flex;
36
flex-wrap: wrap;
47
align-items: center;
8+
padding-bottom: 25px;
59
}
610
.content-contributors .contributors-container div {
711
margin: 5px;

scaladoc-js/src/Globals.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import scala.scalajs.js.annotation.JSGlobalScope
88
object Globals extends js.Object {
99
val pathToRoot: String = js.native
1010
val versionsDictionaryUrl: String = js.native
11+
val githubContributorsUrl: String = js.native
1112
}
1213

1314
object StringUtils {

scaladoc-js/src/content-contributors/ContentContributors.scala

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,42 @@ trait Commits extends js.Array[CommitTop]
3838

3939
class ContentContributors:
4040
document.addEventListener("DOMContentLoaded", (e: Event) => {
41-
val githubApiUrl = "https://api.github.com/repos/lampepfl/dotty/commits"
4241
val indenticonsUrl = "https://github.com/identicons"
43-
val thisPageUrl = document.querySelector(".byline a").asInstanceOf[html.Anchor].href
44-
.stripPrefix("https://github.com/lampepfl/dotty/edit/master/")
45-
val url = s"$githubApiUrl?path=$thisPageUrl"
46-
val request: Future[String] = Ajax.get(url).map(_.responseText)
47-
request.onComplete {
48-
case Success(json: String) =>
49-
val res = JSON.parse(json).asInstanceOf[Commits]
50-
val authors = res.map { commit =>
51-
commit.author match
52-
case null =>
53-
FullAuthor(commit.commit.author.name, "", s"$indenticonsUrl/${commit.commit.author.name}.png")
54-
case author =>
55-
FullAuthor(author.login, author.html_url, author.avatar_url)
56-
}.distinct
57-
58-
val div = document.getElementById("contributors")
59-
authors.foreach { case FullAuthor(name, url, img) =>
60-
val divN = document.createElement("div")
61-
val imgN = document.createElement("img").asInstanceOf[html.Image]
62-
imgN.src = img
63-
val autN = document.createElement("a").asInstanceOf[html.Anchor]
64-
autN.href = url
65-
autN.text = name
66-
divN.appendChild(imgN)
67-
divN.appendChild(autN)
68-
div.appendChild(divN)
69-
}
70-
case Failure(_) =>
71-
println(s"Couldn't fetch contributors for $url")
72-
}
42+
js.typeOf(Globals.githubContributorsUrl) match
43+
case "undefined" =>
44+
// don't do anything
45+
case url =>
46+
val request: Future[String] = Ajax.get(Globals.githubContributorsUrl).map(_.responseText)
47+
request.onComplete {
48+
case Success(json: String) =>
49+
val res = JSON.parse(json).asInstanceOf[Commits]
50+
val authors = res.map { commit =>
51+
commit.author match
52+
case null =>
53+
FullAuthor(commit.commit.author.name, "", s"$indenticonsUrl/${commit.commit.author.name}.png")
54+
case author =>
55+
FullAuthor(author.login, author.html_url, author.avatar_url)
56+
}.distinct
57+
58+
val div = document.getElementById("documentation-contributors")
59+
60+
authors.foreach { case FullAuthor(name, url, img) =>
61+
val divN = document.createElement("div")
62+
val imgN = document.createElement("img").asInstanceOf[html.Image]
63+
imgN.src = img
64+
val autN = document.createElement("a").asInstanceOf[html.Anchor]
65+
autN.href = url
66+
autN.text = name
67+
divN.appendChild(imgN)
68+
divN.appendChild(autN)
69+
div.appendChild(divN)
70+
}
71+
72+
if authors.nonEmpty then
73+
div.asInstanceOf[html.Div].parentElement.classList.toggle("hidden")
74+
75+
case Failure(_) =>
76+
println(s"Couldn't fetch contributors for ${Globals.githubContributorsUrl}")
77+
}
7378
})
7479

scaladoc/resources/dotty_res/styles/scalastyle.css

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ body {
1818
margin: 0;
1919
padding: 0;
2020
font-family: "Lato", sans-serif;
21-
font-size: 16px;
21+
font-size: 18px;
2222
background: var(--body-bg);
2323
}
2424
body, button, input {
@@ -88,7 +88,10 @@ pre code, pre code.hljs {
8888

8989
pre, .symbol.monospace {
9090
font-weight: 500;
91-
font-size: 12px;
91+
font-size: 14px;
92+
padding: 8px;
93+
margin-top: 8px;
94+
margin-bottom: 8px;
9295
}
9396
pre .hljs-comment {
9497
/* Fold comments in snippets */
@@ -176,7 +179,7 @@ th {
176179

177180
/* Navigation */
178181
#sideMenu2 {
179-
overflow-y: scroll;
182+
overflow-y: auto;
180183
overflow-x: hidden;
181184

182185
height: 100%;
@@ -1036,6 +1039,7 @@ footer .socials {
10361039

10371040
.navigation .navigation-menu {
10381041
padding-left: 0px;
1042+
margin: 18px 0px;
10391043
}
10401044
.navigation .navigation-menu .navigation-menu-item {
10411045
margin: 5px 0px;
@@ -1059,3 +1063,70 @@ footer .socials {
10591063
display: flex;
10601064
justify-content: space-between;
10611065
}
1066+
1067+
/* Nav Icons */
1068+
1069+
.nav-chapters {
1070+
font-size: 2.5em;
1071+
text-align: center;
1072+
text-decoration: none;
1073+
1074+
position: fixed;
1075+
top: 0;
1076+
bottom: 0;
1077+
margin: 0;
1078+
max-width: 150px;
1079+
min-width: 90px;
1080+
1081+
display: flex;
1082+
justify-content: center;
1083+
align-content: center;
1084+
flex-direction: column;
1085+
1086+
transition: color 0.5s, background-color 0.5s;
1087+
}
1088+
1089+
.nav-chapters.previous, .nav-chapters.next {
1090+
color: var(--grey400);
1091+
}
1092+
1093+
.nav-chapters:hover {
1094+
text-decoration: none;
1095+
color: var(--grey300);
1096+
background-color: var(--grey900);
1097+
transition: background-color 0.15s, color 0.15s;
1098+
}
1099+
1100+
.nav-wrapper {
1101+
margin-top: 50px;
1102+
display: none;
1103+
}
1104+
1105+
.mobile-nav-chapters {
1106+
font-size: 2.5em;
1107+
text-align: center;
1108+
text-decoration: none;
1109+
width: 90px;
1110+
border-radius: 5px;
1111+
background-color: var(--sidebar-bg);
1112+
}
1113+
1114+
.previous {
1115+
float: left;
1116+
left: var(--side-width);
1117+
}
1118+
1119+
.next {
1120+
float: right;
1121+
right: 0;
1122+
}
1123+
1124+
@media only screen and (max-width: 1080px) {
1125+
.nav-wide-wrapper { display: none; }
1126+
.nav-wrapper { display: block; }
1127+
}
1128+
1129+
@media only screen and (max-width: 1380px) {
1130+
.sidebar-visible .nav-wide-wrapper { display: none; }
1131+
.sidebar-visible .nav-wrapper { display: block; }
1132+
}

scaladoc/src/dotty/tools/scaladoc/SourceLinks.scala

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def pathToString(p: Path) =
1313
trait SourceLink:
1414
val path: Option[Path] = None
1515
def render(memberName: String, path: Path, operation: String, line: Option[Int], optionalRevision: Option[String]): String
16+
def repoSummary: RepoSummary
1617

1718
case class TemplateSourceLink(val urlTemplate: String) extends SourceLink:
1819
override val path: Option[Path] = None
@@ -32,9 +33,13 @@ case class TemplateSourceLink(val urlTemplate: String) extends SourceLink:
3233
mapping.foldLeft(urlTemplate) {
3334
case (sourceLink, (regex, value)) => regex.replaceAllIn(sourceLink, Regex.quoteReplacement(value))
3435
}
36+
override def repoSummary = UnknownRepoSummary
3537

38+
sealed class RepoSummary
39+
case class DefinedRepoSummary(origin: String, org: String, repo: String) extends RepoSummary
40+
case object UnknownRepoSummary extends RepoSummary // we cannot easily get that information from template source links
3641

37-
case class WebBasedSourceLink(prefix: String, revision: String, subPath: String) extends SourceLink:
42+
case class WebBasedSourceLink(repoSummary: RepoSummary, prefix: String, revision: String, subPath: String) extends SourceLink:
3843
override val path: Option[Path] = None
3944
override def render(memberName: String, path: Path, operation: String, line: Option[Int], optionalRevision: Option[String] = None): String =
4045
val action = if operation == "view" then "blob" else operation
@@ -79,10 +84,10 @@ class SourceLinkParser(revision: Option[String]) extends ArgParser[SourceLink]:
7984
name match
8085
case "github" =>
8186
withRevision(rev =>
82-
WebBasedSourceLink(githubPrefix(organization, repo), rev, subPath))
87+
WebBasedSourceLink(DefinedRepoSummary("github", organization, repo), githubPrefix(organization, repo), rev, subPath))
8388
case "gitlab" =>
8489
withRevision(rev =>
85-
WebBasedSourceLink(gitlabPrefix(organization, repo), rev, subPath))
90+
WebBasedSourceLink(DefinedRepoSummary("gitlab", organization, repo), gitlabPrefix(organization, repo), rev, subPath))
8691
case other =>
8792
Left(s"'$other' is not a known provider, please provide full source path template.")
8893
case BrokenKnownProvider("gitlab" | "github") =>
@@ -97,13 +102,19 @@ class SourceLinkParser(revision: Option[String]) extends ArgParser[SourceLink]:
97102

98103
type Operation = "view" | "edit"
99104

100-
class SourceLinks(val sourceLinks: PathBased[SourceLink]):
105+
class SourceLinks(private val sourceLinks: PathBased[SourceLink]):
101106
def pathTo(rawPath: Path, memberName: String = "", line: Option[Int] = None, operation: Operation = "view", optionalRevision: Option[String] = None): Option[String] =
102107
sourceLinks.get(rawPath).map(res => res.elem.render(memberName, res.path, operation, line, optionalRevision))
103108

104109
def pathTo(member: Member): Option[String] =
105110
member.sources.flatMap(s => pathTo(s.path, member.name, Option(s.lineNumber).map(_ + 1)))
106111

112+
def repoSummary(path: Path): Option[RepoSummary] =
113+
sourceLinks.get(path).map(_.elem.repoSummary)
114+
115+
def fullPath(path: Path): Option[Path] =
116+
sourceLinks.get(path).map(_.path)
117+
107118
object SourceLinks:
108119
val usage =
109120
"""Source links provide a mapping between file in documentation and code repository.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java.nio.file.Path
1313
import java.nio.file.Files
1414
import java.nio.file.FileVisitOption
1515
import java.io.File
16+
import dotty.tools.scaladoc.staticFileSymbolUUID
1617

1718
class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: DocContext)
1819
extends Renderer(rootPackage, members, extension = "html"):
@@ -82,6 +83,14 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do
8283
linkResources(page.link.dri, earlyResources, deferJs = false).toList,
8384
linkResources(page.link.dri, resources, deferJs = true).toList,
8485
script(raw(s"""var pathToRoot = "${pathToRoot(page.link.dri)}";""")),
86+
(page.content match
87+
case ResolvedTemplate(loadedTemplate, _) =>
88+
val path = loadedTemplate.file.toPath
89+
ctx.sourceLinks.repoSummary(path) match
90+
case Some(DefinedRepoSummary("github", org, repo)) =>
91+
script(raw(s"""var githubContributorsUrl = "https://api.github.com/repos/$org/$repo/commits?path=docs/${relativePath(path).toString.stripPrefix("docs-for-dotty-page/")}";"""))
92+
case _ => ""
93+
case _ => ""),
8594
ctx.args.versionsDictionaryUrl match
8695
case Some(url) => script(raw(s"""var versionsDictionaryUrl = "$url";"""))
8796
case None => ""
@@ -148,7 +157,7 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do
148157
a(href := pathToPage(link.dri, b.dri))(b.name),
149158
"/"
150159
)).dropRight(1)
151-
div(cls := "breadcrumbs")(innerTags:_*)
160+
div(cls := "breadcrumbs container")(innerTags:_*)
152161

153162
def textFooter: String | AppliedTag =
154163
args.projectFooter.fold("") { f =>

0 commit comments

Comments
 (0)