diff --git a/app.go b/app.go index f6c3467..3fdfc66 100644 --- a/app.go +++ b/app.go @@ -61,6 +61,7 @@ func (app *app) initRouter() { app.router.HandleFunc("/edit/{house:[A-Za-z0-9.-]{8}}.html", app.handler(getEditor)).Methods("GET").Name("edit") app.router.HandleFunc("/stats/{house:[A-Za-z0-9.-]{8}}.html", app.handler(viewHouseStats)).Methods("GET").Name("stats") app.router.HandleFunc("/{house:[A-Za-z0-9.-]{8}}.html", app.handler(getHouse)).Methods("GET").Name("get") + app.router.HandleFunc("/browse", app.handler(viewHouses)).Methods("GET").Name("browse") app.router.PathPrefix("/").Handler(http.FileServer(http.Dir(app.cfg.StaticDir))) } diff --git a/construction.go b/construction.go index e44262a..29c3f32 100644 --- a/construction.go +++ b/construction.go @@ -187,3 +187,36 @@ func viewHouseStats(app *app, w http.ResponseWriter, r *http.Request) error { return nil } + +func viewHouses(app *app, w http.ResponseWriter, r *http.Request) error { + houses, err := getPublicHouses(app) + if err != nil { + fmt.Fprintf(w, ":(") + return err + } + + app.templates["browse"].ExecuteTemplate(w, "browse", struct{ Houses *[]PublicHouse }{houses}) + + return nil +} + +func getPublicHouses(app *app) (*[]PublicHouse, error) { + houses := []PublicHouse{} + rows, err := app.db.Query("SELECT house_id, title, thumb_url FROM publichouses WHERE approved = 1 ORDER BY updated DESC LIMIT 10") + switch { + case err == sql.ErrNoRows: + return nil, impart.HTTPError{http.StatusNotFound, "Return to sender. Address unknown."} + case err != nil: + fmt.Printf("Couldn't fetch: %v\n", err) + return nil, err + } + defer rows.Close() + + house := &PublicHouse{} + for rows.Next() { + err = rows.Scan(&house.ID, &house.Title, &house.ThumbURL) + houses = append(houses, *house) + } + + return &houses, nil +} diff --git a/models.go b/models.go index f5ac466..2a49fd9 100644 --- a/models.go +++ b/models.go @@ -1,6 +1,12 @@ package htmlhouse type ( + PublicHouse struct { + ID string + Title string + ThumbURL string + } + HouseStats struct { ID string Stats []Stat diff --git a/static/404.html b/static/404.html index f63a637..9f3eae2 100644 --- a/static/404.html +++ b/static/404.html @@ -17,6 +17,7 @@

HTMLlot

diff --git a/static/about.html b/static/about.html index 72d8933..39e4328 100644 --- a/static/about.html +++ b/static/about.html @@ -31,6 +31,7 @@

HTMLhouse

diff --git a/static/css/core.less b/static/css/core.less index 885a137..f599a4e 100644 --- a/static/css/core.less +++ b/static/css/core.less @@ -159,6 +159,31 @@ body { } } +.open-house { + display: inline; + margin: 2em; + float: left; + + img { + border: 1px solid #ccc; + display: block; + max-width: 320px; + max-height: 240px; + .opacity(.6); + .transition-duration(0.3s); + } + a:hover img { + .opacity(1); + } + + .house-name { + margin-top: 1em; + font-size: 1.4em; + text-align: center; + display: block; + } +} + #editor, #preview-wrap { position: absolute; top: 5em; diff --git a/static/houses.html b/static/houses.html index ed68c72..55769cb 100644 --- a/static/houses.html +++ b/static/houses.html @@ -31,6 +31,7 @@

my pages

diff --git a/templates.go b/templates.go index 42cdcfc..0f70554 100644 --- a/templates.go +++ b/templates.go @@ -21,4 +21,5 @@ func (app *app) initTemplates() { // Initialize dynamic pages initTemplate(app, "editor") initTemplate(app, "stats") + initTemplate(app, "browse") } diff --git a/templates/browse.html b/templates/browse.html new file mode 100644 index 0000000..f3d3436 --- /dev/null +++ b/templates/browse.html @@ -0,0 +1,55 @@ +{{define "browse"}} + + + + Browse HTMLhouses + + + + + + + + + + + + + + + + + + + + + + + + +
+

Browse

+ +
+ + {{ range .Houses }}
+ +
{{.Title}}
+
{{end}} + + + +{{end}} diff --git a/templates/editor.html b/templates/editor.html index 079ed94..fdc71bb 100644 --- a/templates/editor.html +++ b/templates/editor.html @@ -31,6 +31,7 @@

HTMLhouse

diff --git a/templates/stats.html b/templates/stats.html index 2972c27..edc5257 100644 --- a/templates/stats.html +++ b/templates/stats.html @@ -31,6 +31,7 @@

{{.ID}}.html stats