Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c63022b636 | ||
|
|
f753f94390 | ||
|
|
99e794ac00 | ||
|
|
07daa5e160 |
+1
-1
@@ -1,2 +1,2 @@
|
||||
//go:generate go-bindata -pkg assets simplemde/dist/... simplemde/debug/...
|
||||
//go:generate go-bindata -pkg assets simplemde/dist/... simplemde/debug/... js/... css/...
|
||||
package assets
|
||||
|
||||
File diff suppressed because one or more lines are too long
Vendored
+4
File diff suppressed because one or more lines are too long
+4463
File diff suppressed because it is too large
Load Diff
+10078
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -96,5 +96,5 @@ func (ch *CaddyHugo) TmplData(r *http.Request, docref *docref) interface{} {
|
||||
ch.HugoSites.Fs.Destination = afero.NewMemMapFs()
|
||||
ch.Build()
|
||||
}
|
||||
return tmplData{ch.Site, r, ch, doc, docref}
|
||||
return &tmplData{ch.Site, r, ch, doc, docref}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ func (ch *CaddyHugo) DeltaWebsocket(w http.ResponseWriter, r *http.Request) (int
|
||||
return http.StatusBadRequest, err
|
||||
}
|
||||
|
||||
conn.SetReadDeadline(time.Time{})
|
||||
|
||||
doc, err := ch.doc(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -84,7 +86,10 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
|
||||
timer := time.NewTimer(idlePing)
|
||||
resetTimer := func(d time.Duration) {
|
||||
if !timer.Stop() {
|
||||
<-timer.C
|
||||
select {
|
||||
case <-timer.C:
|
||||
default:
|
||||
}
|
||||
}
|
||||
timer.Reset(d)
|
||||
}
|
||||
@@ -115,7 +120,7 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
|
||||
|
||||
err := conn.ReadJSON(&message)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
errCh <- fmt.Errorf("error reading message from client conn: %v", err)
|
||||
return
|
||||
}
|
||||
ch.ObserveLTime(message.LTime)
|
||||
@@ -127,7 +132,7 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
|
||||
|
||||
err = client.PushDeltas(message.Deltas...)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
errCh <- fmt.Errorf("error pushing deltas into document: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -141,9 +146,17 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case err := <-errCh:
|
||||
fmt.Println("error handling websocket connection:", err)
|
||||
return 500, err
|
||||
default:
|
||||
}
|
||||
|
||||
select {
|
||||
case <-timer.C:
|
||||
conn.WriteJSON(ch.Message())
|
||||
resetTimer(idlePing)
|
||||
case <-readMessagesCh:
|
||||
resetTimer(idlePingShort)
|
||||
case <-wroteMessagesCh:
|
||||
|
||||
@@ -43,6 +43,18 @@ func (ch *CaddyHugo) ServeHTTPWithNext(next httpserver.Handler, c *caddy.Control
|
||||
w.Write(assets.MustAsset("simplemde/debug/simplemde.js"))
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
if strings.HasPrefix(r.URL.Path, "/hugo/vue.js") {
|
||||
w.Write(assets.MustAsset("js/vue.js"))
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
if strings.HasPrefix(r.URL.Path, "/hugo/moment.js") {
|
||||
w.Write(assets.MustAsset("js/moment.js"))
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
if strings.HasPrefix(r.URL.Path, "/hugo/font-awesome.css") {
|
||||
w.Write(assets.MustAsset("css/font-awesome.min.css"))
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
if strings.HasPrefix(r.URL.Path, "/hugo/admin") {
|
||||
return ch.Admin().ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package caddyhugo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestThumbSizeStrings tests parsing various size strings, which doesn't include
|
||||
// scaling zeros, but does use the actual image size to infer single-dimension
|
||||
// strings
|
||||
func TestThumbSizeStrings(t *testing.T) {
|
||||
type testcase struct {
|
||||
input string
|
||||
actualSize image.Rectangle
|
||||
expect image.Rectangle
|
||||
}
|
||||
|
||||
i50x100 := image.Rect(0, 0, 50, 100)
|
||||
i100x100 := image.Rect(0, 0, 100, 100)
|
||||
|
||||
var cases = []testcase{
|
||||
{"100x100", i100x100, image.Rect(0, 0, 100, 100)},
|
||||
{"x100", i100x100, image.Rect(0, 0, 0, 100)},
|
||||
{"100x", i100x100, image.Rect(0, 0, 100, 0)},
|
||||
{"100", i100x100, image.Rect(0, 0, 100, 0)},
|
||||
|
||||
{"100x100", i50x100, image.Rect(0, 0, 100, 100)},
|
||||
{"x100", i50x100, image.Rect(0, 0, 0, 100)},
|
||||
{"100x", i50x100, image.Rect(0, 0, 100, 0)},
|
||||
{"100", i50x100, image.Rect(0, 0, 0, 100)},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(fmt.Sprint(c.input, "=>", c.actualSize), func(t *testing.T) {
|
||||
got, err := parseSizeString(c.input, image.Rect(0, 0, 100, 100))
|
||||
if err != nil {
|
||||
t.Errorf("error parsing size string: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !got.Eq(c.expect) {
|
||||
t.Errorf("expected %v, got %v", c.expect, got)
|
||||
return
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -119,8 +119,8 @@ a {
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="/hugo/simplemde.css" />
|
||||
<script src="https://unpkg.com/vue"></script>
|
||||
<script src="https://unpkg.com/moment"></script>
|
||||
<script src="/hugo/vue.js"></script>
|
||||
<script src="/hugo/moment.js"></script>
|
||||
|
||||
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user