From 11c4c7d5bc9e061586ed79bb38a670129406d513 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Thu, 1 Jul 2021 19:56:49 +0200 Subject: wip: shorter ol names --- skate/schema.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'skate') 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 +} -- cgit v1.2.3