diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-28 18:01:33 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-28 18:01:33 +0200 |
| commit | 5e1664b8008675177a551aff1de371f54d4e20e4 (patch) | |
| tree | ffe405e1e2767890e473f75f474d2781af683f1b /internal/bible/bible.go | |
| parent | f7344bb3de2885323a785bdc8d087bc034407fc4 (diff) | |
| download | lectio-5e1664b8008675177a551aff1de371f54d4e20e4.tar.gz lectio-5e1664b8008675177a551aff1de371f54d4e20e4.zip | |
bible: embed only the Vulgate by default; other corpora opt-in
Split the bundled corpora so the default binary carries only the
public-domain Latin Vulgate. wuj/drb/grb move to corpora_optional/ and are
compiled in only with `-tags fullbible`, or dropped into the user corpora
dir at runtime. This keeps the distributed AGPL binary free of third-party
scripture text -- bible corpora are not covered by lectio's licence.
- bible: read corpus files/metadata from core + optional embed FS
(embReadCorpus/embCorpusFiles); optionalFS is set only under the tag.
- config: default `versions` now reflects corpora actually available in the
build (Vulgate first), so a vul-only binary offers no absent versions.
- Makefile: `make build` = vul only; `make build-full` embeds the rest;
`make test` runs with -tags fullbible; check-corpora validates both dirs.
- tests: corpusmeta asserts on vul (the always-embedded corpus); the
versions-default expectation follows availableVersions().
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{}} |
