commands: Add some band-aid to convert

Fixes #2458
This commit is contained in:
Bjørn Erik Pedersen 2016-09-19 10:52:07 +02:00
parent 2105e42aca
commit 9c017e512e
2 changed files with 18 additions and 4 deletions

View file

@ -137,7 +137,8 @@ func convertContents(mark rune) (err error) {
page.SetDir(filepath.Join(helpers.AbsPathify(viper.GetString("ContentDir")), file.Dir())) page.SetDir(filepath.Join(helpers.AbsPathify(viper.GetString("ContentDir")), file.Dir()))
page.SetSourceContent(psr.Content()) page.SetSourceContent(psr.Content())
if err = page.SetSourceMetaData(metadata, mark); err != nil { 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 != "" { if outputDir != "" {

View file

@ -1020,15 +1020,28 @@ func (p *Page) SetSourceContent(content []byte) {
} }
func (p *Page) SetSourceMetaData(in interface{}, mark rune) (err error) { 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 { if err != nil {
return err return
} }
by = append(by, '\n') by = append(by, '\n')
p.Source.Frontmatter = by p.Source.Frontmatter = by
return nil return
} }
func (p *Page) SafeSaveSourceAs(path string) error { func (p *Page) SafeSaveSourceAs(path string) error {