From 29cbec8575e0d16b2d0a69e296dea6622d518dae Mon Sep 17 00:00:00 2001 From: Virgil Date: Wed, 1 Apr 2026 06:41:38 +0000 Subject: [PATCH] fix(docs): sync zensical readmes to index Co-Authored-By: Virgil --- cmd/docs/cmd_sync.go | 13 +++++++++---- cmd/docs/cmd_sync_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 cmd/docs/cmd_sync_test.go diff --git a/cmd/docs/cmd_sync.go b/cmd/docs/cmd_sync.go index d2bd2b0..5d531be 100644 --- a/cmd/docs/cmd_sync.go +++ b/cmd/docs/cmd_sync.go @@ -6,10 +6,10 @@ import ( "path/filepath" "strings" - "forge.lthn.ai/core/cli/pkg/cli" "dappco.re/go/core/i18n" "dappco.re/go/core/io" "dappco.re/go/core/scm/repos" + "forge.lthn.ai/core/cli/pkg/cli" ) // Flag variables for sync command @@ -295,9 +295,8 @@ func runZensicalSync(reg *repos.Registry, basePath string, outputDir string, dry weight += 10 } - if info.Readme != "" && folder != "" { - dst := filepath.Join(destDir, "index.md") - if err := copyWithFrontMatter(info.Readme, dst, 1); err != nil { + if info.Readme != "" { + if err := copyZensicalReadme(info.Readme, destDir); err != nil { cli.Print(" %s README: %s\n", errorStyle.Render("✗"), err) } } @@ -326,6 +325,12 @@ func runZensicalSync(reg *repos.Registry, basePath string, outputDir string, dry return nil } +// copyZensicalReadme copies a repository README to index.md in the target directory. +func copyZensicalReadme(src, destDir string) error { + dst := filepath.Join(destDir, "index.md") + return copyWithFrontMatter(src, dst, 1) +} + // goHelpOutputName maps repo name to output folder name for go-help. func goHelpOutputName(repoName string) string { if repoName == "core" { diff --git a/cmd/docs/cmd_sync_test.go b/cmd/docs/cmd_sync_test.go new file mode 100644 index 0000000..518f5dc --- /dev/null +++ b/cmd/docs/cmd_sync_test.go @@ -0,0 +1,39 @@ +package docs + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +func TestCopyZensicalReadme_Good(t *testing.T) { + srcDir := t.TempDir() + destDir := t.TempDir() + + src := filepath.Join(srcDir, "README.md") + if err := os.WriteFile(src, []byte("# Hello\n\nBody text.\n"), 0o644); err != nil { + t.Fatalf("write source README: %v", err) + } + + if err := copyZensicalReadme(src, destDir); err != nil { + t.Fatalf("copy README: %v", err) + } + + output := filepath.Join(destDir, "index.md") + data, err := os.ReadFile(output) + if err != nil { + t.Fatalf("read output index.md: %v", err) + } + + content := string(data) + if !strings.HasPrefix(content, "---\n") { + t.Fatalf("expected Hugo front matter at start, got: %q", content) + } + if !strings.Contains(content, "title: \"README\"") { + t.Fatalf("expected README title in front matter, got: %q", content) + } + if !strings.Contains(content, "Body text.") { + t.Fatalf("expected README body to be preserved, got: %q", content) + } +}