Skip to content

Commit 47fe99d

Browse files
committed
Add Edit on Github button and Contriubuted sections
1 parent 600aef8 commit 47fe99d

File tree

11 files changed

+151
-306
lines changed

11 files changed

+151
-306
lines changed

docs/_layouts/doc-page.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@
33
---
44
<main>
55
<header>
6+
<div class="byline">
7+
<a href="{{ urls.editSource }}">
8+
<i class="far fa-edit"></i>
9+
Edit this page on GitHub
10+
</a>
11+
</div>
612
<h1>{{ page.title }}</h1>
713
</header>
814
{{ content }}
915
<div class="two-columns">
10-
<a href="{{ page.previous }}"><strong>previous</strong></a>
11-
<a href="{{ page.next }}"><strong>next</strong></a>
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>
1226
</div>
1327
</main>
1428

docs/_layouts/main.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929
</nav>
3030
</div>
3131
</header>
32-
33-
{% if page.movedTo %}
34-
<aside class="warning">
35-
The content of this page is outdated. Click <a href="{{ page.movedTo }}">here</a> to find the up to date version of this page.
36-
</aside>
37-
{% endif %}
3832
{{ content }}
3933
</div>
4034
</div>

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ object Build {
13211321
Seq(jsDestinationFile)
13221322
}.taskValue,
13231323
Compile / resourceGenerators += Def.task {
1324-
Seq("code-snippets.css", "searchbar.css", "social-links.css", "ux.css", "versions-dropdown.css").map { file =>
1324+
Seq("code-snippets.css", "searchbar.css", "content-contributors.css", "social-links.css", "ux.css", "versions-dropdown.css").map { file =>
13251325
val cssDesitnationFile = (Compile / resourceManaged).value / "dotty_res" / "styles" / file
13261326
val cssSourceFile = (`scaladoc-js` / Compile / resourceDirectory).value / file
13271327
sbt.IO.copyFile(cssSourceFile, cssDesitnationFile)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.content-contributors .contributors-container {
2+
display: flex;
3+
flex-wrap: wrap;
4+
align-items: center;
5+
}
6+
.content-contributors .contributors-container div {
7+
margin: 5px;
8+
}
9+
.content-contributors .contributors-container div a {
10+
vertical-align: middle;
11+
padding: 3px;
12+
text-decoration: none;
13+
}
14+
.content-contributors .contributors-container div img {
15+
vertical-align: middle;
16+
width: 35px;
17+
height: 35px;
18+
margin-bottom: 0;
19+
border-radius: 7px;
20+
}

scaladoc-js/src/Main.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ object Main:
1010
SocialLinks()
1111
DropdownHandler()
1212
Ux()
13+
ContentContributors()
1314
common()
1415

1516
/**
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package dotty.tools.scaladoc
2+
3+
import org.scalajs.dom._
4+
import org.scalajs.dom.ext._
5+
6+
import scala.util.matching.Regex._
7+
import scala.util.matching._
8+
import org.scalajs.dom.ext.Ajax
9+
import scala.scalajs.js.JSON
10+
import scala.scalajs.js
11+
12+
import scala.concurrent.ExecutionContext.Implicits.global
13+
import scala.concurrent.Future
14+
import scala.util.{Success,Failure}
15+
16+
// Contributors widget
17+
// see https://stackoverflow.com/a/19200303/4496364
18+
// Copied from https://github.com/scala/docs.scala-lang/blob/main/resources/js/functions.js and rewritten to Scala.js
19+
20+
case class FullAuthor(name: String, url: String, image: String)
21+
22+
trait FallbackAuthor extends js.Object:
23+
def name: String
24+
25+
trait CommitBottom extends js.Object:
26+
def author: FallbackAuthor
27+
28+
trait Author extends js.Object:
29+
def login: String
30+
def avatar_url: String
31+
def html_url: String
32+
33+
trait CommitTop extends js.Object:
34+
def commit: CommitBottom
35+
def author: Author
36+
37+
trait Commits extends js.Array[CommitTop]
38+
39+
class ContentContributors:
40+
document.addEventListener("DOMContentLoaded", (e: Event) => {
41+
val githubApiUrl = "https://api.github.com/repos/lampepfl/dotty/commits"
42+
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+
}
73+
})
74+

0 commit comments

Comments
 (0)