summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authornytpu <alex@nytpu.com>2021-03-22 08:19:41 -0600
committernytpu <alex@nytpu.com>2021-03-22 08:19:41 -0600
commit8d9892b0a1b4cd696ec3f91adb06e322093490ff (patch)
tree796d9b72f826d3b6de1e41dca50da16003f72ba2 /core
parent1eda2eaea812231f627d5aa84a5036f8f977c662 (diff)
read header.gmi and set header variable to that or to the default
Diffstat (limited to 'core')
-rw-r--r--core/core.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/core.go b/core/core.go
index 513c84c..f3d88ff 100644
--- a/core/core.go
+++ b/core/core.go
@@ -28,9 +28,14 @@ var Data = FullData{
// Maps are created in init()
}
+// the header of feeds.gmi.
+// set in Init, either to the contents of header.gmi or to the default string
+var Header string
+
// have to do this instead of the automatically called init() because
// initialization stuff requires parsing of command line args first
func Init(dataPath string) error {
+ // initialize comitium.json & data maps
f, err := os.Open(filepath.Join(dataPath, "comitium.json"))
if err == nil {
// File exists and could be opened
@@ -59,6 +64,30 @@ func Init(dataPath string) error {
if Data.Pages == nil {
Data.Pages = make(map[string]*Page)
}
+
+ // initialize header.gmi
+ f, err = os.Open(filepath.Join(dataPath, "header.gmi"))
+ if err == nil {
+ fi, err := f.Stat()
+ if err == nil && fi.Size() > 0 {
+ headerBytes, err := ioutil.ReadAll(f)
+ f.Close()
+ if err != nil {
+ return fmt.Errorf("read header.gmi error: %w", err)
+ }
+ Header = string(headerBytes)
+ }
+ f.Close()
+ } else if !os.IsNotExist(err) {
+ return fmt.Errorf("open header.gmi error: %w", err)
+ }
+
+ if Header == "" {
+ Header = `# comitium subscriptions
+
+`
+ }
+
return nil
}