remove unnecessary variables

pull/78/head
Henrique Dias 2016-06-16 16:52:37 +01:00
parent 8acb8352e6
commit 48878cc3b5
2 changed files with 9 additions and 11 deletions

View File

@ -62,24 +62,26 @@ func GET(w http.ResponseWriter, r *http.Request) (int, error) {
// Sanitize the extension
page.Mode = sanitizeMode(page.Mode)
var ppage parser.Page
// Handle the content depending on the file extension
switch page.Mode {
case "markdown", "asciidoc", "rst":
if hasFrontMatterRune(file) {
// Starts a new buffer and parses the file using Hugo's functions
buffer := bytes.NewBuffer(file)
file, err := parser.ReadFrom(buffer)
ppage, err = parser.ReadFrom(buffer)
if err != nil {
return http.StatusInternalServerError, err
}
if strings.Contains(string(file.FrontMatter()), "date") {
if strings.Contains(string(ppage.FrontMatter()), "date") {
page.IsPost = true
}
// Parses the page content and the frontmatter
page.Content = strings.TrimSpace(string(file.Content()))
page.FrontMatter, page.Name, err = frontmatter.Pretty(file.FrontMatter())
page.Content = strings.TrimSpace(string(ppage.Content()))
page.FrontMatter, page.Name, err = frontmatter.Pretty(ppage.FrontMatter())
page.Class = "complete"
} else {
// The editor will handle only content
@ -89,7 +91,6 @@ func GET(w http.ResponseWriter, r *http.Request) (int, error) {
case "json", "toml", "yaml":
// Defines the class and declares an error
page.Class = "frontmatter-only"
var err error
// Checks if the file already has the frontmatter rune and parses it
if hasFrontMatterRune(file) {

View File

@ -46,15 +46,14 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
// Initializes the file content to write
var file []byte
var code int
switch data.ContentType {
case "frontmatter-only":
f, code, err := parseFrontMatterOnlyFile(data)
file, code, err = parseFrontMatterOnlyFile(data)
if err != nil {
return server.RespondJSON(w, &response{err.Error()}, code, err)
}
file = f
case "content-only":
// The main content of the file
mainContent := data.Content["content"].(string)
@ -62,12 +61,10 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
file = []byte(mainContent)
case "complete":
f, code, err := parseCompleteFile(data)
file, code, err = parseCompleteFile(data)
if err != nil {
return server.RespondJSON(w, &response{err.Error()}, code, err)
}
file = f
default:
return server.RespondJSON(w, &response{"Invalid content type."}, http.StatusBadRequest, nil)
}