Skip to content

Commit

Permalink
chore: properly render mkdocs.yml (#1521)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 authored Aug 25, 2023
1 parent 9ef033f commit cb9e467
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# This file is autogenerated by the modulegen code generator. Please look at the generator code when updating it.
# This file is autogenerated by the 'modulegen' tool.
# Please look at the generator code when updating it.
version: 2
updates:
- package-ecosystem: github-actions
Expand Down
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This file is autogenerated by the 'modulegen' tool.
site_name: Testcontainers for Go
site_url: https://golang.testcontainers.org
plugins:
Expand Down Expand Up @@ -31,8 +32,8 @@ markdown_extensions:
permalink: true
- attr_list
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
emoji_index: !!python/name:materialx.emoji.twemoji
nav:
- Home: index.md
- Quickstart: quickstart.md
Expand Down
9 changes: 7 additions & 2 deletions modulegen/internal/dependabot/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ package dependabot

import (
"os"
"path/filepath"

"gopkg.in/yaml.v3"
)

func writeConfig(configFile string, config *Config) error {
err := os.MkdirAll(filepath.Dir(configFile), 0o755)
if err != nil {
return err
}
data, err := yaml.Marshal(config)
if err != nil {
return err
}
header := "# This file is autogenerated by the modulegen code generator. Please look at the generator code when updating it.\n"
header := "# This file is autogenerated by the 'modulegen' tool.\n# Please look at the generator code when updating it.\n"
data = append([]byte(header), data...)
return os.WriteFile(configFile, data, 0o777)
return os.WriteFile(configFile, data, 0o644)
}
23 changes: 22 additions & 1 deletion modulegen/internal/mkdocs/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@ package mkdocs

import (
"os"
"path/filepath"
"strings"

"gopkg.in/yaml.v3"
)

func writeConfig(configFile string, config *Config) error {
err := os.MkdirAll(filepath.Dir(configFile), 0o755)
if err != nil {
return err
}
data, err := yaml.Marshal(config)
if err != nil {
return err
}
return os.WriteFile(configFile, data, 0o777)
return os.WriteFile(configFile, overrideData(data), 0o644)
}

// simple solution to replace the empty strings, as mapping those fields
// into the MkDocs config is not supported yet
func overrideData(data []byte) []byte {
content := "# This file is autogenerated by the 'modulegen' tool.\n" + string(data)
content = setEmoji(content, "generator", "to_svg")
content = setEmoji(content, "index", "twemoji")
return []byte(content)
}

func setEmoji(content string, key string, value string) string {
old := "emoji_" + key + `: ""`
new := "emoji_" + key + ": !!python/name:materialx.emoji." + value
return strings.ReplaceAll(content, old, new)
}

0 comments on commit cb9e467

Please sign in to comment.