Skip to content

Commit df1b1c4

Browse files
committed
Add "edit on github" links to doc pages
1 parent f89861c commit df1b1c4

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

doc-tool/resources/_layouts/doc-page.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
{% include "sidebar" %}
1414

1515
<div id="content-body" class="doc-page-body">
16+
<a id="edit-on-github" href="{{ site.projectUrl }}/edit/master/{{ site.root }}/{{ page.url }}">
17+
Edit this page on GitHub
18+
</a>
1619
<h1 id="doc-page-title">{{ page.title }}</h1>
1720
<hr/>
1821
<div id="doc-page-container">

doc-tool/resources/css/dottydoc.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600,700);
2+
@import url(https://fonts.googleapis.com/css?family=Titillium+Web:200,300,400,600);
23
@import url(https://fonts.googleapis.com/css?family=Roboto+Slab:100,300,400,700);
34

45
html, body {
@@ -34,6 +35,24 @@ div#content-wrapper div#content-body {
3435
transition: all .25s ease-out;
3536
}
3637

38+
div#content-body > a#edit-on-github {
39+
border-left: 1px solid #fff;
40+
position: absolute;
41+
top: 47px;
42+
padding-left: 10px;
43+
right: 250px;
44+
font-size: 14px;
45+
color: #373a3c;
46+
font-family: "Titillium Web", sans-serif;
47+
text-transform: uppercase;
48+
}
49+
50+
div#content-body > a#edit-on-github:hover,
51+
div#content-body > a#edit-on-github:focus {
52+
text-decoration: none;
53+
border-left: 1px solid #0fa00f;
54+
}
55+
3756
div#content-wrapper button#menu-toggle {
3857
background: rgba(244, 243, 244, 0.4) none;
3958
border: 1px solid transparent;

doc-tool/src/dotty/tools/dottydoc/staticsite/DefaultParams.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ case class DefaultParams(
3939
"posts" -> site.posts.map(_.toMap),
4040
"project" -> site.projectTitle,
4141
"version" -> site.projectVersion,
42-
"projectUrl" -> site.projectUrl
42+
"projectUrl" -> site.projectUrl,
43+
"root" -> site.root
4344
).asJava,
4445

4546
"sidebar" -> sidebar.titles.asJava
@@ -55,7 +56,7 @@ case class DefaultParams(
5556

5657
def withPosts(posts: Array[BlogPost]): DefaultParams =
5758
copy(site = SiteInfo(
58-
site.baseurl, site.projectTitle, site.projectVersion, site.projectUrl, posts))
59+
site.baseurl, site.projectTitle, site.projectVersion, site.projectUrl, posts, site.root))
5960

6061
def withUrl(url: String): DefaultParams =
6162
copy(page = PageInfo(url))
@@ -74,7 +75,8 @@ case class SiteInfo(
7475
projectTitle: String,
7576
projectVersion: String,
7677
projectUrl: String,
77-
posts: Array[BlogPost]
78+
posts: Array[BlogPost],
79+
root: String
7880
)
7981

8082
case class Sidebar(titles: List[Title])

doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ case class Site(
172172

173173
DefaultParams(
174174
docs, docsFlattened, documentation, PageInfo(pathFromRoot),
175-
SiteInfo(baseUrl, projectTitle, projectVersion, projectUrl, Array()),
175+
SiteInfo(
176+
baseUrl, projectTitle, projectVersion, projectUrl, Array(),
177+
root.toString
178+
),
176179
sidebar
177180
)
178181
}
@@ -290,7 +293,7 @@ case class Site(
290293
* // given that root is: /some/root
291294
* ```
292295
*/
293-
def stripRoot(f: JFile): String = {
296+
def stripRoot(f: JFile, root: JFile = root): String = {
294297
val rootLen = root.getAbsolutePath.length + 1
295298
f.getAbsolutePath.drop(rootLen)
296299
}

doc-tool/test/dotty/tools/dottydoc/staticsite/SiteTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class SiteTests extends DottyDocTest with SourceFileOps {
7878
}
7979

8080
@Test def siteStructure = {
81-
val assets = site.staticAssets.map(site.stripRoot).toSet
82-
val compd = site.compilableFiles.map(site.stripRoot).toSet
81+
val assets = site.staticAssets.map(site.stripRoot(_)).toSet
82+
val compd = site.compilableFiles.map(site.stripRoot(_)).toSet
8383

8484
val expectedAssets = Set(
8585
"css/toolbar.css",

0 commit comments

Comments
 (0)