Skip to content

Commit

Permalink
Fix doc categories
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Feb 27, 2025
1 parent 1853948 commit 8efa2c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/resources/save_config.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "nxos_save_config Resource - terraform-provider-nxos"
subcategory: ""
subcategory: "General"
description: |-
This resources is used to save the config which is the equivalent of doing a copy running-config startup-config in the device CLI.
---
Expand Down
32 changes: 19 additions & 13 deletions gen/doc_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package main
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"

Expand All @@ -39,6 +40,11 @@ type YamlConfig struct {

var docPaths = []string{"./docs/data-sources/", "./docs/resources/"}

var extraDocs = map[string]string{
"rest": "General",
"save_config": "General",
}

func SnakeCase(s string) string {
var g []string

Expand All @@ -56,7 +62,7 @@ func main() {

// Load configs
for i, filename := range items {
yamlFile, err := ioutil.ReadFile(filepath.Join(definitionsPath, filename.Name()))
yamlFile, err := os.ReadFile(filepath.Join(definitionsPath, filename.Name()))
if err != nil {
log.Fatalf("Error reading file: %v", err)
}
Expand All @@ -72,7 +78,7 @@ func main() {
for i := range configs {
for _, path := range docPaths {
filename := path + SnakeCase(configs[i].Name) + ".md"
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
log.Fatalf("Error opening documentation: %v", err)
}
Expand All @@ -84,17 +90,17 @@ func main() {
}
}

// update nxos_rest resource and data source
for _, path := range docPaths {
filename := path + "rest.md"
content, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatalf("Error opening documentation: %v", err)
}

s := string(content)
s = strings.ReplaceAll(s, `subcategory: ""`, `subcategory: "General"`)
// Update extra doc categories
for doc, cat := range extraDocs {
for _, path := range docPaths {
filename := path + doc + ".md"
content, err := os.ReadFile(filename)
if err == nil {
s := string(content)
s = strings.ReplaceAll(s, `subcategory: ""`, `subcategory: "`+cat+`"`)

ioutil.WriteFile(filename, []byte(s), 0644)
os.WriteFile(filename, []byte(s), 0644)
}
}
}
}

0 comments on commit 8efa2c2

Please sign in to comment.