Added total time to pages Issue #22
Former-commit-id: cafa73d9ad79299f3bb0049679d400479d655503 [formerly a49c91b6ed2187d40bba323e98b3f40373ecb855] [formerly 30ed4b6aedb03cff094e9a6ccd90f4e55ca8bff5 [formerly 71165300922812d6eb98203774d9bddcf119978e [formerlye6e5d701e6
]]] Former-commit-id: 9d4d1b049f4c253868704a377d7e813f0bff4adb [formerly 13817559a3e0c4e156cd85916d77d993ba61eda6] Former-commit-id: 15d127b0267745ebcbcc4fd2a15abdba78d8efb9 Former-commit-id:45977e42ff
10
db.go
@ -77,13 +77,14 @@ func hasPassword(title string) (bool, error) {
|
||||
return hasPassword, nil
|
||||
}
|
||||
|
||||
func getCurrentText(title string, version int) (string, []versionsInfo, bool) {
|
||||
func getCurrentText(title string, version int) (string, []versionsInfo, bool, time.Duration) {
|
||||
title = strings.ToLower(title)
|
||||
var vi []versionsInfo
|
||||
totalTime := time.Now().Sub(time.Now())
|
||||
isCurrent := true
|
||||
currentText := ""
|
||||
if !open {
|
||||
return currentText, vi, isCurrent
|
||||
return currentText, vi, isCurrent, totalTime
|
||||
}
|
||||
err := db.View(func(tx *bolt.Tx) error {
|
||||
var err error
|
||||
@ -107,13 +108,14 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool) {
|
||||
currentText = rebuildTextsToDiffN(p, version)
|
||||
isCurrent = false
|
||||
}
|
||||
vi = getImportantVersions(p)
|
||||
vi, totalTime = getImportantVersions(p)
|
||||
log.Println(totalTime)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("Could not get WikiData: %s", err)
|
||||
}
|
||||
return currentText, vi, isCurrent
|
||||
return currentText, vi, isCurrent, totalTime
|
||||
}
|
||||
|
||||
func (p *WikiData) load(title string) error {
|
||||
|
0
install/awwkoala.init
Normal file → Executable file
0
install/awwkoala.nginx
Normal file → Executable file
33
routes.go
@ -8,6 +8,7 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -35,7 +36,7 @@ func editNote(c *gin.Context) {
|
||||
} else {
|
||||
version := c.DefaultQuery("version", "-1")
|
||||
versionNum, _ := strconv.Atoi(version)
|
||||
currentText, versions, currentVersion := getCurrentText(title, versionNum)
|
||||
currentText, versions, currentVersion, totalTime := getCurrentText(title, versionNum)
|
||||
numRows := len(strings.Split(currentText, "\n")) + 10
|
||||
if currentVersion {
|
||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||
@ -45,6 +46,7 @@ func editNote(c *gin.Context) {
|
||||
"CurrentText": currentText,
|
||||
"NumRows": numRows,
|
||||
"Versions": versions,
|
||||
"TotalTime": totalTime,
|
||||
})
|
||||
} else {
|
||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||
@ -54,6 +56,7 @@ func editNote(c *gin.Context) {
|
||||
"CurrentText": currentText,
|
||||
"NumRows": numRows,
|
||||
"Versions": versions,
|
||||
"TotalTime": totalTime,
|
||||
"NoEdit": true,
|
||||
})
|
||||
}
|
||||
@ -71,10 +74,10 @@ func everythingElse(c *gin.Context) {
|
||||
if strings.ToLower(title) == "about" {
|
||||
versionNum = -1
|
||||
}
|
||||
currentText, versions, _ := getCurrentText(title, versionNum)
|
||||
renderMarkdown(c, currentText, title, versions, "")
|
||||
currentText, versions, _, totalTime := getCurrentText(title, versionNum)
|
||||
renderMarkdown(c, currentText, title, versions, "", totalTime)
|
||||
} else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 {
|
||||
renderMarkdown(c, listEverything(), "ls", nil, RuntimeArgs.AdminKey)
|
||||
renderMarkdown(c, listEverything(), "ls", nil, RuntimeArgs.AdminKey, time.Now().Sub(time.Now()))
|
||||
} else if option == "/list" {
|
||||
renderList(c, title)
|
||||
} else if title == "static" {
|
||||
@ -93,7 +96,7 @@ func serveStaticFile(c *gin.Context, option string) {
|
||||
}
|
||||
}
|
||||
|
||||
func renderMarkdown(c *gin.Context, currentText string, title string, versions []versionsInfo, AdminKey string) {
|
||||
func renderMarkdown(c *gin.Context, currentText string, title string, versions []versionsInfo, AdminKey string, totalTime time.Duration) {
|
||||
r, _ := regexp.Compile("\\[\\[(.*?)\\]\\]")
|
||||
for _, s := range r.FindAllString(currentText, -1) {
|
||||
currentText = strings.Replace(currentText, s, "["+s[2:len(s)-2]+"](/"+s[2:len(s)-2]+"/view)", 1)
|
||||
@ -125,18 +128,20 @@ func renderMarkdown(c *gin.Context, currentText string, title string, versions [
|
||||
|
||||
if AdminKey == "" {
|
||||
c.HTML(http.StatusOK, "view.tmpl", gin.H{
|
||||
"Title": title,
|
||||
"WikiName": RuntimeArgs.WikiName,
|
||||
"Body": template.HTML([]byte(html2)),
|
||||
"Versions": versions,
|
||||
"Title": title,
|
||||
"WikiName": RuntimeArgs.WikiName,
|
||||
"Body": template.HTML([]byte(html2)),
|
||||
"TotalTime": totalTime.String(),
|
||||
"Versions": versions,
|
||||
})
|
||||
} else {
|
||||
c.HTML(http.StatusOK, "view.tmpl", gin.H{
|
||||
"Title": title,
|
||||
"WikiName": RuntimeArgs.WikiName,
|
||||
"Body": template.HTML([]byte(html2)),
|
||||
"Versions": versions,
|
||||
"AdminKey": AdminKey,
|
||||
"Title": title,
|
||||
"WikiName": RuntimeArgs.WikiName,
|
||||
"Body": template.HTML([]byte(html2)),
|
||||
"Versions": versions,
|
||||
"TotalTime": totalTime.String(),
|
||||
"AdminKey": AdminKey,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
0
static/img/awwkoala.png
Normal file → Executable file
Before Width: | Height: | Size: 1004 B After Width: | Height: | Size: 1004 B |
0
static/img/gomascot.png
Normal file → Executable file
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
0
static/img/nginx.png
Normal file → Executable file
Before Width: | Height: | Size: 659 B After Width: | Height: | Size: 659 B |
0
static/img/raspberrypi.png
Normal file → Executable file
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
@ -62,7 +62,7 @@
|
||||
<li class="dropdown active">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li class="dropdown-header">Previous versions</li>
|
||||
<li class="dropdown-header">Total time: {{ .TotalTime }}</li>
|
||||
<li><a href="/{{ .Title }}?version=0">First</a></li>
|
||||
{{ range .Versions }}
|
||||
<li><a href="/{{ $.Title }}?version={{ .VersionNum }}">{{ .VersionDate }}</a></li>
|
||||
|
@ -36,7 +36,7 @@ a.deleteable {
|
||||
<li class="dropdown active">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active"><span class="glyphicon glyphicon-sunglasses" aria-hidden="true"></span> View <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li class="dropdown-header">Previous versions</li>
|
||||
<li class="dropdown-header">Total time: {{ .TotalTime }}</li>
|
||||
<li><a href="/{{ .Title }}/view?version=0">First</a></li>
|
||||
{{ range .Versions }}
|
||||
<li><a href="/{{ $.Title }}/view?version={{ .VersionNum }}">{{ .VersionDate }}</a></li>
|
||||
|
9
utils.go
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
@ -86,7 +85,7 @@ func timeTrack(start time.Time, name string) {
|
||||
log.Printf("%s took %s", name, elapsed)
|
||||
}
|
||||
|
||||
func getImportantVersions(p WikiData) []versionsInfo {
|
||||
func getImportantVersions(p WikiData) ([]versionsInfo, time.Duration) {
|
||||
// defer timeTrack(time.Now(), "getImportantVersions")
|
||||
m := map[int]int{}
|
||||
lastTime := time.Now().AddDate(0, -1, 0)
|
||||
@ -129,7 +128,7 @@ func getImportantVersions(p WikiData) []versionsInfo {
|
||||
for _, nn := range importantVersions {
|
||||
r = append(r, versionsInfo{p.Timestamps[nn], nn})
|
||||
}
|
||||
return r
|
||||
return r, totalTime
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -138,8 +137,7 @@ func getImportantVersions(p WikiData) []versionsInfo {
|
||||
for _, nn := range importantVersions {
|
||||
r = append(r, versionsInfo{p.Timestamps[nn], nn})
|
||||
}
|
||||
fmt.Println(totalTime)
|
||||
return r
|
||||
return r, totalTime
|
||||
}
|
||||
|
||||
func rebuildTextsToDiffN(p WikiData, n int) string {
|
||||
@ -166,6 +164,7 @@ const (
|
||||
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
|
||||
)
|
||||
|
||||
// RandStringBytesMaskImprSrc prints a random string
|
||||
func RandStringBytesMaskImprSrc(n int) string {
|
||||
b := make([]byte, n)
|
||||
// A src.Int63() generates 63 random bits, enough for letterIdxMax characters!
|
||||
|