Skip to content

Commit

Permalink
Add newcode shortcode
Browse files Browse the repository at this point in the history
    
This is for downloadable code snippet.
Also add link to code-snippet-formatting pointing to above
This is for #18231
  • Loading branch information
anshuprateek-grabtaxi committed Jan 25, 2020
1 parent d60ca0b commit 0b0244b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions content/en/docs/contribute/style/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,43 @@ The output is:
{{< kat-button >}}
### Downloadable code blocks
Use {{</* codenew */>}} to make code samples (manifests) downloadable.
A way to include code in your topic is to create a new, complete sample file (or group of sample files) and then reference the sample from your topic. Use this method to include sample YAML files when the sample is generic and reusable, and you want the reader to try it out themselves.
```{{</* codenew file="application/deployment.yaml" */>}}```
The output is:
{{< codenew file="application/deployment.yaml" >}}
Here is an example page containing that shortcode:
https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/
When adding a new standalone sample file, such as a YAML file, place the code in one of the <LANG>/examples/ subdirectories where <LANG> is the language for the topic. In your topic file, use the codenew shortcode:
```{{</* codenew file="<RELPATH>/my-example-yaml>" */>}}```
where `<RELPATH>` is the path to the file to include, relative to the
`examples` directory. The following Hugo shortcode references a YAML
file located at `/content/en/examples/pods/storage/gce-volume.yaml`.
```none
{{</* codenew file="pods/storage/gce-volume.yaml" */>}}
```

Typically, code samples do not change, however natural-language comments can be translated.
For example: https://github.com/kubernetes/website/blob/master/content/ko/examples/application/deployment.yaml is the `ko` version for https://github.com/kubernetes/website/blob/master/content/en/examples/application/deployment.yaml

You may also tell the reader about how to run the code after downloading the file by mentioning relevant commands like

```kubectl apply -f /path/to/<filename.yaml>```

## Common Shortcode Issues

### Ordered Lists
Expand Down

0 comments on commit 0b0244b

Please sign in to comment.