Compare commits

...
4 Commits
10 changed files with 14699 additions and 7 deletions
+1 -1
View File
@@ -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 package assets
+73
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+4463
View File
File diff suppressed because it is too large Load Diff
+10078
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -96,5 +96,5 @@ func (ch *CaddyHugo) TmplData(r *http.Request, docref *docref) interface{} {
ch.HugoSites.Fs.Destination = afero.NewMemMapFs() ch.HugoSites.Fs.Destination = afero.NewMemMapFs()
ch.Build() ch.Build()
} }
return tmplData{ch.Site, r, ch, doc, docref} return &tmplData{ch.Site, r, ch, doc, docref}
} }
+16 -3
View File
@@ -51,6 +51,8 @@ func (ch *CaddyHugo) DeltaWebsocket(w http.ResponseWriter, r *http.Request) (int
return http.StatusBadRequest, err return http.StatusBadRequest, err
} }
conn.SetReadDeadline(time.Time{})
doc, err := ch.doc(r) doc, err := ch.doc(r)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@@ -84,7 +86,10 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
timer := time.NewTimer(idlePing) timer := time.NewTimer(idlePing)
resetTimer := func(d time.Duration) { resetTimer := func(d time.Duration) {
if !timer.Stop() { if !timer.Stop() {
<-timer.C select {
case <-timer.C:
default:
}
} }
timer.Reset(d) timer.Reset(d)
} }
@@ -115,7 +120,7 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
err := conn.ReadJSON(&message) err := conn.ReadJSON(&message)
if err != nil { if err != nil {
errCh <- err errCh <- fmt.Errorf("error reading message from client conn: %v", err)
return return
} }
ch.ObserveLTime(message.LTime) ch.ObserveLTime(message.LTime)
@@ -127,7 +132,7 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
err = client.PushDeltas(message.Deltas...) err = client.PushDeltas(message.Deltas...)
if err != nil { if err != nil {
errCh <- err errCh <- fmt.Errorf("error pushing deltas into document: %v", err)
return return
} }
@@ -141,9 +146,17 @@ func (ch *CaddyHugo) handleConn(conn DeltaConn, doc *docref) (int, error) {
}() }()
for { for {
select {
case err := <-errCh:
fmt.Println("error handling websocket connection:", err)
return 500, err
default:
}
select { select {
case <-timer.C: case <-timer.C:
conn.WriteJSON(ch.Message()) conn.WriteJSON(ch.Message())
resetTimer(idlePing)
case <-readMessagesCh: case <-readMessagesCh:
resetTimer(idlePingShort) resetTimer(idlePingShort)
case <-wroteMessagesCh: case <-wroteMessagesCh:
+12
View File
@@ -43,6 +43,18 @@ func (ch *CaddyHugo) ServeHTTPWithNext(next httpserver.Handler, c *caddy.Control
w.Write(assets.MustAsset("simplemde/debug/simplemde.js")) w.Write(assets.MustAsset("simplemde/debug/simplemde.js"))
return http.StatusOK, nil 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") { if strings.HasPrefix(r.URL.Path, "/hugo/admin") {
return ch.Admin().ServeHTTP(w, r) return ch.Admin().ServeHTTP(w, r)
} }
+49
View File
@@ -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
View File
@@ -119,8 +119,8 @@ a {
} }
</style> </style>
<link rel="stylesheet" href="/hugo/simplemde.css" /> <link rel="stylesheet" href="/hugo/simplemde.css" />
<script src="https://unpkg.com/vue"></script> <script src="/hugo/vue.js"></script>
<script src="https://unpkg.com/moment"></script> <script src="/hugo/moment.js"></script>
<body> <body>