Skip to content

Commit d83058c

Browse files
committed
cmd/golangorg,content/static: render homepage using local root.html
This change alters the behavior to use a local copy of root.html to render the homepage of golang.org. It is copied directly from revision b7422f2 of doc/root.html in the main go repository. This will enable changes to be made to the homepage without having to cherry pick them to a release branch. Updates golang/go#9936 Updates golang/go#29206 Change-Id: I68a6ef017b969f8838f466721bce51c1b8a358d8 Reviewed-on: https://go-review.googlesource.com/c/website/+/180959 Reviewed-by: Katie Hockman <[email protected]> Reviewed-by: Chris Broadfoot <[email protected]>
1 parent 9c74ae0 commit d83058c

File tree

5 files changed

+175
-1
lines changed

5 files changed

+175
-1
lines changed

cmd/golangorg/appinit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func main() {
7575
fs.Bind("/", rootfs, "/", vfs.BindReplace)
7676
}
7777

78+
// Use a local copy of root.html instead of the one in the main go repository.
79+
// See golang.org/issue/29206 for more info.
80+
fs.Bind("/doc/root.html", mapfs.New(static.Files), "/doc/root.html", vfs.BindReplace)
7881
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
7982

8083
webroot := getFullPath("/src/golang.org/x/website")

cmd/golangorg/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,13 @@ func main() {
202202
defer rc.Close() // be nice (e.g., -writeIndex mode)
203203
fs.Bind("/", zipfs.New(rc, *zipfile), *goroot, vfs.BindReplace)
204204
}
205+
// Use a local copy of root.html instead of the one in the main go repository.
206+
// See golang.org/issue/29206 for more info.
205207
if *templateDir != "" {
208+
fs.Bind("/doc/root.html", vfs.OS(*templateDir), "/doc/root.html", vfs.BindReplace)
206209
fs.Bind("/lib/godoc", vfs.OS(*templateDir), "/", vfs.BindBefore)
207210
} else {
211+
fs.Bind("/doc/root.html", mapfs.New(static.Files), "/doc/root.html", vfs.BindReplace)
208212
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
209213
}
210214

content/static/doc/root.html

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<!--{
2+
"Path": "/",
3+
"Template": true
4+
}-->
5+
6+
<div class="left">
7+
8+
<div id="learn">
9+
{{if not $.GoogleCN}}
10+
<a class="popout share">Pop-out</a>
11+
{{end}}
12+
<div class="rootHeading">Try Go</div>
13+
<div class="input">
14+
<textarea spellcheck="false" class="code">// You can edit this code!
15+
// Click here and start typing.
16+
package main
17+
18+
import "fmt"
19+
20+
func main() {
21+
fmt.Println("Hello, 世界")
22+
}</textarea>
23+
</div>
24+
<div class="output">
25+
<pre>
26+
Hello, 世界
27+
</pre>
28+
</div>
29+
<div class="buttons">
30+
<a class="run" href="#" title="Run this code [shift-enter]">Run</a>
31+
{{if not $.GoogleCN}}
32+
<a class="share" href="#" title="Share this code">Share</a>
33+
<a class="tour" href="//tour.golang.org/" title="Learn Go from your browser">Tour</a>
34+
{{end}}
35+
</div>
36+
<div class="toys">
37+
<select>
38+
<option value="hello.go">Hello, World!</option>
39+
<option value="life.go">Conway's Game of Life</option>
40+
<option value="fib.go">Fibonacci Closure</option>
41+
<option value="peano.go">Peano Integers</option>
42+
<option value="pi.go">Concurrent pi</option>
43+
<option value="sieve.go">Concurrent Prime Sieve</option>
44+
<option value="solitaire.go">Peg Solitaire Solver</option>
45+
<option value="tree.go">Tree Comparison</option>
46+
</select>
47+
</div>
48+
</div>
49+
50+
</div>
51+
52+
<div class="right">
53+
54+
<div id="about">
55+
Go is an open source programming language that makes it easy to build
56+
simple, reliable, and efficient software.
57+
</div>
58+
59+
<div id="gopher"></div>
60+
61+
<a href="/dl/" id="start">
62+
<span class="big">Download Go</span>
63+
<span class="desc">
64+
Binary distributions available for<br>
65+
Linux, macOS, Windows, and more.
66+
</span>
67+
</a>
68+
69+
</div>
70+
71+
<div style="clear: both"></div>
72+
73+
{{if not $.GoogleCN}}
74+
<div class="left">
75+
<div id="video">
76+
<div class="rootHeading">Featured video</div>
77+
<div class="js-frontpage-video" style="--aspect-ratio-padding: 58.07%;"><iframe width="415" height="241" src="//www.youtube.com/embed/ytEkHepK08c" frameborder="0" allowfullscreen></iframe></div>
78+
</div>
79+
</div>
80+
81+
<div class="right">
82+
<div id="blog">
83+
<div class="rootHeading">Featured articles</div>
84+
<div class="read"><a href="//blog.golang.org/">Read more</a></div>
85+
</div>
86+
</div>
87+
{{end}}
88+
89+
<div style="clear: both;"></div>
90+
91+
<script>
92+
(function() {
93+
'use strict';
94+
95+
window.initFuncs.push(function() {
96+
// Set up playground if enabled.
97+
if (window.playground) {
98+
window.playground({
99+
"codeEl": "#learn .code",
100+
"outputEl": "#learn .output",
101+
"runEl": "#learn .run",
102+
"shareEl": "#learn .share",
103+
"shareRedirect": "//play.golang.org/p/",
104+
"toysEl": "#learn .toys select"
105+
});
106+
} else {
107+
$('#learn').hide()
108+
}
109+
});
110+
111+
{{if not $.GoogleCN}}
112+
113+
function readableTime(t) {
114+
var m = ["January", "February", "March", "April", "May", "June", "July",
115+
"August", "September", "October", "November", "December"];
116+
var p = t.substring(0, t.indexOf("T")).split("-");
117+
var d = new Date(p[0], p[1]-1, p[2]);
118+
return d.getDate() + " " + m[d.getMonth()] + " " + d.getFullYear();
119+
}
120+
121+
window.feedLoaded = function(result) {
122+
var blog = document.getElementById("blog");
123+
var read = blog.getElementsByClassName("read")[0];
124+
for (var i = 0; i < result.length && i < 2; i++) {
125+
var entry = result[i];
126+
var title = document.createElement("a");
127+
title.className = "title";
128+
title.href = entry.Link;
129+
title.innerHTML = entry.Title;
130+
blog.insertBefore(title, read);
131+
var extract = document.createElement("div");
132+
extract.className = "extract";
133+
extract.innerHTML = entry.Summary;
134+
blog.insertBefore(extract, read);
135+
var when = document.createElement("div");
136+
when.className = "when";
137+
when.innerHTML = "Published " + readableTime(entry.Time);
138+
blog.insertBefore(when, read);
139+
}
140+
}
141+
142+
window.initFuncs.push(function() {
143+
// Load blog feed.
144+
$('<script/>').attr('text', 'text/javascript')
145+
.attr('src', '//blog.golang.org/.json?jsonp=feedLoaded')
146+
.appendTo('body');
147+
148+
// Set the video at random.
149+
var videos = [
150+
{h: 241, s: "//www.youtube.com/embed/ytEkHepK08c"}, // Tour of Go
151+
{h: 241, s: "//www.youtube.com/embed/f6kdp27TYZs"}, // Concurrency Patterns
152+
{h: 233, s: "//player.vimeo.com/video/69237265"} // Simple environment
153+
];
154+
var v = videos[Math.floor(Math.random()*videos.length)];
155+
$('#video iframe').attr('height', v.h).attr('src', v.s);
156+
// Compute the aspect ratio (as a percentage) of the video
157+
// using the fixed width 415 and the height of the current video, v.h.
158+
var ar = 100*v.h/415;
159+
$('.js-frontpage-video').attr('style', '--aspect-ratio-padding: ' + ar + '%;');
160+
});
161+
162+
{{end}}
163+
})();
164+
</script>

content/static/gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var files = []string{
3636
"codewalk.html",
3737
"codewalkdir.html",
3838
"dirlist.html",
39+
"doc/root.html",
3940
"error.html",
4041
"example.html",
4142
"godoc.html",

content/static/static.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)