diff options
Diffstat (limited to 'internal/bible/bible.go')
| -rw-r--r-- | internal/bible/bible.go | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/internal/bible/bible.go b/internal/bible/bible.go index ac746e1..1fb29f2 100644 --- a/internal/bible/bible.go +++ b/internal/bible/bible.go @@ -2,6 +2,7 @@ package bible import ( "embed" + "io/fs" "os" "sort" "strconv" @@ -9,9 +10,55 @@ import ( "sync" ) +// corporaFS embeds only the public-domain Latin Vulgate (vul), which is the +// sole corpus compiled into the default binary. Every other translation lives +// in corpora_optional/ and is NOT embedded unless the build carries the +// "fullbible" tag (see embed_optional.go), keeping the distributed binary free +// of any third-party scripture text -- bible corpora are not covered by +// lectio's AGPL licence. Missing corpora resolve gracefully to a "(not in +// <code>)" note, and users may drop any <code>.tsv/<code>.ini into their +// corpora dir (SetUserCorporaDir) to add a translation without rebuilding. +// //go:embed corpora var corporaFS embed.FS +// optionalFS holds the extra corpora (corpora_optional/) when the "fullbible" +// build tag is set; it is nil in the default build. Set by embed_optional.go. +var optionalFS fs.FS + +// embReadCorpus returns the bytes of an embedded corpus file (e.g. "vul.tsv", +// "drb.ini") from the core FS, then the optional FS if present. +func embReadCorpus(name string) ([]byte, bool) { + if b, err := corporaFS.ReadFile("corpora/" + name); err == nil { + return b, true + } + if optionalFS != nil { + if b, err := fs.ReadFile(optionalFS, "corpora_optional/"+name); err == nil { + return b, true + } + } + return nil, false +} + +// embCorpusFiles lists the base file names of every embedded corpus file across +// the core and optional FSes. +func embCorpusFiles() []string { + var names []string + if ents, err := corporaFS.ReadDir("corpora"); err == nil { + for _, e := range ents { + names = append(names, e.Name()) + } + } + if optionalFS != nil { + if ents, err := fs.ReadDir(optionalFS, "corpora_optional"); err == nil { + for _, e := range ents { + names = append(names, e.Name()) + } + } + } + return names +} + // Verse is a single verse. type Verse struct { Chapter, Verse int @@ -38,7 +85,7 @@ func load(version string) *corpus { data, _ = os.ReadFile(p) } if data == nil { - data, _ = corporaFS.ReadFile("corpora/" + version + ".tsv") + data, _ = embReadCorpus(version + ".tsv") } if data == nil { corpora[version] = &corpus{books: map[string]map[int][]Verse{}} |
