mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Improve history UI and non-history route speed
This commit is contained in:
parent
f45b4f86ca
commit
30f3956568
39
handlers.go
39
handlers.go
@ -108,10 +108,20 @@ func handlePageRequest(c *gin.Context) {
|
|||||||
rawHTML = GithubMarkdownToHTML(rawText)
|
rawHTML = GithubMarkdownToHTML(rawText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
versionsInt64 := p.Text.GetMajorSnapshots(60) // get snapshots 60 seconds apart
|
|
||||||
versionsText := make([]string, len(versionsInt64))
|
// Get history
|
||||||
for i, v := range versionsInt64 {
|
var versionsInt64 []int64
|
||||||
versionsText[i] = time.Unix(v/1000000000, 0).String()
|
var versionsChangeSums []int
|
||||||
|
var versionsText []string
|
||||||
|
if command[0:2] == "/h" {
|
||||||
|
versionsInt64, versionsChangeSums = p.Text.GetMajorSnapshotsAndChangeSums(1) // get snapshots 60 seconds apart
|
||||||
|
versionsText = make([]string, len(versionsInt64))
|
||||||
|
for i, v := range versionsInt64 {
|
||||||
|
versionsText[i] = time.Unix(v/1000000000, 0).Format("Mon Jan 2 15:04:05 MST 2006")
|
||||||
|
}
|
||||||
|
versionsText = reverseSliceString(versionsText)
|
||||||
|
versionsInt64 = reverseSliceInt64(versionsInt64)
|
||||||
|
versionsChangeSums = reverseSliceInt(versionsChangeSums)
|
||||||
}
|
}
|
||||||
|
|
||||||
if command[0:2] == "/r" {
|
if command[0:2] == "/r" {
|
||||||
@ -139,16 +149,17 @@ func handlePageRequest(c *gin.Context) {
|
|||||||
command[0:2] != "/v" &&
|
command[0:2] != "/v" &&
|
||||||
command[0:2] != "/l" &&
|
command[0:2] != "/l" &&
|
||||||
command[0:2] != "/h",
|
command[0:2] != "/h",
|
||||||
"Page": page,
|
"Page": page,
|
||||||
"RenderedPage": template.HTML([]byte(rawHTML)),
|
"RenderedPage": template.HTML([]byte(rawHTML)),
|
||||||
"RawPage": rawText,
|
"RawPage": rawText,
|
||||||
"Versions": versionsInt64,
|
"Versions": versionsInt64,
|
||||||
"VersionsText": versionsText,
|
"VersionsText": versionsText,
|
||||||
"IsLocked": p.IsLocked,
|
"VersionsChangeSums": versionsChangeSums,
|
||||||
"IsEncrypted": p.IsEncrypted,
|
"IsLocked": p.IsLocked,
|
||||||
"ListItems": renderList(rawText),
|
"IsEncrypted": p.IsEncrypted,
|
||||||
"Route": "/" + page + command,
|
"ListItems": renderList(rawText),
|
||||||
"HasDotInName": strings.Contains(page, "."),
|
"Route": "/" + page + command,
|
||||||
|
"HasDotInName": strings.Contains(page, "."),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,9 +438,12 @@
|
|||||||
{{ if .ViewPage }} {{ .RenderedPage }} {{ end }}
|
{{ if .ViewPage }} {{ .RenderedPage }} {{ end }}
|
||||||
{{ if .EditPage }} <textarea autofocus placeholder="Start typing, it will save automatically." id="userInput">{{ .RawPage }}</textarea>{{ end }}
|
{{ if .EditPage }} <textarea autofocus placeholder="Start typing, it will save automatically." id="userInput">{{ .RawPage }}</textarea>{{ end }}
|
||||||
{{ if .HistoryPage }}
|
{{ if .HistoryPage }}
|
||||||
|
<h1>History</h1>
|
||||||
<ul>
|
<ul>
|
||||||
{{range $i, $e := .Versions}}
|
{{range $i, $e := .Versions}}
|
||||||
<li>Version {{index $.VersionsText $i}} <a href="/{{ $.Page }}/view?version={{$e}}">View</a> <a href="/{{ $.Page }}/list?version={{$e}}">List</a> <a href="/{{ $.Page }}/raw?version={{$e}}">Raw</a></li>
|
<li style="list-style: none;">
|
||||||
|
<a href="/{{ $.Page }}/view?version={{$e}}">View</a> <a href="/{{ $.Page }}/list?version={{$e}}">List</a> <a href="/{{ $.Page }}/raw?version={{$e}}">Raw</a>
|
||||||
|
{{index $.VersionsText $i}} ({{if lt (index $.VersionsChangeSums $i) 0}}<span style="color:red">{{else}}<span style="color:green">+{{end}}{{index $.VersionsChangeSums $i}}</span>)</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
8
utils.go
8
utils.go
@ -254,9 +254,17 @@ func reverseSliceInt64(s []int64) []int64 {
|
|||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func reverseSliceString(s []string) []string {
|
func reverseSliceString(s []string) []string {
|
||||||
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||||
s[i], s[j] = s[j], s[i]
|
s[i], s[j] = s[j], s[i]
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reverseSliceInt(s []int) []int {
|
||||||
|
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||||
|
s[i], s[j] = s[j], s[i]
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user