aboutsummaryrefslogtreecommitdiff
path: root/internal/bible/corpusmeta.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/bible/corpusmeta.go')
-rw-r--r--internal/bible/corpusmeta.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/internal/bible/corpusmeta.go b/internal/bible/corpusmeta.go
new file mode 100644
index 0000000..04b9dcb
--- /dev/null
+++ b/internal/bible/corpusmeta.go
@@ -0,0 +1,45 @@
+package bible
+
+import "github.com/lukaszkasprzak/lectio/internal/ini"
+
+// CorpusMeta is the sidecar metadata for a bible corpus (<code>.ini).
+type CorpusMeta struct {
+ Code, Lang, Name, PsalmSystem, Sigla string
+}
+
+// parseCorpusMeta reads a section-less sidecar. ini.Parse returns
+// []ini.Section{Name, Pairs}; keys before any [section] land in the section
+// whose Name == "" (verified against internal/ini).
+func parseCorpusMeta(code string, data []byte) CorpusMeta {
+ m := CorpusMeta{Code: code}
+ secs, err := ini.Parse(data)
+ if err != nil {
+ return m
+ }
+ for _, s := range secs {
+ if s.Name != "" {
+ continue
+ }
+ for _, p := range s.Pairs {
+ switch p.Key {
+ case "lang":
+ m.Lang = p.Val
+ case "name":
+ m.Name = p.Val
+ case "psalm_system":
+ m.PsalmSystem = p.Val
+ case "sigla":
+ m.Sigla = p.Val
+ }
+ }
+ }
+ return m
+}
+
+func embeddedCorpusMeta(code string) (CorpusMeta, bool) {
+ data, err := corporaFS.ReadFile("corpora/" + code + ".ini")
+ if err != nil {
+ return CorpusMeta{}, false
+ }
+ return parseCorpusMeta(code, data), true
+}