remove unnecessary variables
This commit is contained in:
		
							parent
							
								
									8acb8352e6
								
							
						
					
					
						commit
						48878cc3b5
					
				|  | @ -62,24 +62,26 @@ func GET(w http.ResponseWriter, r *http.Request) (int, error) { | ||||||
| 	// Sanitize the extension
 | 	// Sanitize the extension
 | ||||||
| 	page.Mode = sanitizeMode(page.Mode) | 	page.Mode = sanitizeMode(page.Mode) | ||||||
| 
 | 
 | ||||||
|  | 	var ppage parser.Page | ||||||
|  | 
 | ||||||
| 	// Handle the content depending on the file extension
 | 	// Handle the content depending on the file extension
 | ||||||
| 	switch page.Mode { | 	switch page.Mode { | ||||||
| 	case "markdown", "asciidoc", "rst": | 	case "markdown", "asciidoc", "rst": | ||||||
| 		if hasFrontMatterRune(file) { | 		if hasFrontMatterRune(file) { | ||||||
| 			// Starts a new buffer and parses the file using Hugo's functions
 | 			// Starts a new buffer and parses the file using Hugo's functions
 | ||||||
| 			buffer := bytes.NewBuffer(file) | 			buffer := bytes.NewBuffer(file) | ||||||
| 			file, err := parser.ReadFrom(buffer) | 			ppage, err = parser.ReadFrom(buffer) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return http.StatusInternalServerError, err | 				return http.StatusInternalServerError, err | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			if strings.Contains(string(file.FrontMatter()), "date") { | 			if strings.Contains(string(ppage.FrontMatter()), "date") { | ||||||
| 				page.IsPost = true | 				page.IsPost = true | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			// Parses the page content and the frontmatter
 | 			// Parses the page content and the frontmatter
 | ||||||
| 			page.Content = strings.TrimSpace(string(file.Content())) | 			page.Content = strings.TrimSpace(string(ppage.Content())) | ||||||
| 			page.FrontMatter, page.Name, err = frontmatter.Pretty(file.FrontMatter()) | 			page.FrontMatter, page.Name, err = frontmatter.Pretty(ppage.FrontMatter()) | ||||||
| 			page.Class = "complete" | 			page.Class = "complete" | ||||||
| 		} else { | 		} else { | ||||||
| 			// The editor will handle only content
 | 			// The editor will handle only content
 | ||||||
|  | @ -89,7 +91,6 @@ func GET(w http.ResponseWriter, r *http.Request) (int, error) { | ||||||
| 	case "json", "toml", "yaml": | 	case "json", "toml", "yaml": | ||||||
| 		// Defines the class and declares an error
 | 		// Defines the class and declares an error
 | ||||||
| 		page.Class = "frontmatter-only" | 		page.Class = "frontmatter-only" | ||||||
| 		var err 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 hasFrontMatterRune(file) { | 		if hasFrontMatterRune(file) { | ||||||
|  |  | ||||||
|  | @ -46,15 +46,14 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) { | ||||||
| 
 | 
 | ||||||
| 	// Initializes the file content to write
 | 	// Initializes the file content to write
 | ||||||
| 	var file []byte | 	var file []byte | ||||||
|  | 	var code int | ||||||
| 
 | 
 | ||||||
| 	switch data.ContentType { | 	switch data.ContentType { | ||||||
| 	case "frontmatter-only": | 	case "frontmatter-only": | ||||||
| 		f, code, err := parseFrontMatterOnlyFile(data) | 		file, code, err = parseFrontMatterOnlyFile(data) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return server.RespondJSON(w, &response{err.Error()}, code, err) | 			return server.RespondJSON(w, &response{err.Error()}, code, err) | ||||||
| 		} | 		} | ||||||
| 
 |  | ||||||
| 		file = f |  | ||||||
| 	case "content-only": | 	case "content-only": | ||||||
| 		// The main content of the file
 | 		// The main content of the file
 | ||||||
| 		mainContent := data.Content["content"].(string) | 		mainContent := data.Content["content"].(string) | ||||||
|  | @ -62,12 +61,10 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) { | ||||||
| 
 | 
 | ||||||
| 		file = []byte(mainContent) | 		file = []byte(mainContent) | ||||||
| 	case "complete": | 	case "complete": | ||||||
| 		f, code, err := parseCompleteFile(data) | 		file, code, err = parseCompleteFile(data) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return server.RespondJSON(w, &response{err.Error()}, code, err) | 			return server.RespondJSON(w, &response{err.Error()}, code, err) | ||||||
| 		} | 		} | ||||||
| 
 |  | ||||||
| 		file = f |  | ||||||
| 	default: | 	default: | ||||||
| 		return server.RespondJSON(w, &response{"Invalid content type."}, http.StatusBadRequest, nil) | 		return server.RespondJSON(w, &response{"Invalid content type."}, http.StatusBadRequest, nil) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue