Skip to content

Commit

Permalink
Added date formatter, pages, and fixed metadata search for new entry …
Browse files Browse the repository at this point in the history
…without a file
  • Loading branch information
cgxeiji committed Dec 19, 2018
1 parent 6a6faf4 commit 8bbc22f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
18 changes: 11 additions & 7 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ TODO: Add a flag for manual/auto input of metadata
if askYesNo("Would you like to search the web for metadata?") {
doi = query(requestSearch())
}
fmt.Println()
fmt.Println("Adding the entry manually...")
fmt.Println("What kind of entry is it?")
t := selectType()
fmt.Println()
fmt.Println("Please, add the required fields:")
entry = add(t)
if doi != "" {
entry = addDOI(doi)
} else {
fmt.Println()
fmt.Println("Adding the entry manually...")
fmt.Println("What kind of entry is it?")
t := selectType()
fmt.Println()
fmt.Println("Please, add the required fields:")
entry = add(t)
}
}
commit(entry)
edit(entry)
Expand Down
22 changes: 21 additions & 1 deletion cmd/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -263,7 +264,7 @@ func parseCrossref(work *crossref.Work) *scholar.Entry {
}
e.Required["author"] = strings.TrimSuffix(e.Required["author"], " and ")

e.Required["date"] = work.Date
e.Required["date"] = formatDate(work.Date)
e.Required["title"] = work.Title

for _, a := range work.Editors {
Expand All @@ -272,8 +273,27 @@ func parseCrossref(work *crossref.Work) *scholar.Entry {
e.Optional["editor"] = strings.TrimSuffix(e.Optional["editor"], " and ")

e.Optional["volume"] = work.Volume
e.Optional["pages"] = work.Pages
e.Optional["number"] = work.Issue
e.Optional["doi"] = work.DOI

return e
}

func formatDate(date string) string {
parts := strings.Split(date, "-")
for i := range parts {
fixed := ""
p, err := strconv.Atoi(parts[i])
if err != nil {
panic(err)
}
if p < 10 {
fixed += "0"
}
fixed += strconv.Itoa(p)
parts[i] = fixed
}

return strings.Join(parts, "-")
}

0 comments on commit 8bbc22f

Please sign in to comment.