internal/web: consistently remove OMIT lines from code blocks

OMIT lines may appear in code before or after the section intended to be
displayed in a code block, however in the case of playground code blocks
those lines are actually included. This change makes sure we always
filter out the OMIT lines when generating code blocks, and adds a test.

I noticed this when the playground snippets in the race detector blog
post (https://go.dev/blog/race-detector) gave this error:

  package play: build constraints exclude all Go files in /tmp/sandbox2684341108

This is because those programs begin with the lines `// +build OMIT`,
which were never intended to be executed.

Change-Id: I5b0320da139741c789126f0c9d3dabc7044cd350
Reviewed-on: https://go-review.googlesource.com/c/website/+/466775
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2 files changed
tree: 6c49b547fd67b93712617e1896b4f90319428a36
  1. _content/
  2. _later/
  3. cmd/
  4. internal/
  5. tour/
  6. .eslintrc.yaml
  7. .gitattributes
  8. .prettierrc.yaml
  9. .stylelintrc.yaml
  10. codereview.cfg
  11. content.go
  12. CONTRIBUTING.md
  13. go-app-deploy.sh
  14. go.mod
  15. go.sum
  16. jest-transform.cjs
  17. LICENSE
  18. npm
  19. npx
  20. package-lock.json
  21. package.json
  22. PATENTS
  23. README.md
  24. tsconfig.json
README.md

Go website

Go Reference

This repo holds content and serving programs for the go.dev and golang.org web sites.

Content is in _content/ (go.dev) and tour/ (go.dev/tour). Server code is in cmd/ and internal/.

To run the combined go.dev+golang.org server to preview local content changes, use:

go run ./cmd/golangorg

The supporting programs cmd/admingolangorg and cmd/googlegolangorg are the servers for admin.golang.org and google.golang.org. (They do not use the _content/ directories.)

Each command directory has its own README.md explaining deployment.

JS/TS/CSS Formatting

This repository uses eslint to format JS and TS files, and stylelint to format CSS files.

See also:

It is encouraged that all JS, TS, and CSS code be run through formatters before submitting a change. However, it is not a strict requirement enforced by CI.

Installing npm Dependencies:

  1. Install docker
  2. Create a .gitignore file at repo root
  3. Add .gitignore and node_modules to .gitignore
  4. Run ./npm install

Run ESlint

./npx eslint [options] [file] [dir]

Run Stylelint

./npx stylelint [input] [options]

TypeScript Support

TypeScript files served from _content are transformed into JavaScript. Reference .ts files in html templates as module code.

<script type="module" src="/ts/filename.ts">

Write unit tests for TypeScript code using the jest testing framework.

Run Jest

./npx jest [TestPathPattern]

Deploying

Each time a CL is reviewed and submitted, the code is deployed to App Engine. See cmd/golangorg/README.md for details.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://go.dev/doc/contribute.

The main issue tracker for the website repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/website:” in the subject line, so it is easy to find.