finish title pull
This commit is contained in:
parent
43000b45f2
commit
c5ba1b3041
|
@ -9,6 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFlashes(session *sessions.Session) map[string]interface{} {
|
func GetFlashes(session *sessions.Session) map[string]interface{} {
|
||||||
|
@ -102,6 +103,10 @@ func LoginPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// ?url=
|
// ?url=
|
||||||
func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
var url = r.URL.Query().Get("url")
|
var url = r.URL.Query().Get("url")
|
||||||
|
reHttp := regexp.MustCompile("^http://")
|
||||||
|
if ! reHttp.Match([]byte(url)) {
|
||||||
|
url = "http://" + url
|
||||||
|
}
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error looking up link", url, ":", err)
|
fmt.Println("Error looking up link", url, ":", err)
|
||||||
|
@ -112,7 +117,10 @@ func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
} else {
|
} else {
|
||||||
re := regexp.MustCompile("< *[Tt][Ii][Tt][Ll][Ee] *>(.*)</ *[Tt][Ii][Tt][Ll][Ee] *>")
|
re := regexp.MustCompile("< *[Tt][Ii][Tt][Ll][Ee] *>(.*)</ *[Tt][Ii][Tt][Ll][Ee] *>")
|
||||||
title := re.FindStringSubmatch(string(body))
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<form class="form-add" action="/add" method="post" role="form" class="container col-form">
|
<form class="form-add" action="/add" method="post" role="form" class="container col-form">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-2">Link:</div><div class="col-xs-10"><input type="text" class="form-control" name="link" placeholder="Link" value="{{.link}}"/></div>
|
<div class="col-xs-2">Link:</div><div class="col-xs-10"><input type="text" class="form-control" name="link" placeholder="Link" value="{{.link}}"/></div>
|
||||||
<div class="col-xs-2">Title:</div><div class="col-xs-10"><input type="text" class="form-control" name="title" placeholder="Title"/></div>
|
<div class="col-xs-2">Title:</div><div class="col-xs-10"><input type="text" class="form-control" name="title" placeholder="Title" value="{{.title}}"/></div>
|
||||||
<div class="col-xs-2">Path:</div><div class="col-xs-10"><input type="text" class="form-control" name="path" placeholder="Path"/></div>
|
<div class="col-xs-2">Path:</div><div class="col-xs-10"><input type="text" class="form-control" name="path" placeholder="Path"/></div>
|
||||||
<div class="col-xs-2">Description:</div><div class="col-xs-10"><textarea class="form-control" name="description" placeholder="Description" rows="3" cols="80">{{.task.Description}}</textarea></div>
|
<div class="col-xs-2">Description:</div><div class="col-xs-10"><textarea class="form-control" name="description" placeholder="Description" rows="3" cols="80">{{.task.Description}}</textarea></div>
|
||||||
<div class="col-xs-2"></div><div class="col-xs-10"><input class="btn btn-lg btn-primary btn-block" type="submit" value="Add Link" /></div>
|
<div class="col-xs-2"></div><div class="col-xs-10"><input class="btn btn-lg btn-primary btn-block" type="submit" value="Add Link" /></div>
|
||||||
|
|
Loading…
Reference in New Issue