charmbracelet / soft-serve

The mighty, self-hostable Git server for the command line🍦
MIT License
5.2k stars 132 forks source link

Readme files are always rendered in Markdown format #463

Closed LindsayZhou closed 7 months ago

LindsayZhou commented 7 months ago

Describe the bug Regardless the actual format, readme files are always rendered in Markdown format.
Included in the service's About tab and the repository's readme page

To Reproduce Create a repository and commit a readme file.

Expected behavior For non-Markdown readme files, represent them as normal files.

I personally like to use orgmode files as readme files.
If the service cannot parse the orgmode file, then I export it as a plain text file (emacs built-in feature).

Screenshots Current: 2024-01-19_16:21:15 What I want: 2024-01-19_16:23:04

Environment (please complete the following information):

Additional context Here is my rough patch:

diff --git a/pkg/ui/pages/repo/readme.go b/pkg/ui/pages/repo/readme.go
index e977bb9..1b12560 100644
--- a/pkg/ui/pages/repo/readme.go
+++ b/pkg/ui/pages/repo/readme.go
@@ -3,6 +3,7 @@ package repo
 import (
    "fmt"
    "path/filepath"
+   "strings"

    "github.com/charmbracelet/bubbles/key"
    "github.com/charmbracelet/bubbles/spinner"
@@ -34,7 +35,6 @@ type Readme struct {
 func NewReadme(common common.Common) *Readme {
    readme := code.New(common, "", "")
    readme.NoContentStyle = readme.NoContentStyle.Copy().SetString("No readme found.")
-   readme.UseGlamour = true
    s := spinner.New(spinner.WithSpinner(spinner.Dot),
        spinner.WithStyle(common.Styles.Spinner))
    return &Readme{
@@ -114,6 +114,13 @@ func (r *Readme) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
    case ReadmeMsg:
        r.isLoading = false
        r.readmePath = msg.Path
+       readmeExt := strings.ToLower(filepath.Ext(msg.Path))
+       r.code.UseGlamour = (readmeExt == ".md" ||
+           readmeExt == ".markdown" ||
+           readmeExt == ".mdown" ||
+           readmeExt == "mkdn" ||
+           readmeExt == "mdwn" ||
+           readmeExt == "mkd")
        r.code.GotoTop()
        cmds = append(cmds, r.code.SetContent(msg.Content, msg.Path))
    case spinner.TickMsg:
diff --git a/pkg/ui/pages/selection/selection.go b/pkg/ui/pages/selection/selection.go
index 4b9b72a..9f0d884 100644
--- a/pkg/ui/pages/selection/selection.go
+++ b/pkg/ui/pages/selection/selection.go
@@ -2,7 +2,9 @@ package selection

 import (
    "fmt"
+   "path/filepath"
    "sort"
+   "strings"

    "github.com/charmbracelet/bubbles/key"
    "github.com/charmbracelet/bubbles/list"
@@ -62,7 +64,6 @@ func New(c common.Common) *Selection {
        tabs:       t,
    }
    readme := code.New(c, "", "")
-   readme.UseGlamour = true
    readme.NoContentStyle = c.Styles.NoContent.Copy().
        SetString(defaultNoContent)
    selector := selector.New(c,
@@ -206,6 +207,13 @@ func (s *Selection) Init() tea.Cmd {
            if err != nil {
                continue
            }
+           readmeExt := strings.ToLower(filepath.Ext(path))
+           s.readme.UseGlamour = (readmeExt == ".md" ||
+               readmeExt == ".markdown" ||
+               readmeExt == ".mdown" ||
+               readmeExt == "mkdn" ||
+               readmeExt == "mdwn" ||
+               readmeExt == "mkd")

            readmeCmd = s.readme.SetContent(readme, path)
        }