diff --git a/README.md b/README.md index 270239b5..6e098442 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # GopherJS.org +## Generating + +```bash +go generate github.com/gopherjs/gopherjs.github.io/... +``` + ## Todo * Tweak look and feel, logo, etc. diff --git a/doc.go b/doc.go new file mode 100644 index 00000000..2d687440 --- /dev/null +++ b/doc.go @@ -0,0 +1,6 @@ +// Package gopherjswebsite is the www.gopherjs.org website source. +// +// It should be updated with `go generate github.com/gopherjs/gopherjs.github.io/...`. +package gopherjswebsite + +//go:generate go run generate.go diff --git a/generate.go b/generate.go new file mode 100644 index 00000000..9c9af070 --- /dev/null +++ b/generate.go @@ -0,0 +1,68 @@ +// +build generate + +package main + +import ( + "bytes" + "fmt" + "io/ioutil" + "log" + "net/http" + "text/template" +) + +func t(text string) *template.Template { + return template.Must(template.New("").Parse(text)) +} + +// Filename -> Template. +var templates = map[string]*template.Template{ + + "index.md": t(`--- +# generated by generate.go; DO NOT EDIT +layout: index +title: Home +permalink: / +--- + +{{.HTTPGet "https://raw.githubusercontent.com/gopherjs/gopherjs/master/README.md"}}`), +} + +type data struct{} + +// HTTPGet fetches the contents at the given url. +func (data) HTTPGet(url string) (string, error) { + resp, err := http.Get(url) + if err != nil { + return "", err + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return "", err + } + return string(body), nil +} + +func gen() error { + for filename, t := range templates { + var buf bytes.Buffer + err := t.Execute(&buf, data{}) + if err != nil { + return err + } + fmt.Println("writing", filename) + err = ioutil.WriteFile(filename, buf.Bytes(), 0644) + if err != nil { + return err + } + } + return nil +} + +func main() { + err := gen() + if err != nil { + log.Fatalln(err) + } +} diff --git a/index.md b/index.md index 93ead15e..5a43fb64 100644 --- a/index.md +++ b/index.md @@ -1,4 +1,5 @@ --- +# generated by generate.go; DO NOT EDIT layout: index title: Home permalink: / @@ -7,6 +8,8 @@ permalink: / GopherJS - A compiler from Go to JavaScript ------------------------------------------- +[![Circle CI](https://circleci.com/gh/gopherjs/gopherjs.svg?style=svg)](https://circleci.com/gh/gopherjs/gopherjs) + 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/). ### What is supported? @@ -31,6 +34,7 @@ Now you can use `gopherjs build [files]` or `gopherjs install [package]` which - Use `float64` instead of `float32`. ### Community +- [#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)) - [Google Group](https://groups.google.com/d/forum/gopherjs) - [Bindings to JavaScript APIs and libraries](https://github.com/gopherjs/gopherjs/wiki/bindings) - [GopherJS on Twitter](https://twitter.com/GopherJS)