mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/taigrr/gico/commits"
|
|
"github.com/taigrr/gico/gitgraph/svg"
|
|
)
|
|
|
|
type DayCount [366]int
|
|
|
|
func main() {
|
|
r := mux.NewRouter()
|
|
r.HandleFunc("/weekly.svg", func(w http.ResponseWriter, r *http.Request) {
|
|
author := r.URL.Query().Get("author")
|
|
w.Header().Add("Content-Type", "text/html")
|
|
now := time.Now()
|
|
year := now.Year()
|
|
freq, err := commits.GlobalFrequencyChan(year, []string{author})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
today := now.YearDay() - 1
|
|
fmt.Println(today)
|
|
if today < 6 {
|
|
curYear := year - 1
|
|
curFreq, err := commits.GlobalFrequencyChan(curYear, []string{author})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
freq = append(curFreq, freq...)
|
|
today += 365
|
|
if curYear%4 == 0 {
|
|
today++
|
|
}
|
|
}
|
|
fmt.Println(freq)
|
|
week := freq[today-6 : today+1]
|
|
svg := svg.GetWeekSVG(week)
|
|
svg.WriteTo(w)
|
|
})
|
|
r.HandleFunc("/yearly.svg", func(w http.ResponseWriter, r *http.Request) {
|
|
year := time.Now().Year()
|
|
yst := r.URL.Query().Get("year")
|
|
author := r.URL.Query().Get("author")
|
|
y, err := strconv.Atoi(yst)
|
|
if err == nil {
|
|
year = y
|
|
}
|
|
freq, err := commits.GlobalFrequencyChan(year, []string{author})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
svg := svg.GetYearSVG(freq)
|
|
w.Header().Add("Content-Type", "text/html")
|
|
svg.WriteTo(w)
|
|
})
|
|
|
|
http.ListenAndServe(":8080", r)
|
|
}
|