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

View File

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

View File

@ -37,6 +37,7 @@
<a href="/history/{{ .Name }}" class="navbar-item">History</a>
<a href="/recent/" class="navbar-item">Recent Changes</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>
<span class="navbar-item"><b>{{ $.Session.Me }}</b></span>
{{ else }}

21
util.go
View File

@ -2,6 +2,7 @@ package main
import (
"bufio"
"fmt"
"log"
"math/rand"
"regexp"
@ -95,3 +96,23 @@ func (sw *stopwatch) Stop() {
d := endTime.Sub(sw.start)
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())
}