db: automatically populate first article in blank databases

This commit is contained in:
mappu 2017-07-11 20:19:37 +12:00
parent 53e5e0cfae
commit c263decdfe

View File

@ -1,6 +1,7 @@
package yatwiki3 package yatwiki3
import ( import (
"database/sql"
"errors" "errors"
"fmt" "fmt"
"html/template" "html/template"
@ -28,6 +29,14 @@ func NewWikiServer(opts *ServerOptions) (*WikiServer, error) {
return nil, err 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) tmpl, err := template.New("yatwiki/page").Parse(pageTemplate)
if err != nil { if err != nil {
return nil, err return nil, err