From 66b697a51345bfed8cc472cb894a6edc7845397f Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 10:05:54 +0800 Subject: [PATCH] add ShortSha template func --- modules/base/template.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/base/template.go b/modules/base/template.go index dca76fafdc..dfcae93147 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -33,6 +33,13 @@ func List(l *list.List) chan interface{} { return c } +func ShortSha(sha1 string) string { + if len(sha1) == 40 { + return sha1[:10] + } + return sha1 +} + var mailDomains = map[string]string{ "gmail.com": "gmail.com", } @@ -72,4 +79,5 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ }, "DiffTypeToStr": DiffTypeToStr, "DiffLineTypeToStr": DiffLineTypeToStr, + "ShortSha": ShortSha, }