Comments: fixes #9 #10
+17
-6
@@ -8,6 +8,7 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -175,17 +176,27 @@ func (d *diskvStorage) nextKey(post string) (string, error) {
|
|||||||
d.keyMtx.Lock()
|
d.keyMtx.Lock()
|
||||||
defer d.keyMtx.Unlock()
|
defer d.keyMtx.Unlock()
|
||||||
|
|
||||||
var i uint64
|
|
||||||
|
|
||||||
prefix := post + "-"
|
prefix := post + "-"
|
||||||
|
|
||||||
|
lastKey := prefix
|
||||||
|
|
||||||
keys := d.KeysPrefix(prefix, nil)
|
keys := d.KeysPrefix(prefix, nil)
|
||||||
for range keys {
|
for key := range keys {
|
||||||
i++
|
lastKey = key
|
||||||
}
|
}
|
||||||
|
|
||||||
key := prefix + fmt.Sprint(i)
|
if lastKey == prefix {
|
||||||
err := d.WriteStream(key, &bytes.Buffer{}, true)
|
return prefix + "1", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
minusPrefix := lastKey[len(prefix):]
|
||||||
|
lastIdx, err := strconv.Atoi(minusPrefix)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("comment key %q seems malformed", lastKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
key := prefix + fmt.Sprint(lastIdx+1)
|
||||||
|
err = d.WriteStream(key, &bytes.Buffer{}, true)
|
||||||
|
|
||||||
return key, err
|
return key, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (ch *CaddyHugo) commentsSetting(c *caddy.Controller) {
|
|||||||
if c.Val() == "hugo" {
|
if c.Val() == "hugo" {
|
||||||
for c.NextBlock() {
|
for c.NextBlock() {
|
||||||
if c.Val() == "comments" {
|
if c.Val() == "comments" {
|
||||||
ch.Comments = comments.Default()
|
ch.Comments = comments.WithStorage(comments.NewDiskv(path.Join(ch.Site.Root, "comments")))
|
||||||
if c.NextArg() {
|
if c.NextArg() {
|
||||||
ch.Comments.Password = c.Val()
|
ch.Comments.Password = c.Val()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user