7
7
8
8
// Caltech Library package
9
9
"github.com/caltechlibrary/doitools"
10
+
11
+ // 3rd Party Package
12
+ "github.com/hscells/doi"
10
13
)
11
14
12
15
type PersonOrOrganization struct {
@@ -53,6 +56,7 @@ type Codemeta struct {
53
56
// Additional codemeta Terms are defined at https://codemeta.github.io/terms/
54
57
}
55
58
59
+
56
60
func (person * PersonOrOrganization ) ToJSON () ([]byte , error ) {
57
61
return JSONMarshalIndent (person , "" , "\t " )
58
62
}
@@ -71,6 +75,15 @@ func (person *PersonOrOrganization) ToCFF() ([]byte, error) {
71
75
orcid: %s` , person .FamilyName , person .GivenName , person .Id )), nil
72
76
}
73
77
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
+
74
87
// ToCff crosswalks a Codemeta data structure rendering
75
88
// CITATION.cff document as an array of byte.
76
89
// Based on documentation at https://citation-file-format.github.io/
@@ -96,7 +109,7 @@ repository-code: %q`, cm.CodeRepository))...)
96
109
src = append (src , []byte (`
97
110
type: software` )... )
98
111
}
99
- if strings . HasPrefix (cm .Identifier , "https://doi.org/" ) {
112
+ if isDOI (cm .Identifier ) {
100
113
if doi , err := doitools .NormalizeDOI (cm .Identifier ); err == nil {
101
114
src = append (src , []byte (fmt .Sprintf (`
102
115
doi: %s` , doi ))... )
0 commit comments