feat: support folder index pages
This commit is contained in:
@@ -104,10 +104,22 @@ func (s *Service) LoadPage(ctx context.Context, requestPath string) (*Page, erro
|
||||
return nil, err
|
||||
}
|
||||
|
||||
normalized := normalizeRequestPath(requestPath)
|
||||
record, err := s.repo.GetDocumentByPath(ctx, normalized)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var (
|
||||
record *DocumentRecord
|
||||
normalized string
|
||||
lastErr error
|
||||
)
|
||||
for _, candidate := range normalizeRequestPathCandidates(requestPath) {
|
||||
found, err := s.repo.GetDocumentByPath(ctx, candidate)
|
||||
if err == nil {
|
||||
record = found
|
||||
normalized = candidate
|
||||
break
|
||||
}
|
||||
lastErr = err
|
||||
}
|
||||
if record == nil {
|
||||
return nil, lastErr
|
||||
}
|
||||
|
||||
content, err := s.store.Read(record.CurrentHash)
|
||||
@@ -129,15 +141,15 @@ func (s *Service) LoadPage(ctx context.Context, requestPath string) (*Page, erro
|
||||
}, nil
|
||||
}
|
||||
|
||||
func normalizeRequestPath(path string) string {
|
||||
func normalizeRequestPathCandidates(path string) []string {
|
||||
path = strings.Trim(path, "/")
|
||||
if path == "" {
|
||||
return "getting-started.md"
|
||||
return []string{"index.md", "getting-started.md"}
|
||||
}
|
||||
if !strings.HasSuffix(path, ".md") {
|
||||
path += ".md"
|
||||
return []string{path + ".md", path + "/index.md"}
|
||||
}
|
||||
return path
|
||||
return []string{path}
|
||||
}
|
||||
|
||||
func (s *Service) syncFile(ctx context.Context, path string) (*DocumentChange, error) {
|
||||
|
||||
Reference in New Issue
Block a user