77
88 // Caltech Library package
99 "github.com/caltechlibrary/doitools"
10+
11+ // 3rd Party Package
12+ "github.com/hscells/doi"
1013)
1114
1215type PersonOrOrganization struct {
@@ -53,6 +56,7 @@ type Codemeta struct {
5356 // Additional codemeta Terms are defined at https://codemeta.github.io/terms/
5457}
5558
59+
5660func (person * PersonOrOrganization ) ToJSON () ([]byte , error ) {
5761 return JSONMarshalIndent (person , "" , "\t " )
5862}
@@ -71,6 +75,15 @@ func (person *PersonOrOrganization) ToCFF() ([]byte, error) {
7175 orcid: %s` , person .FamilyName , person .GivenName , person .Id )), nil
7276}
7377
78+ // Check if identifier is a DOI
79+ func isDOI (identifier string ) bool {
80+ doi , err := doi .Parse (identifier )
81+ if err != nil {
82+ return false
83+ }
84+ return doi .IsValid ()
85+ }
86+
7487// ToCff crosswalks a Codemeta data structure rendering
7588// CITATION.cff document as an array of byte.
7689// Based on documentation at https://citation-file-format.github.io/
@@ -96,7 +109,7 @@ repository-code: %q`, cm.CodeRepository))...)
96109 src = append (src , []byte (`
97110type: software` )... )
98111 }
99- if strings . HasPrefix (cm .Identifier , "https://doi.org/" ) {
112+ if isDOI (cm .Identifier ) {
100113 if doi , err := doitools .NormalizeDOI (cm .Identifier ); err == nil {
101114 src = append (src , []byte (fmt .Sprintf (`
102115doi: %s` , doi ))... )
0 commit comments