Compare commits

..

No commits in common. "main" and "v0.0.8" have entirely different histories.
main ... v0.0.8

View file

@ -162,43 +162,33 @@ func (c *Client) Open(name, ref string) (fs.File, error) {
return c.serveNotFound(owner, repo), nil return c.serveNotFound(owner, repo), nil
} }
res, err := c.getRawFileOrLFS(owner, repo, filepath, ref)
if err == nil {
if strings.HasSuffix(filepath, ".md") {
res, err = handleMD(res)
if err != nil {
return nil, err
}
}
return &openFile{
content: res,
name: filepath,
}, nil
}
// If file not found, try as directory
entries, err := c.getDirectoryContents(owner, repo, filepath, ref) entries, err := c.getDirectoryContents(owner, repo, filepath, ref)
if err == nil { if err == nil {
// Check if this is a directory and the request doesn't end with /
// If so, look for index.html in this directory
if !strings.HasSuffix(filepath, "/") {
indexContent, err := c.getRawFileOrLFS(owner, repo, filepath+"/index.html", ref)
if err == nil {
return &openFile{
content: indexContent,
name: "index.html",
}, nil
}
}
return &openDir{ return &openDir{
entries: entries, entries: entries,
name: filepath, name: filepath,
}, nil }, nil
} }
// Neither file nor directory found res, err := c.getRawFileOrLFS(owner, repo, filepath, ref)
return c.serveNotFound(owner, repo), nil if err != nil {
if err == fs.ErrNotExist {
return c.serveNotFound(owner, repo), nil
}
return nil, err
}
if strings.HasSuffix(filepath, ".md") {
res, err = handleMD(res)
if err != nil {
return nil, err
}
}
return &openFile{
content: res,
name: filepath,
}, nil
} }
func (c *Client) getRawFileOrLFS(owner, repo, filepath, ref string) ([]byte, error) { func (c *Client) getRawFileOrLFS(owner, repo, filepath, ref string) ([]byte, error) {