From 5fd05d7bc70fae64b9592da610d139f418aa48f4 Mon Sep 17 00:00:00 2001 From: milldr Date: Thu, 1 Aug 2024 10:57:25 -0400 Subject: [PATCH] Disable category.json rendering and clean up URLs --- .github/actions/build-website/action.yml | 7 ++-- package-lock.json | 7 ++-- scripts/docs-collator/ModuleRenderer.py | 5 +-- .../templates/components/terraform-docs.yml | 32 +++++++++---------- scripts/docs-collator/utils/rendering.py | 17 ++++++---- 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/.github/actions/build-website/action.yml b/.github/actions/build-website/action.yml index 9a54a2a67..148bca8df 100644 --- a/.github/actions/build-website/action.yml +++ b/.github/actions/build-website/action.yml @@ -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" @@ -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 diff --git a/package-lock.json b/package-lock.json index bcf4b212a..c095388b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6227,8 +6227,8 @@ "license": "MIT" }, "node_modules/custom-loaders": { - "version": "0.0.0", - "resolved": "file:plugins/custom-loaders" + "resolved": "plugins/custom-loaders", + "link": true }, "node_modules/cytoscape": { "version": "3.30.1", @@ -18566,6 +18566,9 @@ "type": "github", "url": "https://github.com/sponsors/wooorm" } + }, + "plugins/custom-loaders": { + "version": "0.0.0" } } } diff --git a/scripts/docs-collator/ModuleRenderer.py b/scripts/docs-collator/ModuleRenderer.py index 263393b28..2f076b515 100644 --- a/scripts/docs-collator/ModuleRenderer.py +++ b/scripts/docs-collator/ModuleRenderer.py @@ -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) diff --git a/scripts/docs-collator/templates/components/terraform-docs.yml b/scripts/docs-collator/templates/components/terraform-docs.yml index 84331ef58..5644ca3c6 100644 --- a/scripts/docs-collator/templates/components/terraform-docs.yml +++ b/scripts/docs-collator/templates/components/terraform-docs.yml @@ -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 --- | --- | --- | --- @@ -40,7 +40,7 @@ content: |- {{- if ne (len .Module.Resources) 0 }} - #### Resources + ### Resources The following resources are used by this module: {{ range .Module.Resources }} @@ -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 }} @@ -65,12 +65,12 @@ content: |- {{- end }} {{- end }} - #### Required Inputs + ### Required Inputs
{{- range .Module.Inputs }} {{- if and (not (has .Name $context_variables)) .Required }} -
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} required{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
+
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} required{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
{{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}} {{- range $lines }} @@ -95,12 +95,12 @@ content: |- {{ if $optional -}} - #### Optional Inputs + ### Optional Inputs
{{- range .Module.Inputs }} {{- if and (not (has .Name $context_variables)) (not .Required) }} -
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} optional{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
+
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} optional{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
{{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}} {{- range $lines }} @@ -114,7 +114,7 @@ content: |- ```
{{ 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 }} @@ -128,7 +128,7 @@ content: |-
{{ end }} - #### Context Variables + ### Context Variables
@@ -138,7 +138,7 @@ content: |-
{{- range .Module.Inputs }} {{- if and (has .Name $context_variables) }} -
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} {{ ternary .Required "required" "optional" }}{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
+
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} {{ ternary .Required "required" "optional" }}{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
{{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}} {{- range $lines }} @@ -152,7 +152,7 @@ content: |- ```
{{ 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 }} @@ -167,11 +167,11 @@ content: |-
{{ if ne (len .Module.Outputs) 0 -}} - #### Outputs + ### Outputs
{{- range .Module.Outputs }} -
`{{ .Name }}`{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
+
`{{ .Name }}`{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
{{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "" | default "n/a" ) -1 -}} {{- range $lines }} diff --git a/scripts/docs-collator/utils/rendering.py b/scripts/docs-collator/utils/rendering.py index 3b8900017..9121dc750 100644 --- a/scripts/docs-collator/utils/rendering.py +++ b/scripts/docs-collator/utils/rendering.py @@ -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
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. @@ -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)