From 9771c5bf56c2050408056e1de34a11ee3970832b Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 24 Aug 2023 20:46:45 +0200 Subject: [PATCH] chore: properly render mkdocs.yml Signed-off-by: Matthieu MOREL --- .github/dependabot.yml | 3 ++- mkdocs.yml | 3 ++- modulegen/internal/dependabot/writer.go | 9 +++++++-- modulegen/internal/mkdocs/writer.go | 23 ++++++++++++++++++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1231cabf86..317b9dc0ef 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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 diff --git a/mkdocs.yml b/mkdocs.yml index 99b10620e7..bdcdf7ad17 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,3 +1,4 @@ +# This file is autogenerated by the 'modulegen' tool. site_name: Testcontainers for Go site_url: https://golang.testcontainers.org plugins: @@ -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 diff --git a/modulegen/internal/dependabot/writer.go b/modulegen/internal/dependabot/writer.go index 611bd63783..0a134f827a 100644 --- a/modulegen/internal/dependabot/writer.go +++ b/modulegen/internal/dependabot/writer.go @@ -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) } diff --git a/modulegen/internal/mkdocs/writer.go b/modulegen/internal/mkdocs/writer.go index a625d2ab27..4d6a685af6 100644 --- a/modulegen/internal/mkdocs/writer.go +++ b/modulegen/internal/mkdocs/writer.go @@ -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) }