fix some things

This commit is contained in:
Henrique Dias 2016-06-25 22:05:45 +01:00
parent 669cb2c4ae
commit 4a19c6d5e3
2 changed files with 8 additions and 9 deletions

View File

@ -1,11 +1,11 @@
package editor
package file
import (
"bytes"
"path/filepath"
"strings"
"github.com/hacdias/caddy-filemanager/internal/file"
"github.com/hacdias/caddy-hugo/tools/frontmatter"
"github.com/spf13/hugo/parser"
)
@ -18,7 +18,7 @@ type Editor 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
editor := new(Editor)
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
editor.Content = strings.TrimSpace(string(page.Content()))
editor.FrontMatter, _, err = Pretty(page.FrontMatter())
editor.FrontMatter, _, err = frontmatter.Pretty(page.FrontMatter())
editor.Class = "complete"
} else {
// The editor will handle only content
editor.Class = "content-only"
editor.Content = fi.Content
editor.Content = i.Content
}
case "json", "toml", "yaml":
// 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
if editor.hasFrontMatterRune(i.Raw) {
editor.FrontMatter, _, err = Pretty(i.Raw)
editor.FrontMatter, _, err = frontmatter.Pretty(i.Raw)
} 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

View File

@ -13,7 +13,6 @@ import (
"github.com/dustin/go-humanize"
"github.com/hacdias/caddy-filemanager/internal/config"
"github.com/hacdias/caddy-filemanager/internal/editor"
p "github.com/hacdias/caddy-filemanager/internal/page"
"github.com/hacdias/caddy-filemanager/utils/errors"
"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()
if err != nil {