Skip to content

Commit

Permalink
commands: Add some band-aid to convert
Browse files Browse the repository at this point in the history
  • Loading branch information
bep authored and tychoish committed Aug 13, 2017
1 parent d0224fb commit 7c8b207
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion commands/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ func convertContents(mark rune) (err error) {
page.SetDir(filepath.Join(helpers.AbsPathify(viper.GetString("ContentDir")), file.Dir()))
page.SetSourceContent(psr.Content())
if err = page.SetSourceMetaData(metadata, mark); err != nil {
return fmt.Errorf("Failed to set source metadata for file %q: %s", page.FullFilePath(), err)
jww.ERROR.Printf("Failed to set source metadata for file %q: %s. For more info see For more info see https://github.com/spf13/hugo/issues/2458", page.FullFilePath(), err)
continue
}

if outputDir != "" {
Expand Down
19 changes: 16 additions & 3 deletions hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,15 +1020,28 @@ func (p *Page) SetSourceContent(content []byte) {
}

func (p *Page) SetSourceMetaData(in interface{}, mark rune) (err error) {
by, err := parser.InterfaceToFrontMatter(in, mark)
// See https://github.com/spf13/hugo/issues/2458
defer func() {
if r := recover(); r != nil {
var ok bool
err, ok = r.(error)
if !ok {
err = fmt.Errorf("error from marshal: %v", r)
}
}
}()

var by []byte

by, err = parser.InterfaceToFrontMatter(in, mark)
if err != nil {
return err
return
}
by = append(by, '\n')

p.Source.Frontmatter = by

return nil
return
}

func (p *Page) SafeSaveSourceAs(path string) error {
Expand Down

0 comments on commit 7c8b207

Please sign in to comment.