You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
775 B

package cv
import (
"html/template"
"log"
"net/url"
"strings"
)
func (g *generator) setupTemplate() error {
tpl := template.New("cv.gohtml")
tpl.Funcs(template.FuncMap{
"prettyUrl": prettyUrl,
"notEmpty": notEmpty,
})
tpl, err := tpl.ParseFiles("templates/cv.gohtml")
if err != nil {
return err
}
g.tpl = tpl
return nil
}
func notEmpty(v interface{}) bool {
switch t := v.(type) {
case string:
return len(t) > 0
case []string:
return len(t) > 0
}
return true
}
func prettyUrl(u string) string {
v, err := url.Parse(u)
if err != nil {
log.Println("Error:", err)
return u
}
if strings.HasPrefix(v.Host, "www.") {
v.Host = strings.TrimPrefix(v.Host, "www.")
}
v.Path = strings.TrimRight(v.Path, "/")
return v.Host + v.Path
}