diff --git a/plugins/factoid.go b/plugins/factoid.go index bdf0cc0..ba99689 100644 --- a/plugins/factoid.go +++ b/plugins/factoid.go @@ -461,8 +461,22 @@ func (p *FactoidPlugin) RegisterWeb() *string { return &tmp } +func linkify(text string) template.HTML { + parts := strings.Split(text, " ") + for i, word := range parts { + if strings.HasPrefix(word, "http") { + parts[i] = fmt.Sprintf("%s", word, word) + } + } + return template.HTML(strings.Join(parts, " ")) +} + func (p *FactoidPlugin) serveQuery(w http.ResponseWriter, r *http.Request) { context := make(map[string]interface{}) + funcMap := template.FuncMap{ + // The name "title" is what the function will be called in the template text. + "linkify": linkify, + } if e := r.FormValue("entry"); e != "" { var entries []Factoid p.Coll.Find(bson.M{"trigger": bson.M{"$regex": e}}).All(&entries) @@ -470,7 +484,7 @@ func (p *FactoidPlugin) serveQuery(w http.ResponseWriter, r *http.Request) { context["Entries"] = entries context["Search"] = e } - t, err := template.New("factoidIndex").Parse(factoidIndex) + t, err := template.New("factoidIndex").Funcs(funcMap).Parse(factoidIndex) if err != nil { log.Println(err) } diff --git a/plugins/webTemplates.go b/plugins/webTemplates.go index 28d43a0..10bd3af 100644 --- a/plugins/webTemplates.go +++ b/plugins/webTemplates.go @@ -76,7 +76,7 @@ var factoidIndex string = ` {{range .Entries}} {{.Trigger}} - {{.FullText}} + {{linkify .FullText}} {{.CreatedBy}} {{.AccessCount}}