|
|
|
@ -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"
|
|
|
|
|