1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Added tables

Former-commit-id: 24a1bdaa1d3170e05d79673d21af87f4b29d9334 [formerly a24894fef63128336e479858867e08d06dc1b263] [formerly 91e9f3826c5503f6f9474d09b6a76b39e95c91b4 [formerly 341fa07b9414be0e61efa2aa0b1216d70ed5e579 [formerly 825139b9a1]]]
Former-commit-id: f1cacfbae235471096b9e7d9f57d3ca39099536b [formerly 9ca1e6b879cebf82e66be0577afd688250577821]
Former-commit-id: be91c9328fdd33bc365da81e2d39bea68021792b
Former-commit-id: ae2ec1a113
This commit is contained in:
Zack Scholl 2016-02-09 16:59:30 -05:00
parent 4c9ce382fb
commit 33ce555d57

View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"html/template"
"io/ioutil"
"net/http"
@ -55,7 +56,7 @@ func everythingElse(c *gin.Context) {
panic(err)
}
renderMarkdown(c, p.CurrentText, title)
} else if option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 {
} else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 {
renderMarkdown(c, listEverything(), "Everything")
} else if option == "/list" {
renderList(c, title)
@ -76,7 +77,9 @@ func serveStaticFile(c *gin.Context, option string) {
}
func renderMarkdown(c *gin.Context, currentText string, title string) {
fmt.Println(currentText)
unsafe := blackfriday.MarkdownCommon([]byte(currentText))
fmt.Println(string(unsafe))
pClean := bluemonday.UGCPolicy()
pClean.AllowElements("img")
pClean.AllowAttrs("alt").OnElements("img")
@ -197,14 +200,21 @@ func deleteListItem(c *gin.Context) {
}
func listEverything() string {
everything := ""
everything := `| Title | Current size | Changes | Total Size |
| --------- |-------------| -----| ------------- |
`
db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys
b := tx.Bucket([]byte("datas"))
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
if len(v) > 1 {
everything += "- [" + string(k) + "](/" + string(k) + "/view) (" + strconv.Itoa(len(v)) + ")\n"
var p CowyoData
p.load(string(k))
if len(p.CurrentText) > 1 {
contentSize := strconv.Itoa(len(p.CurrentText))
numChanges := strconv.Itoa(len(p.Diffs))
totalSize := strconv.Itoa(len(v))
everything += "| [" + p.Title + "](/" + p.Title + "/view) | " + contentSize + " | " + numChanges + " | " + totalSize + "|\n"
}
}
return nil