Skip to content

Commit

Permalink
Disable category.json rendering and clean up URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
milldr committed Aug 1, 2024
1 parent 0c0a28e commit 5fd05d7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 29 deletions.
7 changes: 5 additions & 2 deletions .github/actions/build-website/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ runs:
with:
python-version: '3.10'

- name: "Install Python Dependencies"
- name: "Initialize Build Harness"
shell: bash
run: |
make init
- name: "Install Python Dependencies"
shell: bash
run: |
pip install -r scripts/docs-collator/requirements.txt
- name: "Install terraform-docs"
Expand Down Expand Up @@ -91,5 +95,4 @@ runs:
GOOGLE_TAG_MANAGER: ${{ inputs.google_tag_manager }}
GOOGLE_SITE_VERIFICATION_ID: ${{ inputs.google_site_verification_id }}
run: |
make init
make build-production
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions scripts/docs-collator/ModuleRenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def render(self, repo):
repo, module_download_dir, module_docs_dir
)

self.__create_index_for_provider(repo)
self.__create_indexes_for_subfolders(repo)
# Disable category.json for now
# self.__create_index_for_provider(repo)
# self.__create_indexes_for_subfolders(repo)

def __render_readme(self, module_download_dir, module_docs_dir):
readme_yaml_file = os.path.join(module_download_dir, README_YAML)
Expand Down
32 changes: 16 additions & 16 deletions scripts/docs-collator/templates/components/terraform-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ content: |-
{{ .Header }}
### Terraform
## Terraform
{{ if ne (len .Module.Requirements) 0 -}}
#### Version Requirements
### Version Requirements
{{ range .Module.Providers }}
- `{{ .Name }}`{{ if .Version }}, version: `{{ .Version }}`{{ end }}
{{- end }}
{{- end }}
{{ if ne (len .Module.Providers) 0 -}}
#### Providers
### Providers
{{ range .Module.Providers }}
- `{{ .Name }}`{{ if .Version }}, version: `{{ .Version }}`{{ end }}
{{- end }}
{{- end }}
{{ if ne (len .Module.ModuleCalls) 0 -}}
#### Modules
### Modules
Name | Version | Source | Description
--- | --- | --- | ---
Expand All @@ -40,7 +40,7 @@ content: |-
{{- if ne (len .Module.Resources) 0 }}
#### Resources
### Resources
The following resources are used by this module:
{{ range .Module.Resources }}
Expand All @@ -53,7 +53,7 @@ content: |-
{{- end }}
{{ if ne (len .Module.Resources) 0 -}}
#### Data Sources
### Data Sources
The following data sources are used by this module:
{{ range .Module.Resources }}
Expand All @@ -65,12 +65,12 @@ content: |-
{{- end }}
{{- end }}
#### Required Inputs
### Required Inputs
<dl>
{{- range .Module.Inputs }}
{{- if and (not (has .Name $context_variables)) .Required }}
<dt>`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} <i>required</i>{{ if contains "OBSOLETE: " (tostring .Description) }} <strong>OBSOLETE</strong>{{ end }}</dt>
<dt><a id="{{ .Name }}" href="#{{ .Name }}">`{{ .Name }}`</a>{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} <i>required</i>{{ if contains "OBSOLETE: " (tostring .Description) }} <strong>OBSOLETE</strong>{{ end }}</dt>
<dd>
{{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}}
{{- range $lines }}
Expand All @@ -95,12 +95,12 @@ content: |-
{{ if $optional -}}
#### Optional Inputs
### Optional Inputs
<dl>
{{- range .Module.Inputs }}
{{- if and (not (has .Name $context_variables)) (not .Required) }}
<dt>`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} <i>optional</i>{{ if contains "OBSOLETE: " (tostring .Description) }} <strong>OBSOLETE</strong>{{ end }}</dt>
<dt><a id="{{ .Name }}" href="#{{ .Name }}">`{{ .Name }}`</a>{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} <i>optional</i>{{ if contains "OBSOLETE: " (tostring .Description) }} <strong>OBSOLETE</strong>{{ end }}</dt>
<dd>
{{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}}
{{- range $lines }}
Expand All @@ -114,7 +114,7 @@ content: |-
```
<br/>
{{ end }}
**Default value:** {{ if lt (len (split "\n" .GetValue)) 2 }}`{{ .GetValue }}`{{ else }}
**Default value:** {{ if lt (len (split "\n" .GetValue)) 2 }}`{{ .GetValue | replace "{}" "{ }" | replace "[]" "[ ]" }}`{{ else }}
```hcl
{{- $lines := regexSplit "\n" .GetValue -1 -}}
{{- range $lines }}
Expand All @@ -128,7 +128,7 @@ content: |-
</dl>
{{ end }}
#### Context Variables
### Context Variables
<details>
<summary>
Expand All @@ -138,7 +138,7 @@ content: |-
<dl>
{{- range .Module.Inputs }}
{{- if and (has .Name $context_variables) }}
<dt>`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} <i>{{ ternary .Required "required" "optional" }}</i>{{ if contains "OBSOLETE: " (tostring .Description) }} <strong>OBSOLETE</strong>{{ end }}</dt>
<dt><a id="{{ .Name }}" href="#{{ .Name }}">`{{ .Name }}`</a>{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} <i>{{ ternary .Required "required" "optional" }}</i>{{ if contains "OBSOLETE: " (tostring .Description) }} <strong>OBSOLETE</strong>{{ end }}</dt>
<dd>
{{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}}
{{- range $lines }}
Expand All @@ -152,7 +152,7 @@ content: |-
```
<br/>
{{ end }}
**Default value:** {{ if lt (len (split "\n" .GetValue)) 2 }}`{{ .GetValue }}`{{ else }}
**Default value:** {{ if lt (len (split "\n" .GetValue)) 2 }}`{{ .GetValue | replace "{}" "{ }" | replace "[]" "[ ]" }}`{{ else }}
```hcl
{{- $lines := regexSplit "\n" .GetValue -1 -}}
{{- range $lines }}
Expand All @@ -167,11 +167,11 @@ content: |-
</details>
{{ if ne (len .Module.Outputs) 0 -}}
#### Outputs
### Outputs
<dl>
{{- range .Module.Outputs }}
<dt>`{{ .Name }}`{{ if contains "OBSOLETE: " (tostring .Description) }} <strong>OBSOLETE</strong>{{ end }}</dt>
<dt><a id="{{ .Name }}" href="#{{ .Name }}">`{{ .Name }}`</a>{{ if contains "OBSOLETE: " (tostring .Description) }} <strong>OBSOLETE</strong>{{ end }}</dt>
<dd>
{{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "" | default "n/a" ) -1 -}}
{{- range $lines }}
Expand Down
17 changes: 10 additions & 7 deletions scripts/docs-collator/utils/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def fix_mdx_format(content):
"""
1. Replace all special characters outside code blocks for MDX support
2. Fix the formatting for <details><summary> html tags
3. Remove < and > from URLs
Even after we re-render all terraform-docs, there are still some issues in our markdown files.
This function cleans up the remaining issues.
Expand All @@ -105,13 +106,15 @@ def fix_mdx_format(content):

# Perform replacements only if not in a code block
if not in_code_block:
for pattern, replacement in replacements.items():
line = re.sub(pattern, replacement, line)

# Strip < and > from URLs
# f.e. https://github.com/cloudposse/terraform-aws-ec2-ami-backup/blob/1e3706b662f9f55362c54b90d466d4083b539df4/README.yaml#L67
# if "http" in line and line.startswith('<') and line.endswith('>'):
# line = line[1:-1] # Strip the first and last character
# Split the line by inline code blocks (single backticks)
parts = re.split(r'(`[^`]*`)', line)
for i, part in enumerate(parts):
# Only perform replacements on parts that are not inline code blocks
if not part.startswith('`') and not part.endswith('`'):
for pattern, replacement in replacements.items():
part = re.sub(pattern, replacement, part)
parts[i] = part
line = ''.join(parts)

result.append(line)

Expand Down

0 comments on commit 5fd05d7

Please sign in to comment.