Skip to content

Commit 5843095

Browse files
Fix rendering all markdown by default. (#190)
* Fix rendering all markdown by default. * Fix formatting. * Apply Copilot recommendations.
1 parent 6123581 commit 5843095

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

internal/server/handlers.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"path"
1111
"path/filepath"
12+
"slices"
1213
"sort"
1314
"strings"
1415
"unicode/utf8"
@@ -83,7 +84,21 @@ func (s *Server) showOrRender(w http.ResponseWriter, r *http.Request) {
8384
// If the path is not a directory, then it's a file, so we can render it,
8485
// let's check first if it's a markdown file
8586
if ext := strings.ToLower(filepath.Ext(currentPath)); ext == ".md" || ext == ".markdown" {
86-
s.serveMarkdown(currentPath, w, r)
87+
// Check FullMarkdownRender first to avoid unnecessary filename extraction
88+
if s.FullMarkdownRender {
89+
s.serveMarkdown(currentPath, w, r)
90+
return
91+
}
92+
93+
// Not rendering all markdown, check if this is an index-like file
94+
filename := filepath.Base(currentPath)
95+
if slices.Contains(allowedIndexFiles, filename) {
96+
s.serveMarkdown(currentPath, w, r)
97+
return
98+
}
99+
100+
// If not an index file and FullMarkdownRender is disabled, serve as plain text
101+
s.serveFile(0, currentPath, w, r)
87102
return
88103
}
89104

0 commit comments

Comments
 (0)