mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
fix some things
This commit is contained in:
parent
669cb2c4ae
commit
4a19c6d5e3
@ -1,11 +1,11 @@
|
|||||||
package editor
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-filemanager/internal/file"
|
"github.com/hacdias/caddy-hugo/tools/frontmatter"
|
||||||
"github.com/spf13/hugo/parser"
|
"github.com/spf13/hugo/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ type Editor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEditor gets the editor based on a FileInfo struct
|
// GetEditor gets the editor based on a FileInfo struct
|
||||||
func (i *file.Info) GetEditor() (*Editor, error) {
|
func (i *Info) GetEditor() (*Editor, error) {
|
||||||
// Create a new editor variable and set the mode
|
// Create a new editor variable and set the mode
|
||||||
editor := new(Editor)
|
editor := new(Editor)
|
||||||
editor.Mode = strings.TrimPrefix(filepath.Ext(i.Name), ".")
|
editor.Mode = strings.TrimPrefix(filepath.Ext(i.Name), ".")
|
||||||
@ -52,12 +52,12 @@ func (i *file.Info) GetEditor() (*Editor, error) {
|
|||||||
|
|
||||||
// Parses the page content and the frontmatter
|
// Parses the page content and the frontmatter
|
||||||
editor.Content = strings.TrimSpace(string(page.Content()))
|
editor.Content = strings.TrimSpace(string(page.Content()))
|
||||||
editor.FrontMatter, _, err = Pretty(page.FrontMatter())
|
editor.FrontMatter, _, err = frontmatter.Pretty(page.FrontMatter())
|
||||||
editor.Class = "complete"
|
editor.Class = "complete"
|
||||||
} else {
|
} else {
|
||||||
// The editor will handle only content
|
// The editor will handle only content
|
||||||
editor.Class = "content-only"
|
editor.Class = "content-only"
|
||||||
editor.Content = fi.Content
|
editor.Content = i.Content
|
||||||
}
|
}
|
||||||
case "json", "toml", "yaml":
|
case "json", "toml", "yaml":
|
||||||
// Defines the class and declares an error
|
// Defines the class and declares an error
|
||||||
@ -65,9 +65,9 @@ func (i *file.Info) GetEditor() (*Editor, error) {
|
|||||||
|
|
||||||
// Checks if the file already has the frontmatter rune and parses it
|
// Checks if the file already has the frontmatter rune and parses it
|
||||||
if editor.hasFrontMatterRune(i.Raw) {
|
if editor.hasFrontMatterRune(i.Raw) {
|
||||||
editor.FrontMatter, _, err = Pretty(i.Raw)
|
editor.FrontMatter, _, err = frontmatter.Pretty(i.Raw)
|
||||||
} else {
|
} else {
|
||||||
editor.FrontMatter, _, err = Pretty(editor.appendFrontMatterRune(i.Raw, editor.Mode))
|
editor.FrontMatter, _, err = frontmatter.Pretty(editor.appendFrontMatterRune(i.Raw, editor.Mode))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there were any errors
|
// Check if there were any errors
|
@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/hacdias/caddy-filemanager/internal/config"
|
"github.com/hacdias/caddy-filemanager/internal/config"
|
||||||
"github.com/hacdias/caddy-filemanager/internal/editor"
|
|
||||||
p "github.com/hacdias/caddy-filemanager/internal/page"
|
p "github.com/hacdias/caddy-filemanager/internal/page"
|
||||||
"github.com/hacdias/caddy-filemanager/utils/errors"
|
"github.com/hacdias/caddy-filemanager/utils/errors"
|
||||||
"github.com/mholt/caddy/caddyhttp/httpserver"
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
||||||
@ -170,7 +169,7 @@ func (i *Info) serveSingleFile(w http.ResponseWriter, r *http.Request, c *config
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if editor.CanBeEdited(i.Name) {
|
if CanBeEdited(i.Name) {
|
||||||
editor, err := i.GetEditor()
|
editor, err := i.GetEditor()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user