Skip to content

Commit

Permalink
cmd/golangorg,content/static: render homepage using local root.html
Browse files Browse the repository at this point in the history
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 b7422f212878c68807c76351abc3fa02c5f6e7bd 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]>
  • Loading branch information
andybons committed Jun 6, 2019
1 parent 9c74ae0 commit d83058c
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/golangorg/appinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func main() {
fs.Bind("/", rootfs, "/", vfs.BindReplace)
}

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

webroot := getFullPath("/src/golang.org/x/website")
Expand Down
4 changes: 4 additions & 0 deletions cmd/golangorg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,13 @@ func main() {
defer rc.Close() // be nice (e.g., -writeIndex mode)
fs.Bind("/", zipfs.New(rc, *zipfile), *goroot, vfs.BindReplace)
}
// Use a local copy of root.html instead of the one in the main go repository.
// See golang.org/issue/29206 for more info.
if *templateDir != "" {
fs.Bind("/doc/root.html", vfs.OS(*templateDir), "/doc/root.html", vfs.BindReplace)
fs.Bind("/lib/godoc", vfs.OS(*templateDir), "/", vfs.BindBefore)
} else {
fs.Bind("/doc/root.html", mapfs.New(static.Files), "/doc/root.html", vfs.BindReplace)
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
}

Expand Down
164 changes: 164 additions & 0 deletions content/static/doc/root.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<!--{
"Path": "/",
"Template": true
}-->

<div class="left">

<div id="learn">
{{if not $.GoogleCN}}
<a class="popout share">Pop-out</a>
{{end}}
<div class="rootHeading">Try Go</div>
<div class="input">
<textarea spellcheck="false" class="code">// You can edit this code!
// Click here and start typing.
package main

import "fmt"

func main() {
fmt.Println("Hello, 世界")
}</textarea>
</div>
<div class="output">
<pre>
Hello, 世界
</pre>
</div>
<div class="buttons">
<a class="run" href="#" title="Run this code [shift-enter]">Run</a>
{{if not $.GoogleCN}}
<a class="share" href="#" title="Share this code">Share</a>
<a class="tour" href="//tour.golang.org/" title="Learn Go from your browser">Tour</a>
{{end}}
</div>
<div class="toys">
<select>
<option value="hello.go">Hello, World!</option>
<option value="life.go">Conway's Game of Life</option>
<option value="fib.go">Fibonacci Closure</option>
<option value="peano.go">Peano Integers</option>
<option value="pi.go">Concurrent pi</option>
<option value="sieve.go">Concurrent Prime Sieve</option>
<option value="solitaire.go">Peg Solitaire Solver</option>
<option value="tree.go">Tree Comparison</option>
</select>
</div>
</div>

</div>

<div class="right">

<div id="about">
Go is an open source programming language that makes it easy to build
simple, reliable, and efficient software.
</div>

<div id="gopher"></div>

<a href="/dl/" id="start">
<span class="big">Download Go</span>
<span class="desc">
Binary distributions available for<br>
Linux, macOS, Windows, and more.
</span>
</a>

</div>

<div style="clear: both"></div>

{{if not $.GoogleCN}}
<div class="left">
<div id="video">
<div class="rootHeading">Featured video</div>
<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>
</div>
</div>

<div class="right">
<div id="blog">
<div class="rootHeading">Featured articles</div>
<div class="read"><a href="//blog.golang.org/">Read more</a></div>
</div>
</div>
{{end}}

<div style="clear: both;"></div>

<script>
(function() {
'use strict';

window.initFuncs.push(function() {
// Set up playground if enabled.
if (window.playground) {
window.playground({
"codeEl": "#learn .code",
"outputEl": "#learn .output",
"runEl": "#learn .run",
"shareEl": "#learn .share",
"shareRedirect": "//play.golang.org/p/",
"toysEl": "#learn .toys select"
});
} else {
$('#learn').hide()
}
});

{{if not $.GoogleCN}}

function readableTime(t) {
var m = ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"];
var p = t.substring(0, t.indexOf("T")).split("-");
var d = new Date(p[0], p[1]-1, p[2]);
return d.getDate() + " " + m[d.getMonth()] + " " + d.getFullYear();
}

window.feedLoaded = function(result) {
var blog = document.getElementById("blog");
var read = blog.getElementsByClassName("read")[0];
for (var i = 0; i < result.length && i < 2; i++) {
var entry = result[i];
var title = document.createElement("a");
title.className = "title";
title.href = entry.Link;
title.innerHTML = entry.Title;
blog.insertBefore(title, read);
var extract = document.createElement("div");
extract.className = "extract";
extract.innerHTML = entry.Summary;
blog.insertBefore(extract, read);
var when = document.createElement("div");
when.className = "when";
when.innerHTML = "Published " + readableTime(entry.Time);
blog.insertBefore(when, read);
}
}

window.initFuncs.push(function() {
// Load blog feed.
$('<script/>').attr('text', 'text/javascript')
.attr('src', '//blog.golang.org/.json?jsonp=feedLoaded')
.appendTo('body');

// Set the video at random.
var videos = [
{h: 241, s: "//www.youtube.com/embed/ytEkHepK08c"}, // Tour of Go
{h: 241, s: "//www.youtube.com/embed/f6kdp27TYZs"}, // Concurrency Patterns
{h: 233, s: "//player.vimeo.com/video/69237265"} // Simple environment
];
var v = videos[Math.floor(Math.random()*videos.length)];
$('#video iframe').attr('height', v.h).attr('src', v.s);
// Compute the aspect ratio (as a percentage) of the video
// using the fixed width 415 and the height of the current video, v.h.
var ar = 100*v.h/415;
$('.js-frontpage-video').attr('style', '--aspect-ratio-padding: ' + ar + '%;');
});

{{end}}
})();
</script>
1 change: 1 addition & 0 deletions content/static/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var files = []string{
"codewalk.html",
"codewalkdir.html",
"dirlist.html",
"doc/root.html",
"error.html",
"example.html",
"godoc.html",
Expand Down
4 changes: 3 additions & 1 deletion content/static/static.go

Large diffs are not rendered by default.

0 comments on commit d83058c

Please sign in to comment.