Skip to content

Commit fd45202

Browse files
committed
content: update README
The README does not mention that files that are newly added to the content directory need to be added manually to static/gen.go file before running go generate. This change fixes that. Update the description of how the static content is used in concert with the content from the main Go repository in more detail. Replace go install && ./golangorg with go run, since it's shorter. Add a TODO note mentioning improvements that can be made in the near future to simplify this process. Updates golang/go#29206 Change-Id: I8a85bcb783c7c10975aa6fd5a7ad464f05d42dd2 Reviewed-on: https://go-review.googlesource.com/c/website/+/207262 Reviewed-by: Andrew Bonventre <[email protected]>
1 parent 7323790 commit fd45202

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

content/README.md

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# content
22

3-
This directory contains doc/, static/, favicon.ico, and robots.txt. The
4-
executable lives at golang.org/x/website/cmd/golangorg.
3+
The `static` directory contains static content. This content is used alongside
4+
the content in the main Go repository by the [`golangorg`](golang.org/x/website/cmd/golangorg)
5+
binary when serving the [golang.org](https://golang.org) website.
6+
The details of the directory to path mapping are documented at the top of
7+
[`cmd/golangorg/main.go`](https://go.googlesource.com/website/+/refs/heads/master/cmd/golangorg/main.go).
8+
9+
TODO(dmitshur): The process below can be simplified.
10+
See [golang.org/issue/29206#issuecomment-536099768](https://golang.org/issue/29206#issuecomment-536099768).
511

612
## Development mode
713

8-
In production, CSS/JS/template assets need to be compiled into the golangorg
14+
In production, CSS/JS/template assets need to be compiled into the `golangorg`
915
binary. It can be tedious to recompile assets every time, but you can pass a
1016
flag to load CSS/JS/templates from disk every time a page loads:
1117

@@ -15,16 +21,31 @@ golangorg -templates=$GOPATH/src/golang.org/x/website/content/static -http=:6060
1521

1622
## Recompiling static assets
1723

18-
The files that live at `static/style.css`, `static/jquery.js` and so on are not
19-
present in the final binary. They are placed into `static/static.go` by running
20-
`go generate`. So to compile a change and test it in your browser:
24+
Files such as `static/style.css`, `static/doc/copyright.html` and so on are not
25+
present in the final binary. They are embedded into `static/static.go` by running
26+
`go generate`. To compile a change and test it in your browser:
27+
28+
1) Make changes to an existing file such as `static/style.css`.
29+
30+
2) If a new file is being added to the `static` directory, add it to the `files`
31+
slice in `static/gen`.
2132

22-
1) Make changes to e.g. `static/style.css`.
33+
3) Run `go generate golang.org/x/website/content/static` so `static/static.go` is
34+
up to date.
2335

24-
2) Run `go generate golang.org/x/website/content/static` so `static/static.go` picks
25-
up the change.
36+
4) Run `go run golang.org/x/website/cmd/golangorg -http=:6060` and view your changes
37+
in the browser at http://localhost:6060. You may need to disable your browser's cache
38+
to avoid reloading a stale file.
2639

27-
3) Run `go install golang.org/x/website/cmd/golangorg` so the compiled `golangorg` binary picks up the change.
40+
A test exists to catch a possible mistake of forgetting to regenerate static assets:
2841

29-
4) Run `golangorg -http=:6060` and view your changes in the browser. You may need
30-
to disable your browser's cache to avoid reloading a stale file.
42+
```
43+
website $ go test ./...
44+
--- FAIL: TestStaticIsUpToDate (0.06s)
45+
gen_test.go:27: static.go is stale. Run:
46+
$ go generate golang.org/x/website/content/static
47+
$ git diff
48+
to see the differences.
49+
FAIL
50+
FAIL golang.org/x/website/content/static 0.650s
51+
```

0 commit comments

Comments
 (0)