From ae2ec1a113674b2378d60a5f79018ab5e470e228 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 9 Feb 2016 16:59:30 -0500 Subject: [PATCH] Added tables Former-commit-id: 24a1bdaa1d3170e05d79673d21af87f4b29d9334 [formerly a24894fef63128336e479858867e08d06dc1b263] [formerly 91e9f3826c5503f6f9474d09b6a76b39e95c91b4 [formerly 825139b9a1cb3cf61b4c94caf8c12cf2a21ae5d0]] Former-commit-id: f1cacfbae235471096b9e7d9f57d3ca39099536b [formerly 9ca1e6b879cebf82e66be0577afd688250577821] Former-commit-id: be91c9328fdd33bc365da81e2d39bea68021792b --- routes.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/routes.go b/routes.go index 9da27d1..8ff1e9d 100644 --- a/routes.go +++ b/routes.go @@ -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