mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Add -debounce for setting the debounce time
This commit is contained in:
parent
85877602e0
commit
63bdbb5824
@ -19,8 +19,9 @@ import (
|
||||
|
||||
var customCSS []byte
|
||||
var defaultLock string
|
||||
var debounceTime int
|
||||
|
||||
func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defaultPage string, defaultPassword string) {
|
||||
func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defaultPage string, defaultPassword string, debounce int) {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
router := gin.Default()
|
||||
store := sessions.NewCookieStore([]byte("secret"))
|
||||
@ -63,11 +64,15 @@ func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defa
|
||||
fmt.Printf("Loaded CSS file, %d bytes\n", len(customCSS))
|
||||
}
|
||||
|
||||
// lock all pages automatically
|
||||
if defaultPassword != "" {
|
||||
fmt.Println("running with locked pages")
|
||||
defaultLock = HashPassword(defaultPassword)
|
||||
}
|
||||
|
||||
// set the debounce time
|
||||
debounceTime = debounce
|
||||
|
||||
if TLS {
|
||||
http.ListenAndServeTLS(host+":"+port, crt_path, key_path, router)
|
||||
} else {
|
||||
@ -334,6 +339,7 @@ func handlePageRequest(c *gin.Context) {
|
||||
"RecentlyEdited": getRecentlyEdited(page, c),
|
||||
"IsPublished": p.IsPublished,
|
||||
"CustomCSS": len(customCSS) > 0,
|
||||
"Debounce": debounceTime,
|
||||
})
|
||||
}
|
||||
|
||||
|
7
main.go
7
main.go
@ -38,7 +38,7 @@ func main() {
|
||||
} else {
|
||||
fmt.Printf("\nRunning cowyo server (version %s) at http://%s:%s\n\n", version, host, c.GlobalString("port"))
|
||||
}
|
||||
serve(c.GlobalString("host"), c.GlobalString("port"), c.GlobalString("cert"), c.GlobalString("key"), TLS, c.GlobalString("css"), c.GlobalString("default-page"), c.GlobalString("lock"))
|
||||
serve(c.GlobalString("host"), c.GlobalString("port"), c.GlobalString("cert"), c.GlobalString("key"), TLS, c.GlobalString("css"), c.GlobalString("default-page"), c.GlobalString("lock"), c.GlobalInt("debounce"))
|
||||
return nil
|
||||
}
|
||||
app.Flags = []cli.Flag{
|
||||
@ -87,6 +87,11 @@ func main() {
|
||||
Value: "",
|
||||
Usage: "password to lock editing all files (default: all pages unlocked)",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "debounce",
|
||||
Value: 500,
|
||||
Usage: "debounce time for saving data, in milliseconds",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "debug, d",
|
||||
Usage: "turn on debugging",
|
||||
|
@ -176,7 +176,7 @@ body#pad textarea {
|
||||
$('#saveEditButton').removeClass()
|
||||
$('#saveEditButton').text("Saving")
|
||||
upload();
|
||||
}, 500));
|
||||
}, {{ .Debounce }}));
|
||||
|
||||
function upload() {
|
||||
$.ajax({
|
||||
@ -531,10 +531,10 @@ body#pad textarea {
|
||||
<a href="#" id="menuLink1" class="pure-menu-link">View</a>
|
||||
<ul class="pure-menu-children">
|
||||
<li class="pure-menu-item">
|
||||
<a href="/{{ .Page }}/view" class="pure-menu-link">Current</a>
|
||||
<a href="/{{ .Page }}/read" class="pure-menu-link">Current</a>
|
||||
</li>
|
||||
{{ range .RecentlyEdited}}
|
||||
<li class="pure-menu-item"><a class="pure-menu-link" href="/{{.}}/view/">{{.}}</a></li>
|
||||
<li class="pure-menu-item"><a class="pure-menu-link" href="/{{.}}/read">{{.}}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
|
Loading…
Reference in New Issue
Block a user