@@ -14,20 +14,30 @@ import (
1414 highlighting "github.com/yuin/goldmark-highlighting/v2"
1515 meta "github.com/yuin/goldmark-meta"
1616 mdParser "github.com/yuin/goldmark/parser"
17- "gopkg.in/yaml.v2 "
17+ "gopkg.in/yaml.v3 "
1818)
1919
2020type article struct {
2121 Title string
2222 Date time.Time
2323 Content []byte
2424 Uri string
25+ Author articleAuthor
26+ }
27+
28+ type articleAuthor struct {
29+ Name string
30+ Email string
2531}
2632
2733type articleMetadata struct {
28- Title string `yaml:"title"`
29- Date ArticleDate `yaml:"date"`
30- Uri string `yaml:"uri"`
34+ Title string `yaml:"title"`
35+ Date ArticleDate `yaml:"date"`
36+ Uri string `yaml:"uri"`
37+ Author struct {
38+ Name string `yaml:"name"`
39+ Email string `yaml:"email,omitempty"`
40+ } `yaml:"author"`
3141}
3242
3343func NewArticle (file fs.File ) (* article , error ) {
@@ -53,11 +63,15 @@ func NewArticle(file fs.File) (*article, error) {
5363 Date : metadata .Date .Time ,
5464 Content : buf .Bytes (),
5565 Uri : uri ,
66+ Author : articleAuthor {
67+ Email : metadata .Author .Email ,
68+ Name : metadata .Author .Name ,
69+ },
5670 }, nil
5771}
5872
5973func getMetadata (context mdParser.Context ) (* articleMetadata , error ) {
60- metadata , err := meta .TryGetItems (context )
74+ metadata , err := meta .TryGet (context )
6175 if err != nil {
6276 return nil , fmt .Errorf ("Could not get article metadata: %s" , err )
6377 }
@@ -67,9 +81,11 @@ func getMetadata(context mdParser.Context) (*articleMetadata, error) {
6781 return nil , fmt .Errorf ("Could not Marshal metadata: %s" , err )
6882 }
6983 var final articleMetadata
70- err = yaml .Unmarshal (out , & final )
84+ if err = yaml .Unmarshal (out , & final ); err != nil {
85+ return nil , fmt .Errorf ("Failed to unmarshal metadata: %s" , err )
86+ }
7187
72- return & final , err
88+ return & final , nil
7389}
7490
7591func fileToMarkdown (file fs.File , buf * bytes.Buffer ) (mdParser.Context , error ) {
0 commit comments