Add link to today's page in navbar
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2020-07-19 15:18:03 +02:00
parent ff4f165c32
commit 942f6b2e9f
4 changed files with 28 additions and 0 deletions

View File

@ -99,6 +99,7 @@ type indexPage struct {
Content template.HTML Content template.HTML
Backrefs map[string][]Backref Backrefs map[string][]Backref
ShowGraph bool ShowGraph bool
TodayPage string
} }
type Node struct { type Node struct {
@ -131,6 +132,7 @@ type editPage struct {
Editor template.HTML Editor template.HTML
Backrefs map[string][]Backref Backrefs map[string][]Backref
ShowGraph bool ShowGraph bool
TodayPage string
} }
type historyPage struct { type historyPage struct {
@ -449,6 +451,7 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Editor: editor, Editor: editor,
Name: page, Name: page,
Backrefs: mpPage.Refs, Backrefs: mpPage.Refs,
TodayPage: todayPage(),
ShowGraph: page != "Daily_Notes", ShowGraph: page != "Daily_Notes",
} }
@ -459,6 +462,7 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
err = t.Execute(w, data) err = t.Execute(w, data)
if err != nil { if err != nil {
log.Println(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
} }
@ -651,6 +655,7 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Name: page, Name: page,
Backrefs: mpPage.Refs, Backrefs: mpPage.Refs,
ShowGraph: page != "Daily_Notes", ShowGraph: page != "Daily_Notes",
TodayPage: todayPage(),
} }
t, err := template.ParseFiles("templates/layout.html", "templates/view.html") t, err := template.ParseFiles("templates/layout.html", "templates/view.html")

View File

@ -1,4 +1,5 @@
{{ define "navbar" }} {{ define "navbar" }}
<a href="/edit/{{ .TodayPage }}" class="navbar-item">Today</a>
<a href="/{{ .Name }}" class="navbar-item">Back</a> <a href="/{{ .Name }}" class="navbar-item">Back</a>
{{ end }} {{ end }}

View File

@ -37,6 +37,7 @@
<a href="/history/{{ .Name }}" class="navbar-item">History</a> <a href="/history/{{ .Name }}" class="navbar-item">History</a>
<a href="/recent/" class="navbar-item">Recent Changes</a> <a href="/recent/" class="navbar-item">Recent Changes</a>
<a href="/graph/" class="navbar-item">Graph</a> <a href="/graph/" class="navbar-item">Graph</a>
<a href="/{{ .TodayPage }}" class="navbar-item">Today</a>
<a href="/auth/logout" class="navbar-item">Logout</a> <a href="/auth/logout" class="navbar-item">Logout</a>
<span class="navbar-item"><b>{{ $.Session.Me }}</b></span> <span class="navbar-item"><b>{{ $.Session.Me }}</b></span>
{{ else }} {{ else }}

21
util.go
View File

@ -2,6 +2,7 @@ package main
import ( import (
"bufio" "bufio"
"fmt"
"log" "log"
"math/rand" "math/rand"
"regexp" "regexp"
@ -95,3 +96,23 @@ func (sw *stopwatch) Stop() {
d := endTime.Sub(sw.start) d := endTime.Sub(sw.start)
log.Printf("%-20s: %s\n", sw.label, d.String()) log.Printf("%-20s: %s\n", sw.label, d.String())
} }
func todayPage() string {
now := time.Now()
months := []string{
"",
"januari",
"februari",
"maart",
"april",
"mei",
"juni",
"juli",
"augustus",
"september",
"oktober",
"november",
"december",
}
return fmt.Sprintf("%d_%s_%d", now.Day(), months[now.Month()], now.Year())
}