updates
This commit is contained in:
@@ -37,7 +37,7 @@ func (i *Info) Update(w http.ResponseWriter, r *http.Request, c *config.Config)
|
||||
|
||||
switch kind {
|
||||
case "frontmatter-only":
|
||||
if file, code, err = parseFrontMatterOnlyFile(data, i.Name); err != nil {
|
||||
if file, code, err = ParseFrontMatterOnlyFile(data, i.Name); err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
case "content-only":
|
||||
@@ -45,7 +45,7 @@ func (i *Info) Update(w http.ResponseWriter, r *http.Request, c *config.Config)
|
||||
mainContent = strings.TrimSpace(mainContent)
|
||||
file = []byte(mainContent)
|
||||
case "complete":
|
||||
if file, code, err = parseCompleteFile(data, i.Name, c.FrontMatter); err != nil {
|
||||
if file, code, err = ParseCompleteFile(data, i.Name, c.FrontMatter); err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
default:
|
||||
@@ -62,9 +62,10 @@ func (i *Info) Update(w http.ResponseWriter, r *http.Request, c *config.Config)
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func parseFrontMatterOnlyFile(data interface{}, filename string) ([]byte, int, error) {
|
||||
// ParseFrontMatterOnlyFile parses a frontmatter only file
|
||||
func ParseFrontMatterOnlyFile(data interface{}, filename string) ([]byte, int, error) {
|
||||
frontmatter := strings.TrimPrefix(filepath.Ext(filename), ".")
|
||||
f, code, err := parseFrontMatter(data, frontmatter)
|
||||
f, code, err := ParseFrontMatter(data, frontmatter)
|
||||
fString := string(f)
|
||||
|
||||
// If it's toml or yaml, strip frontmatter identifier
|
||||
@@ -82,7 +83,8 @@ func parseFrontMatterOnlyFile(data interface{}, filename string) ([]byte, int, e
|
||||
return f, code, err
|
||||
}
|
||||
|
||||
func parseFrontMatter(data interface{}, frontmatter string) ([]byte, int, error) {
|
||||
// ParseFrontMatter is the frontmatter parser
|
||||
func ParseFrontMatter(data interface{}, frontmatter string) ([]byte, int, error) {
|
||||
var mark rune
|
||||
|
||||
switch frontmatter {
|
||||
@@ -105,7 +107,8 @@ func parseFrontMatter(data interface{}, frontmatter string) ([]byte, int, error)
|
||||
return f, http.StatusOK, nil
|
||||
}
|
||||
|
||||
func parseCompleteFile(data map[string]interface{}, filename string, frontmatter string) ([]byte, int, error) {
|
||||
// ParseCompleteFile parses a complete file
|
||||
func ParseCompleteFile(data map[string]interface{}, filename string, frontmatter string) ([]byte, int, error) {
|
||||
mainContent := ""
|
||||
|
||||
if _, ok := data["content"]; ok {
|
||||
@@ -121,7 +124,7 @@ func parseCompleteFile(data map[string]interface{}, filename string, frontmatter
|
||||
data["date"] = data["date"].(string) + ":00"
|
||||
}
|
||||
|
||||
front, code, err := parseFrontMatter(data, frontmatter)
|
||||
front, code, err := ParseFrontMatter(data, frontmatter)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(frontmatter)
|
||||
|
||||
Reference in New Issue
Block a user