Add calendar
continuous-integration/drone/push Build is passing Details

single-block-api
Peter Stuifzand 3 years ago
parent 67d658d1ba
commit d1858ad849

@ -219,19 +219,74 @@ mark {
.grid {
display: grid;
grid-template-columns: 300px auto;
grid-template-columns: 300px 1000px auto;
.sidebar {
padding: 0 12px;
width: 100%;
.wiki-link {
&::before, &::after {
content: '';
}
}
}
.sidebar-right {
width: 100%;
padding: 0 12px;
}
}
.calendar-grid {
display: grid;
width: calc(8*48px);
grid-template-columns: repeat(8, auto);
border-right: 1px solid #444;
border-bottom: 1px solid #444;
.day {
width: 48px;
height: 48px;
border-left: 1px solid #444;
border-top: 1px solid #444;
text-align: center;
vertical-align: middle;
padding: 3px 0 0 0;
position: relative;
}
.week {
background: #ebebff;
}
.week a {
color: black;
}
.day a {
position: absolute;
top: 1px;
right: 3px;
font-size: 9pt;
color: black;
}
.day span {
position: absolute;
width: 100%;
height: 100%;
font-size: 20pt;
color: black;
top: 8px;
left: 0;
right: 0;
bottom: 0;
}
.today {
font-weight: bold;
}
.current {
background: #f0f0f0;
}
}

@ -42,6 +42,13 @@ var (
authToken = os.Getenv("API_TOKEN")
)
type Day struct {
Class string
Text string
URL string
Count string
}
type Backref struct {
Name string
Title string
@ -99,6 +106,8 @@ type PagesRepository interface {
type pageBaseInfo struct {
BaseURL string
RedirectURI string
Days []Day
Month string
}
type indexPage struct {
@ -168,7 +177,7 @@ type recentPage struct {
Recent []Change
}
var baseTemplate = []string{"templates/layout.html", "templates/sidebar.html"}
var baseTemplate = []string{"templates/layout.html", "templates/sidebar.html", "templates/sidebar-right.html"}
type indexHandler struct{}
type graphHandler struct{}
@ -336,7 +345,7 @@ func (h *historyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
pageBase := getPageBase()
pageBase := getPageBase(time.Now())
pageData := historyPage{
pageBaseInfo: pageBase,
Session: sess,
@ -352,12 +361,90 @@ func (h *historyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
func getPageBase() pageBaseInfo {
func daysInMonth(year int, month time.Month) int {
return time.Date(year, month, 1, 0, 0, 0, 0, time.UTC).AddDate(0, 1, -1).Day()
}
func prepareDays(t time.Time) []Day {
today := time.Now()
var days []Day
curDate := t.AddDate(0, 0, -t.Day()+1)
preDays := int(curDate.Weekday()) - 1
maxDays := daysInMonth(curDate.Year(), curDate.Month())
endOfMonth := false
for i := 0; i < 6; i++ {
_, week := curDate.ISOWeek()
days = append(days, Day{
Class: "week day",
Text: fmt.Sprintf("%02d", week),
URL: "",
Count: "",
})
for d := 0; d < 7; d++ {
day := -preDays + (i * 7) + 1 + d
fday := fmt.Sprintf("%d", day)
if day <= 0 {
fday = ""
}
if day > maxDays {
fday = ""
endOfMonth = true
}
class := "day"
if timeEqual(curDate, today) {
class += " today"
}
if timeEqual(curDate, t) {
class += " current"
}
days = append(days, Day{
Class: class,
Text: fday,
URL: fmt.Sprintf("/edit/%s", formatDatePageName(curDate)),
Count: "",
})
if fday != "" {
curDate = curDate.AddDate(0, 0, 1)
}
if day == maxDays {
endOfMonth = true
}
}
if endOfMonth {
break
}
}
return days
}
func timeEqual(date time.Time, today time.Time) bool {
if date.Year() != today.Year() {
return false
}
if date.Month() != today.Month() {
return false
}
if date.Day() != today.Day() {
return false
}
return true
}
func getPageBase(t time.Time) pageBaseInfo {
clientID := *baseurl
pageBase := pageBaseInfo{
BaseURL: clientID,
RedirectURI: redirectURI,
Days: prepareDays(t),
Month: t.Month().String(),
}
return pageBase
}
@ -374,7 +461,6 @@ func (h *saveHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := sess.Flush(); err != nil {
log.Println(err)
log.Println(err)
}
}()
@ -461,7 +547,11 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
`, html.EscapeString(pageText)))
}
pageBase := getPageBase()
curDate, err := ParseDatePageName(page)
if err != nil {
curDate = time.Now()
}
pageBase := getPageBase(curDate)
title := cleanTitle(mpPage.Title)
if newTitle, err := PageTitle(pageText); err == nil {
title = newTitle
@ -571,7 +661,7 @@ func (h *graphHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
pageBase := getPageBase()
pageBase := getPageBase(time.Now())
data := graphPage{
pageBaseInfo: pageBase,
Session: sess,
@ -736,7 +826,11 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
pageText = renderLinks(pageText, false)
pageText = renderMarkdown2(pageText)
pageBase := getPageBase()
curDate, err := ParseDatePageName(page)
if err != nil {
curDate = time.Now()
}
pageBase := getPageBase(curDate)
data := indexPage{
pageBaseInfo: pageBase,
Session: sess,
@ -850,7 +944,7 @@ func (h *recentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
pageBase := getPageBase()
pageBase := getPageBase(time.Now())
err = t.Execute(w, recentPage{
pageBaseInfo: pageBase,
Session: sess,
@ -914,7 +1008,6 @@ func main() {
return
}
format := r.URL.Query().Get("format")
if format == "" {
format = "json"

@ -57,6 +57,10 @@
<section class="section">
{{ template "content" . }}
</section>
{{ block "sidebar-right" . }}
<div class="sidebar-right"></div>
{{end}}
</div>

@ -0,0 +1,23 @@
{{ define "sidebar-right" }}
<div class="sidebar-right">
<div class="calendar">
<h3>{{ .Month }}</h3>
<div class="calendar-grid">
<div class="day"></div>
<div class="day">m</div>
<div class="day">d</div>
<div class="day">w</div>
<div class="day">d</div>
<div class="day">v</div>
<div class="day">z</div>
<div class="day">z</div>
{{ range .Days }}
<div class="{{ .Class }}">
<a href="{{ .URL }}">{{ .Text }}</a>
<span>{{ .Count }}</span>
</div>
{{ end }}
</div>
</div>
</div>
{{ end }}
Loading…
Cancel
Save