diff options
-rw-r--r-- | skate/schema.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/skate/schema.go b/skate/schema.go index c0be5ef..8554e14 100644 --- a/skate/schema.go +++ b/skate/schema.go @@ -648,6 +648,7 @@ func OpenLibraryEditionToRelease(v *OpenLibraryEdition, authorMap map[string]str release.Publisher = v.Publishers[0] } if len(v.Works) > 0 { + // TODO: We should be ok with just the basename, e.g. just "OL10896658M" release.Extra.OpenLibrary.WorkID = v.Works[0].Key release.WorkID = v.Works[0].Key } @@ -668,3 +669,16 @@ func OpenLibraryEditionToRelease(v *OpenLibraryEdition, authorMap map[string]str } return &release, nil } + +// ShortenOpenLibraryIdentifier shortens an id like "/books/OL10899962M" to +// "OL10899962M" or returns the same string, if no simplifications can be made. +// TODO: add test. +func ShortenOpenLibraryIdentifier(s string) string { + fields := strings.Split(s, "/") + for _, f := range fields { + if strings.HasPrefix(f, "OL") { + return f + } + } + return s +} |