Skip to content

Commit 699155b

Browse files
committed
Merge pull request #35 from gopherjs/generate-index-page-content-from-canonical-source
Make index.md generated from canonical GopherJS README.
2 parents a8a3d8a + 40ad2e4 commit 699155b

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# GopherJS.org
22

3+
## Generating
4+
5+
```bash
6+
go generate github.com/gopherjs/gopherjs.github.io/...
7+
```
8+
39
## Todo
410

511
* Tweak look and feel, logo, etc.

doc.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Package gopherjswebsite is the www.gopherjs.org website source.
2+
//
3+
// It should be updated with `go generate github.com/gopherjs/gopherjs.github.io/...`.
4+
package gopherjswebsite
5+
6+
//go:generate go run generate.go

generate.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// +build generate
2+
3+
package main
4+
5+
import (
6+
"bytes"
7+
"fmt"
8+
"io/ioutil"
9+
"log"
10+
"net/http"
11+
"text/template"
12+
)
13+
14+
func t(text string) *template.Template {
15+
return template.Must(template.New("").Parse(text))
16+
}
17+
18+
// Filename -> Template.
19+
var templates = map[string]*template.Template{
20+
21+
"index.md": t(`---
22+
# generated by generate.go; DO NOT EDIT
23+
layout: index
24+
title: Home
25+
permalink: /
26+
---
27+
28+
{{.HTTPGet "https://raw.githubusercontent.com/gopherjs/gopherjs/master/README.md"}}`),
29+
}
30+
31+
type data struct{}
32+
33+
// HTTPGet fetches the contents at the given url.
34+
func (data) HTTPGet(url string) (string, error) {
35+
resp, err := http.Get(url)
36+
if err != nil {
37+
return "", err
38+
}
39+
defer resp.Body.Close()
40+
body, err := ioutil.ReadAll(resp.Body)
41+
if err != nil {
42+
return "", err
43+
}
44+
return string(body), nil
45+
}
46+
47+
func gen() error {
48+
for filename, t := range templates {
49+
var buf bytes.Buffer
50+
err := t.Execute(&buf, data{})
51+
if err != nil {
52+
return err
53+
}
54+
fmt.Println("writing", filename)
55+
err = ioutil.WriteFile(filename, buf.Bytes(), 0644)
56+
if err != nil {
57+
return err
58+
}
59+
}
60+
return nil
61+
}
62+
63+
func main() {
64+
err := gen()
65+
if err != nil {
66+
log.Fatalln(err)
67+
}
68+
}

index.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
# generated by generate.go; DO NOT EDIT
23
layout: index
34
title: Home
45
permalink: /
@@ -7,6 +8,8 @@ permalink: /
78
GopherJS - A compiler from Go to JavaScript
89
-------------------------------------------
910

11+
[![Circle CI](https://circleci.com/gh/gopherjs/gopherjs.svg?style=svg)](https://circleci.com/gh/gopherjs/gopherjs)
12+
1013
GopherJS compiles Go code ([golang.org](http://golang.org/)) to pure JavaScript code. Its main purpose is to give you the opportunity to write front-end code in Go which will still run in all browsers. Give GopherJS a try on the [GopherJS Playground](http://gopherjs.github.io/playground/).
1114

1215
### What is supported?
@@ -31,6 +34,7 @@ Now you can use `gopherjs build [files]` or `gopherjs install [package]` which
3134
- Use `float64` instead of `float32`.
3235

3336
### Community
37+
- [#gopherjs Channel on Gophers Slack](https://gophers.slack.com/messages/gopherjs/) (invites to Gophers Slack are available [here](http://blog.gopheracademy.com/gophers-slack-community/#how-can-i-be-invited-to-join:2facdc921b2310f18cb851c36fa92369))
3438
- [Google Group](https://groups.google.com/d/forum/gopherjs)
3539
- [Bindings to JavaScript APIs and libraries](https://github.com/gopherjs/gopherjs/wiki/bindings)
3640
- [GopherJS on Twitter](https://twitter.com/GopherJS)

0 commit comments

Comments
 (0)