pulumi/pkg/codegen/docs
bors[bot] cddee7a471
Merge #11937
11937: Fix broken links related to resources named "index" r=sean1588 a=sean1588

fixes: https://github.com/pulumi/registry/issues/951

This PR fixes an issue where a resource named "index" has trouble resolving the url likely because "index" is some sort of reserved keyword. This change prepends a double underscore to the resource name in the URL that gets generated and also updates the links that reference this on both the module page and the package tree in the left nav. Visually everything looks the same, it is just the directory name and underlying links that get updated. It will still display as "Index" when rendered on the page.

As an example this route `/registry/packages/gcp/api-docs/firestore/index/` ends up resulting in a 404. With this change we add a double underscore which results in the following route `registry/packages/gcp/api-docs/firestore/__index/` and is now able to render the page.


![Peek 2023-01-20 12-00](https://user-images.githubusercontent.com/16751381/213794883-5e55d303-eaba-40ce-85c2-26443daee393.gif)


Co-authored-by: Sean Holung <sean.holung@gmail.com>
2023-01-20 22:10:11 +00:00
..
templates update package details template 2023-01-13 15:38:22 -08:00
README.md Replace Hugo shortcodes (#9491) 2022-04-29 15:04:15 -07:00
examples.go sdk/go: Remove 'nolint' directives from package docs 2023-01-06 09:06:47 -08:00
gen.go Merge #11937 2023-01-20 22:10:11 +00:00
gen_function.go add to function gen 2023-01-17 14:17:12 -08:00
gen_kubernetes.go sdk/go: Remove 'nolint' directives from package docs 2023-01-06 09:06:47 -08:00
gen_method.go Initial implementation of simplified invokes for dotnet and nodejs 2023-01-11 14:17:14 -08:00
gen_test.go pkg/codegen/docs: Fix data race in tests 2023-01-07 10:01:32 -08:00
package_tree.go Update error handling (#8406) 2021-11-12 18:37:17 -08:00
package_tree_test.go pkg/codegen/docs: Fix data race in tests 2023-01-07 10:01:32 -08:00
utils.go try hyphens 2023-01-20 12:53:34 -08:00
utils_test.go sdk/go: Remove 'nolint' directives from package docs 2023-01-06 09:06:47 -08:00

README.md

Docs generator

This generator generates resource-level docs by utilizing the Pulumi schema.

Crash course on templates

The templates use Go's built-in html/template package to process templates with data. The driver for this doc generator (e.g. tfbridge for TF-based providers) then persists each file from memory onto the disk as .md files.

Although we are using the html/template package, it has the same exact interface as the text/template package, except for some HTML specific things. Therefore, all of the functions available in the text/template package are also available with the html/template package.

  • Data can be injected using {{.PropertyName}}.
  • Nested properties can be accessed using the dot notation, i.e. {{.Property1.Property2}}.
  • Templates can inject other templates using the {{template "template_name"}} directive.
    • For this to work, you will need to first define the named template using {{define "template_name"}}.
  • You can pass data to nested templates by simply passing an argument after the template's name.
  • To remove whitespace from injected values, use the - in the template tags.
    • For example, {{if .SomeBool}} some text {{- else}} some other text {{- end}}. Note the use of - to eliminate whitespace from the enclosing text.
    • Read more here.
  • To render un-encoded content use the custom global function htmlSafe.
    • Note: This should only be used if you know for sure you are not injecting any user-generated content, as it by-passes the HTML encoding.
  • To render strings to Markdown, use the custom global function markdownify.
  • To print regular strings, that share the same syntax as the Go templating engine, use the built-in global function print function.

Learn more from here: https://curtisvermeeren.github.io/2017/09/14/Golang-Templates-Cheatsheet

Modifying templates and updating tests

We run tests that validate our template-rendering output. If you need to make change that produces a set of Markdown files that differs from the set that we use in our tests (see codegen/testing/test/testdata/**/*.md), your pull-request checks will fail, and to get them to pass, you'll need to modify the test data to match the output produced by your change.

For minor diffs, you can just update the test files manually and include those updates with your PR. But for large diffs, you may want to regenerate the full set. To do that, from the root of the repo, run:

cd pkg/codegen/docs && PULUMI_ACCEPT=true go test . && cd -