fix(docs): sync zensical readmes to index
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
b5d32ade33
commit
29cbec8575
2 changed files with 48 additions and 4 deletions
|
|
@ -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" {
|
||||
|
|
|
|||
39
cmd/docs/cmd_sync_test.go
Normal file
39
cmd/docs/cmd_sync_test.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue