forked from Gitlink/gitlink-cli
fix: clean _Sidebar.md reference on wiki +delete
CI / test (push) Failing after 1m2s
Details
CI / test (push) Failing after 1m2s
Details
Add safe sidebar cleanup using a separate helper file (sidebar.go) to avoid encoding issues. Only removes the page reference, never adds or modifies other content. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
92a953ba56
commit
6fda83bf38
|
|
@ -0,0 +1,32 @@
|
|||
package wiki
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// removeSidebarRef removes a page reference from _Sidebar.md.
|
||||
// Only modifies the file if the reference is found.
|
||||
func removeSidebarRef(tmpDir, pageName string) error {
|
||||
sbPath := filepath.Join(tmpDir, "_Sidebar.md")
|
||||
data, err := os.ReadFile(sbPath)
|
||||
if err != nil {
|
||||
return nil // no sidebar, nothing to clean up
|
||||
}
|
||||
|
||||
entry := "[[" + pageName + "]]"
|
||||
lines := strings.Split(string(data), "\n")
|
||||
var keep []string
|
||||
for _, line := range lines {
|
||||
if strings.TrimSpace(line) != entry {
|
||||
keep = append(keep, line)
|
||||
}
|
||||
}
|
||||
|
||||
result := strings.Join(keep, "\n")
|
||||
if result == string(data) {
|
||||
return nil // no change needed
|
||||
}
|
||||
return os.WriteFile(sbPath, []byte(result), 0644)
|
||||
}
|
||||
|
|
@ -349,7 +349,7 @@ func runCreate(ctx *common.RuntimeContext) error {
|
|||
msg = fmt.Sprintf("Create wiki page %q", pageName)
|
||||
}
|
||||
|
||||
if _, stderr, err := runGit(tmpDir, "add", fileName); err != nil {
|
||||
if _, stderr, err := runGit(tmpDir, "add", fileName, "_Sidebar.md"); err != nil {
|
||||
return fmt.Errorf("git add: %s%s", stderr, err)
|
||||
}
|
||||
if _, stderr, err := runGit(tmpDir, "commit", "-m", msg); err != nil {
|
||||
|
|
@ -437,7 +437,7 @@ func runUpdate(ctx *common.RuntimeContext) error {
|
|||
msg = fmt.Sprintf("Update wiki page %q", pageName)
|
||||
}
|
||||
|
||||
if _, stderr, err := runGit(tmpDir, "add", fileName); err != nil {
|
||||
if _, stderr, err := runGit(tmpDir, "add", fileName, "_Sidebar.md"); err != nil {
|
||||
return fmt.Errorf("git add: %s%s", stderr, err)
|
||||
}
|
||||
if _, stderr, err := runGit(tmpDir, "commit", "-m", msg); err != nil {
|
||||
|
|
@ -491,13 +491,16 @@ func runDelete(ctx *common.RuntimeContext) error {
|
|||
if err := os.Remove(filePath); err != nil {
|
||||
return fmt.Errorf("delete page: %w", err)
|
||||
}
|
||||
// Clean up sidebar reference
|
||||
removeSidebarRef(tmpDir, pageName)
|
||||
|
||||
|
||||
msg := ctx.Arg("message")
|
||||
if msg == "" {
|
||||
msg = fmt.Sprintf("Delete wiki page %q", pageName)
|
||||
}
|
||||
|
||||
if _, stderr, err := runGit(tmpDir, "add", fileName); err != nil {
|
||||
if _, stderr, err := runGit(tmpDir, "add", fileName, "_Sidebar.md"); err != nil {
|
||||
return fmt.Errorf("git add: %s%s", stderr, err)
|
||||
}
|
||||
if _, stderr, err := runGit(tmpDir, "commit", "-m", msg); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue