2d0a636095f2e62758778f887919f6f11ab5ebf5

Author
Souma <101255979+5ouma@users.noreply.github.com>
Committer
Kieran Klukas <kieran@dunkirk.sh>
Date

Message

feat(backend): Support README files in the second-depth directories

Many other Git platforms support them as well.

Diff

 1diff --git a/pkg/backend/utils.go b/pkg/backend/utils.go
 2index be1b0b4a78cfd21265ebb809920a8d5a780f6825..63dc0be5542e8d98b262f241371c50e2630eae6e 100644
 3--- a/pkg/backend/utils.go
 4+++ b/pkg/backend/utils.go
 5@@ -1,6 +1,8 @@
 6 package backend
 7 
 8 import (
 9+	"path/filepath"
10+
11 	"github.com/charmbracelet/soft-serve/git"
12 	"github.com/charmbracelet/soft-serve/pkg/proto"
13 )
14@@ -16,8 +18,13 @@ func LatestFile(r proto.Repository, ref *git.Reference, pattern string) (string,
15 }
16 
17 // Readme returns the repository's README.
18+// It searches in priority order: root, .github, docs.
19 func Readme(r proto.Repository, ref *git.Reference) (readme string, path string, err error) {
20-	pattern := "[rR][eE][aA][dD][mM][eE]*"
21-	readme, path, err = LatestFile(r, ref, pattern)
22+	for _, dir := range []string{".", ".github", "docs"} {
23+		readme, path, err = LatestFile(r, ref, filepath.Join(dir, "[rR][eE][aA][dD][mM][eE]*"))
24+		if err == nil {
25+			return
26+		}
27+	}
28 	return
29 }