implement metadata writing
Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
parent
10b9c8aa64
commit
d8417c16fc
74
gempub.go
74
gempub.go
|
@ -22,10 +22,82 @@ type Metadata struct {
|
|||
PublishDate time.Time // YYYY-MM-DD eg. 2006-01-02
|
||||
RevisionDate time.Time // YYYY-MM-DD eg. 2006-01-02
|
||||
Copyright string // copyright of the book
|
||||
License string // license of the book Version string a // human readable only, not meant to be parsed
|
||||
License string // license of the book
|
||||
Version string // human readable only, not meant to be parsed
|
||||
Cover string // a JPG or PNG image which can be anywhere in the directory structure
|
||||
}
|
||||
|
||||
func (m Metadata) Write(w io.Writer) error {
|
||||
if err := m.Valid(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprintln(w, "title: ", m.Title); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprintln(w, "gpubVersion: ", m.GpubVersion); err != nil {
|
||||
return err
|
||||
}
|
||||
if m.Index != "" {
|
||||
if _, err := fmt.Fprintln(w, "index: ", m.Index); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if m.Author != "" {
|
||||
if _, err := fmt.Fprintln(w, "author: ", m.Author); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if m.Language != "" {
|
||||
if _, err := fmt.Fprintln(w, "language: ", m.Language); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if m.Charset != "" {
|
||||
if _, err := fmt.Fprintln(w, "charset: ", m.Charset); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if m.Description != "" {
|
||||
if _, err := fmt.Fprintln(w, "description: ", m.Description); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if m.Copyright != "" {
|
||||
if _, err := fmt.Fprintln(w, "copyright: ", m.Copyright); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if m.Version != "" {
|
||||
if _, err := fmt.Fprintln(w, "version: ", m.Version); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if m.Cover != "" {
|
||||
if _, err := fmt.Fprintln(w, "cover: ", m.Cover); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !m.Published.IsZero() {
|
||||
if _, err := fmt.Fprintln(w, "published: ", m.Published.Format("2006-01-02")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !m.PublishDate.IsZero() {
|
||||
if _, err := fmt.Fprintln(w, "publishDate: ", m.PublishDate.Format("2006-01-02")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !m.RevisionDate.IsZero() {
|
||||
if _, err := fmt.Fprintln(w, "revisionDate: ", m.RevisionDate.Format("2006-01-02")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
ErrNoTitle = errors.New("gempub: no title in document")
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue