Skip to content

Commit

Permalink
Add -diary for diary mode
Browse files Browse the repository at this point in the history
New creates a new page with a timestamp
  • Loading branch information
schollz committed Nov 4, 2017
1 parent 63bdbb5 commit 684ff4e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
var customCSS []byte
var defaultLock string
var debounceTime int
var diaryMode bool

func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defaultPage string, defaultPassword string, debounce int) {
func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defaultPage string, defaultPassword string, debounce int, diary bool) {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
store := sessions.NewCookieStore([]byte("secret"))
Expand Down Expand Up @@ -73,6 +74,9 @@ func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defa
// set the debounce time
debounceTime = debounce

// set diary mode
diaryMode = diary

if TLS {
http.ListenAndServeTLS(host+":"+port, crt_path, key_path, router)
} else {
Expand Down Expand Up @@ -340,6 +344,8 @@ func handlePageRequest(c *gin.Context) {
"IsPublished": p.IsPublished,
"CustomCSS": len(customCSS) > 0,
"Debounce": debounceTime,
"DiaryMode": diaryMode,
"Date": time.Now().Format("2006-01-02"),
})
}

Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"), c.GlobalInt("debounce"))
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"), c.GlobalBool("diary"))
return nil
}
app.Flags = []cli.Flag{
Expand Down Expand Up @@ -96,6 +96,10 @@ func main() {
Name: "debug, d",
Usage: "turn on debugging",
},
cli.BoolFlag{
Name: "diary",
Usage: "turn diary mode (doing New will give a timestamped page)",
},
}
app.Commands = []cli.Command{
{
Expand Down
4 changes: 4 additions & 0 deletions templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,11 @@ body#pad textarea {
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
<a href="#" id="menuLink1" class="pure-menu-link">{{ .Page }}</a>
<ul class="pure-menu-children">
{{ if .DiaryMode }}
<li class="pure-menu-item"><a href="/{{ .Date }}/edit" class="pure-menu-link">New</a></li>
{{ else }}
<li class="pure-menu-item"><a href="/" class="pure-menu-link">New</a></li>
{{ end }}
<li class="pure-menu-item"><a href="https://github.com/schollz/cowyo" class="pure-menu-link">Source</a></li>
{{ if .EditPage }}
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="publishPage">
Expand Down

2 comments on commit 684ff4e

@gitfvb
Copy link

@gitfvb gitfvb commented on 684ff4e Nov 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow starting CowYo with "--diary" on windows, the diary mode does not work... but I cannot see from the code where the problem is... Does anyone else have an idea? Version is 2.8.0

@schollz
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me on windows, can you describe what is happening (and not happening)? Basically, all -diary will do is make the "New" button create a page with today's date.

Please sign in to comment.