Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: properly render mkdocs.yml #1521

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
}
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this override more than in the original PR. Neat!

}

// 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)
}