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 }