From c263decdfe951883c8b07518d796ac461bb6b1bc Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 11 Jul 2017 20:19:37 +1200 Subject: [PATCH] db: automatically populate first article in blank databases --- WikiServer.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/WikiServer.go b/WikiServer.go index fde6b4f..eb324b4 100644 --- a/WikiServer.go +++ b/WikiServer.go @@ -1,6 +1,7 @@ package yatwiki3 import ( + "database/sql" "errors" "fmt" "html/template" @@ -28,6 +29,14 @@ func NewWikiServer(opts *ServerOptions) (*WikiServer, error) { return nil, err } + tr, err := wdb.TotalRevisions() + if (err == nil && tr == 0) || err == sql.ErrNoRows { + err := wdb.SaveArticle(opts.DefaultPage, `YATWiki3`, "", 0) + if err != nil { + return nil, err + } + } + tmpl, err := template.New("yatwiki/page").Parse(pageTemplate) if err != nil { return nil, err