better render performance and code cleanup
This commit is contained in:
parent
3cd460318a
commit
fb41dd75c4
3 changed files with 28 additions and 27 deletions
26
engine.go
26
engine.go
|
|
@ -62,7 +62,7 @@ func (e *Engine) Index(title, text, user string, public bool) (string, error) {
|
|||
title = titleRe.ReplaceAllString(title, "")
|
||||
newTitle := makeLinkTitle(title)
|
||||
if err := e.Exists(false, newTitle); err == nil {
|
||||
return "", errors.New("engine: article already exists")
|
||||
return "", errors.New("engine: article '" + title + "' already exists")
|
||||
}
|
||||
art := render(text)
|
||||
art.Title = title
|
||||
|
|
@ -81,8 +81,8 @@ func (e *Engine) Exists(public bool, title string) error {
|
|||
}
|
||||
|
||||
func (e *Engine) Delete(title string) error {
|
||||
if title == "Index" {
|
||||
return errors.New("engine: the index page cannot be deleted")
|
||||
if title == indexName {
|
||||
return errors.New("engine: page '" + indexName + "' cannot be deleted")
|
||||
}
|
||||
if err := e.Exists(false, title); err != nil {
|
||||
return err
|
||||
|
|
@ -94,8 +94,8 @@ func (e *Engine) Update(title, text, user string, public bool) error {
|
|||
if user == "" {
|
||||
return errors.New("engine: user cannot be empty")
|
||||
}
|
||||
if title == "Index" && !public {
|
||||
return errors.New("engine: page 'Index' must stay public")
|
||||
if title == indexName && !public {
|
||||
return errors.New("engine: page '" + indexName + "' must stay public")
|
||||
}
|
||||
if err := e.Exists(false, title); err != nil {
|
||||
return err
|
||||
|
|
@ -149,11 +149,10 @@ func (e *Engine) Get(public bool, title string) (Article, error) {
|
|||
art.Public = p
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
art.LinkTitle = title
|
||||
if public && !art.Public {
|
||||
err = errors.New("engine: article does not exist")
|
||||
err = errors.New("engine: article '" + title + "' does not esist")
|
||||
}
|
||||
return art, err
|
||||
}
|
||||
|
|
@ -240,13 +239,12 @@ func (e *Engine) GetAll(public bool) (t []Title, err error) {
|
|||
continue
|
||||
}
|
||||
for _, field := range doc.Fields {
|
||||
if field.Name() != "title" {
|
||||
continue
|
||||
}
|
||||
f, ok := field.(*document.TextField)
|
||||
if ok {
|
||||
t = append(t, Title{string(f.Value()), v.ID})
|
||||
break
|
||||
if field.Name() == "title" {
|
||||
f, ok := field.(*document.TextField)
|
||||
if ok {
|
||||
t = append(t, Title{string(f.Value()), v.ID})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue