Commit 3d66cf1a authored by Ronny Bangsund's avatar Ronny Bangsund

Link improvements.

-Added Title to scraps and links
-Links flow
-Loading scraps gets the hash from the struct just created, rather than the file attempted (for logging to be saner)
-Total count loaded shown after loading the scraps on startup
-Header sends no-cache
parent 9776ca28
......@@ -21,6 +21,7 @@ var scraps = map[string]Scrap{}
type Scrap struct {
Hash string
Title string
Language string
User string
Content string
......@@ -95,6 +96,7 @@ func loadScrap(hash string) Scrap {
var content []byte
content, _ = ioutil.ReadFile("./data/" + s.Language + "/" + s.Hash)
s.Content = fmt.Sprintf("%s", content)
s.Title = s.Hash[:8] + "..."
return s
}
......@@ -113,15 +115,20 @@ func loadScraps() {
if err != nil {
fatal("Error: %s.", err.Error())
}
count := 0
max := 0
for _, fi := range files {
if !fi.IsDir() {
max++
s := loadScrap(fi.Name())
if s.Content != "" {
if !s.hasExpired() {
scraps[s.Hash] = s
info("Scrap %s loaded.", fi.Name())
info("Scrap %s loaded.", s.Hash)
count++
}
}
}
}
info("%d scraps loaded out of %d.", count, max)
}
......@@ -38,9 +38,7 @@
<ul style="display:inline;list-style:none;font-size:18px;">
{{range .Links}}
{{if .Hash}}
<li style="color:green;background-color:#ffa509;width:100%;margin-left:0;padding-left:0;left:0;">
<a href="/{{.Hash}}">{{.User}}</a>
</li>
<li style="color:green;background-color:#ffa509;width:100%;margin-left:0;padding-left:0;left:0;word-wrap:break-word;"><a href="/{{.Hash}}">{{.Title}}</a> by {{.User}}</li>
{{end}}
{{end}}
</ul>
......
......@@ -20,11 +20,12 @@ type IndexPage struct {
}
type ScrapLink struct {
Hash string
User string
Hash string
Title string
User string
}
var indexTemplate, _ = template.ParseFiles("tpl/index.tpl")
var indexTemplate, indexerr = template.ParseFiles("tpl/index.tpl")
var links = []ScrapLink{}
func initWeb() {
......@@ -41,6 +42,7 @@ func endWeb() {
func get_index(ctx *web.Context, arg string) {
ctx.SetHeader("Content-type", "text/html", true)
ctx.SetHeader("Cache-Control", "no-cache", true)
user := "anonymous"
cookie, err := ctx.Request.Cookie("usercookie")
if err == nil {
......@@ -126,7 +128,7 @@ func buildLinks() {
i := 0
links = []ScrapLink{}
for _, v := range scraps {
links = append(links, ScrapLink{v.Hash, v.User})
links = append(links, ScrapLink{v.Hash, v.Title, v.User})
i++
if i > 9 {
break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment