EurekaAdapter: flesh out CreatePage, SavePage, DeletePage and added TODO comments and the Config map; gofmt

This commit is contained in:
Iris Lightshard 2022-06-05 12:09:00 -06:00
parent 1bc8eac481
commit b9d971140a
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
5 changed files with 62 additions and 35 deletions

View file

@ -4,7 +4,7 @@ type Adapter interface {
Init(cfg *Config)
Name() string
EditableSlugs() bool
BuildOptions() ([]string)
BuildOptions() []string
GetConfig(key string) (interface{}, error)
SetConfig(key string, value interface{}) error
ListPages() map[string]string

View file

@ -10,6 +10,7 @@ import (
type EurekaAdapter struct {
Root string
Config map[string]interface{}
}
func (self *EurekaAdapter) Init(cfg *Config) {
@ -21,6 +22,8 @@ func (self *EurekaAdapter) Init(cfg *Config) {
}
self.Root = cfg.Root
// TODO: read config.h and build self.Config
}
func (self *EurekaAdapter) Name() string {
@ -88,25 +91,49 @@ func (self *EurekaAdapter) GetPage(filename string) (Page, error) {
}
func (self *EurekaAdapter) FormatPage(raw string) string {
// TODO: implement Eureka formatter to show preview
return raw
}
func (self *EurekaAdapter) FormattingHelp() string {
// TODO: show Eureka formatting guide
return "help!"
}
func (self *EurekaAdapter) CreatePage(slug, title, content string) error {
// eureka makes titles from slugs, so we don't use title here
f, err := os.Create(filepath.Join(self.Root, "inc", newSlug))
if err != nil {
return err
}
defer f.Close()
f.WriteString(content)
return nil
}
func (self *EurekaAdapter) SavePage(oldSlug, newSlug, title, content string) error {
// eureka makes titles from slugs, so we don't use title here
f, err := os.Create(filepath.Join(self.Root, "inc", newSlug))
if err != nil {
return err
}
defer f.Close()
if oldSlug != newSlug {
// TODO: delete old html as well
os.Remove(filepath.Join(self.Root, "inc", oldSlug))
}
f.WriteString(content)
return nil
}
func (self *EurekaAdapter) DeletePage(slug string) error {
return nil
// TODO: delete old html as well
return os.Remove(filepath.Join(self.Root, "inc", slug))
}
func (self *EurekaAdapter) Build(buildOptions map[string]string) (bool, string) {
// TODO: shell out to build.sh with buildOptions, record exit status and output
return true, "Build successful"
}

View file

@ -2,9 +2,9 @@ package lfo
import (
"context"
"strings"
"net/http"
core "nilfm.cc/git/nirvash/archetype"
"strings"
)
func WithAdapter(next http.Handler, adapter core.Adapter) http.Handler {

View file

@ -33,7 +33,7 @@ func main() {
},
}
rtr.Get("/login",renderer.Template(
rtr.Get("/login", renderer.Template(
"templates/login.html"))
rtr.Post("/login", middleware.Authorize("/", udb, "/login?tryagain=1"))