Skip to content

Commit

Permalink
✨ Add (Database).FindWork to facilitate alias resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
gwennlbh committed Apr 27, 2024
1 parent 2610507 commit f42fbc8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func LoadDatabase(at string, skipValidation bool) (database Database, err error)
}

func (db Database) FindMedia(mediaEmbed Media, workID string) (found bool, media Media) {
w, ok := db[workID]
w, ok := db.FindWork(workID)

if !ok {
return false, Media{}
Expand All @@ -45,6 +45,20 @@ func (db Database) FindMedia(mediaEmbed Media, workID string) (found bool, media
return false, Media{}
}

func (db Database) FindWork(idOrAlias string) (work Work, found bool) {
work, found = db[idOrAlias]
if !found {
for _, w := range db {
for _, alias := range w.Metadata.Aliases {
if alias == idOrAlias {
return w, true
}
}
}
}
return
}

// FirstParagraph returns the first paragraph content block of the given work in the given language
func (work Work) FirstParagraph(lang string) (found bool, paragraph ContentBlock) {
for _, block := range work.Content[lang].Blocks {
Expand Down

0 comments on commit f42fbc8

Please sign in to comment.