From c5ba1b304188393611916d6cf4904ad6055cf20c Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Tue, 5 May 2015 07:09:10 -0700 Subject: [PATCH] finish title pull --- route_handlers.go | 10 +++++++++- templates/pages/add.html | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/route_handlers.go b/route_handlers.go index 59ddc92..a2b163c 100644 --- a/route_handlers.go +++ b/route_handlers.go @@ -9,6 +9,7 @@ import ( "time" "io/ioutil" "regexp" + "strings" ) func GetFlashes(session *sessions.Session) map[string]interface{} { @@ -102,6 +103,10 @@ func LoginPostHandler(w http.ResponseWriter, r *http.Request) { // ?url= func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) { var url = r.URL.Query().Get("url") + reHttp := regexp.MustCompile("^http://") + if ! reHttp.Match([]byte(url)) { + url = "http://" + url + } resp, err := http.Get(url) if err != nil { fmt.Println("Error looking up link", url, ":", err) @@ -112,7 +117,10 @@ func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) { } else { re := regexp.MustCompile("< *[Tt][Ii][Tt][Ll][Ee] *>(.*)") title := re.FindStringSubmatch(string(body)) - fmt.Println(title) + if title != nil { + ShowTemplate("add", w, map[string]interface{}{"user": user, "link": url, "title": strings.TrimSpace(title[1])}) + return + } } } diff --git a/templates/pages/add.html b/templates/pages/add.html index b999f4a..e98f6b5 100644 --- a/templates/pages/add.html +++ b/templates/pages/add.html @@ -4,7 +4,7 @@
Link:
-
Title:
+
Title:
Path:
Description: