Skip to content

Commit

Permalink
improve reference parsing in jsonfeed reader
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed May 14, 2024
1 parent bd47ea5 commit 851d6bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var versionCmd = &cobra.Command{
Short: "Print the version number of commonmeta",
Long: `All software has versions. This is commonmeta's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Commonmeta v0.3.7 -- HEAD")
fmt.Println("Commonmeta v0.3.8 -- HEAD")
},
}

Expand Down
27 changes: 14 additions & 13 deletions jsonfeed/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ type Relation struct {
// Reference represents a reference in the JSON Feed item.
type Reference struct {
Key string `json:"key"`
DOI string `json:"doi"`
URL string `json:"url"`
ID string `json:"id"`
PublicationYear string `json:"publicationYear"`
Title string `json:"title"`
}
Expand Down Expand Up @@ -324,17 +323,19 @@ func Read(content Content) (commonmeta.Data, error) {
}

for _, v := range content.Reference {
reference := commonmeta.Reference{
Key: v.Key,
ID: doiutils.NormalizeDOI(v.DOI),
Title: v.Title,
PublicationYear: v.PublicationYear,
}
containsKey := slices.ContainsFunc(data.References, func(e commonmeta.Reference) bool {
return e.Key != "" && e.Key == reference.Key
})
if !containsKey {
data.References = append(data.References, reference)
if v.ID != "" {
reference := commonmeta.Reference{
Key: v.Key,
ID: v.ID,
Title: v.Title,
PublicationYear: v.PublicationYear,
}
containsKey := slices.ContainsFunc(data.References, func(e commonmeta.Reference) bool {
return e.Key != "" && e.Key == reference.Key
})
if !containsKey {
data.References = append(data.References, reference)
}
}
}

Expand Down

0 comments on commit 851d6bc

Please sign in to comment.