clean up news display

This commit is contained in:
Dan Ballard 2015-08-30 20:23:35 -07:00
parent a4abe1424a
commit 470b011ded
3 changed files with 28 additions and 10 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects) # Compiled Object files, Static and Dynamic libs (Shared Objects)
transmet transmet
db/dbconf.yml db/dbconf.yml
.Rhistory
.project .project
*~ *~
*.o *.o

View File

@ -44,7 +44,7 @@ func stringTimes(times int, str string) string {
// Turns a Time into a formated string // Turns a Time into a formated string
func dateFormat(t time.Time) string { func dateFormat(t time.Time) string {
return t.Format(time.ANSIC) return t.Format("2006.01.02 15:04:05")
} }
// takes a category_id and returns "Root / Parent / Category" // takes a category_id and returns "Root / Parent / Category"
@ -56,6 +56,14 @@ func fullCategoryPath(categoriesFlat map[int]*categories.Category, category_id i
return strings.Join(categoryNames, " / ") return strings.Join(categoryNames, " / ")
} }
// truncate a string
func truncate(str string, maxLen int) string {
if len(str) <= maxLen {
return str
}
return str[0:maxLen] + "..."
}
// Tempalte helper functions // Tempalte helper functions
var funcMap = template.FuncMap { var funcMap = template.FuncMap {
"add": func (x, y int) int { return x + y }, "add": func (x, y int) int { return x + y },
@ -64,6 +72,7 @@ var funcMap = template.FuncMap {
"stringTimes": stringTimes, "stringTimes": stringTimes,
"dateFormat": dateFormat, "dateFormat": dateFormat,
"fullCategoryPath": fullCategoryPath, "fullCategoryPath": fullCategoryPath,
"truncate": truncate,
} }

View File

@ -13,19 +13,27 @@
{{define "row-news"}} {{define "row-news"}}
<div class="news-row"> <div class="news-row">
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-2">
<h3>{{.post.Title}}</h3> {{fullCategoryPath .categories .post.Category_id}}
</div> </div>
<div class="col-xs-12"> <div class="col-xs-8">
<strong>{{truncate .post.Title 100}}</strong>
</div>
<div class="col-xs-2">
{{dateFormat .post.Date}} {{dateFormat .post.Date}}
</div> </div>
<div class="col-xs-12"> </div>
<a href="{{.post.Url}}">{{.post.Url}}</a> <div class="row">
</div> <div class="col-xs-2">&nbsp;</div>
<div class="col-xs-12"> <div class="col-xs-8">
Category: {{fullCategoryPath .categories .post.Category_id}} <a href="{{.post.Url}}">{{truncate .post.Url 100}}</a>
</div> </div>
<div class="col-xs-2">&nbsp;</div>
</div>
<div class="row">
<div class="col-xs-2">&nbsp;</div>
<div class="col-xs-8">{{truncate .post.Notes 500}}</div>
<div class="col-xs-2">&nbsp;</div>
</div> </div>
<div>{{.post.Notes}}</div>
</div> </div>
{{end}} {{end}}