aboutsummaryrefslogtreecommitdiffstats
path: root/skate
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-07-01 19:56:49 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-07-01 19:56:49 +0200
commit11c4c7d5bc9e061586ed79bb38a670129406d513 (patch)
tree8f8f2be096de89fdb7082e73ddbbcd612c5c369f /skate
parent8f424c4e37ee738fe8c08b17953f9c40d6b5fb5c (diff)
downloadrefcat-11c4c7d5bc9e061586ed79bb38a670129406d513.tar.gz
refcat-11c4c7d5bc9e061586ed79bb38a670129406d513.zip
wip: shorter ol names
Diffstat (limited to 'skate')
-rw-r--r--skate/schema.go14
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
+}