]> Sergey Matveev's repositories - sgblog.git/commitdiff
Shorter datetimes displaying
authorSergey Matveev <stargrave@stargrave.org>
Sat, 14 Mar 2020 11:33:55 +0000 (14:33 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 14 Mar 2020 11:33:55 +0000 (14:33 +0300)
cmd/sgblog/gopher.go
cmd/sgblog/http.go
common.go

index 808c40fb0d343e080a82d1cbb73e5e2a62791691..e98d65b9f08d25c50639b39af32aec232495f08b 100644 (file)
@@ -30,6 +30,7 @@ import (
        "os"
        "strconv"
        "strings"
+       "time"
 
        "github.com/hjson/hjson-go"
        "go.stargrave.org/sgblog"
@@ -95,22 +96,33 @@ func serveGopher() {
 
                logEnded := false
                var menu bytes.Buffer
+               var yearPrev int
+               var monthPrev time.Month
+               var dayPrev int
                for i := 0; i < PageEntries; i++ {
                        commit, err := repoLog.Next()
                        if err != nil {
                                logEnded = true
                                break
                        }
+                       yearCur, monthCur, dayCur := commit.Author.When.Date()
+                       if dayCur != dayPrev || monthCur != monthPrev || yearCur != yearPrev {
+                               menu.WriteString(fmt.Sprintf(
+                                       "i%04d-%02d-%02d\t\tnull.host\t1%s",
+                                       yearCur, monthCur, dayCur, CRLF,
+                               ))
+                               yearPrev, monthPrev, dayPrev = yearCur, monthCur, dayCur
+                       }
                        commitN++
                        lines := msgSplit(commit.Message)
-
                        var commentsValue string
                        if l := len(parseComments(getNote(commentsTree, commit.Hash))); l > 0 {
                                commentsValue = fmt.Sprintf(" (%dC)", l)
                        }
                        menu.WriteString(fmt.Sprintf(
-                               "0[%s] %s (%dL)%s\t/%s\t%s\t%d%s",
-                               commit.Author.When.Format(sgblog.WhenFmt),
+                               "0[%02d:%02d] %s (%dL)%s\t/%s\t%s\t%d%s",
+                               commit.Author.When.Hour(),
+                               commit.Author.When.Minute(),
                                lines[0],
                                len(lines)-2,
                                commentsValue,
index 18477a6c53fa6b7c81159a040daae8e067247125..968555826bba8621a28e59578b0b859e6b626359 100644 (file)
@@ -35,6 +35,7 @@ import (
        "os"
        "strconv"
        "strings"
+       "time"
 
        "github.com/hjson/hjson-go"
        "go.stargrave.org/sgblog"
@@ -300,7 +301,18 @@ func serveHTTP() {
                                `<th size="5%"><a title="Lines">L</a></th>` +
                                `<th size="5%"><a title="Comments">C</a></th>` +
                                "<th>Linked to</th></tr>\n")
+               var yearPrev int
+               var monthPrev time.Month
+               var dayPrev int
                for _, entry := range entries {
+                       yearCur, monthCur, dayCur := entry.commit.Author.When.Date()
+                       if dayCur != dayPrev || monthCur != monthPrev || yearCur != yearPrev {
+                               table.WriteString(fmt.Sprintf(
+                                       "<tr><td colspan=6><center><tt>%04d-%02d-%02d</tt></center></td></tr>\n",
+                                       yearCur, monthCur, dayCur,
+                               ))
+                               yearPrev, monthPrev, dayPrev = yearCur, monthCur, dayCur
+                       }
                        commitN++
                        lines := msgSplit(entry.commit.Message)
                        domains := []string{}
@@ -318,11 +330,13 @@ func serveHTTP() {
                                commentsValue = "&nbsp;"
                        }
                        table.WriteString(fmt.Sprintf(
-                               "<tr><td>%d</td><td><tt>%s</tt></td>"+
+                               "<tr><td>%d</td><td><tt>%02d:%02d</tt></td>"+
                                        "<td>%s</td>"+
                                        "<td>%d</td><td>%s</td>"+
                                        "<td>%s</td></tr>\n",
-                               commitN, entry.commit.Author.When.Format(sgblog.WhenFmt),
+                               commitN,
+                               entry.commit.Author.When.Hour(),
+                               entry.commit.Author.When.Minute(),
                                makeA(cfg.URLPrefix+"/"+entry.commit.Hash.String(), lines[0]),
                                len(lines)-2,
                                commentsValue,
index f778860cfae7e6fa23bd16ae3bbc169736d61bc3..de1739390dcf929d948e400044aa7268e4ddf3f3 100644 (file)
--- a/common.go
+++ b/common.go
@@ -2,6 +2,6 @@
 package sgblog
 
 const (
+       Version = "0.4.0"
        WhenFmt = "2006-01-02 15:04:05Z07:00"
-       Version = "0.3.5"
 )