Skip to content

Commit

Permalink
Make thumbnails host configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
thebaer committed Jan 20, 2018
1 parent c001ce6 commit d924964
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ DB_USER=dbuser DB_PASSWORD=pass DB_DB=htmlhouse PRIVATE_KEY=keys/dev PUBLIC_KEY=
| `PORT` | Port to run app on | `8080` |
| `STATIC_DIR` | Relative dir where static files are stored | `static` |
| `AUTO_APPROVE` | Automatically approves public posts | false |
| `PREVIEWS_HOST` | Fully-qualified URL (without trailing slash) of screenshot server | None. |
| `TWITTER_KEY` | Twitter consumer key | `notreal` |
| `TWITTER_SECRET` | Twitter consumer secret | `notreal` |
| `TWITTER_TOKEN` | Twitter access token of the posting Twitter account | `notreal` |
Expand Down
7 changes: 4 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ type config struct {
HostName string `env:"key=HOST default=https://html.house"`
ServerPort int `env:"key=PORT default=8080"`

AutoApprove bool `env:"key=AUTO_APPROVE default=false"`
AdminPass string `env:"key=ADMIN_PASS default=uhoh"`
BrowseItems int `env:"key=BROWSE_ITEMS default=10"`
AutoApprove bool `env:"key=AUTO_APPROVE default=false"`
PreviewsHost string `env:"key=PREVIEWS_HOST`
AdminPass string `env:"key=ADMIN_PASS default=uhoh"`
BrowseItems int `env:"key=BROWSE_ITEMS default=10"`

// Twitter configuration
TwitterConsumerKey string `env:"key=TWITTER_KEY default=notreal"`
Expand Down
2 changes: 1 addition & 1 deletion construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func addPublicAccess(app *app, houseID, html string) error {
data := url.Values{}
data.Set("url", fmt.Sprintf("%s/%s.html", app.cfg.HostName, houseID))

u, err := url.ParseRequestURI("https://peeper.html.house")
u, err := url.ParseRequestURI(app.cfg.PreviewsHost)
u.Path = "/"
urlStr := fmt.Sprintf("%v", u)

Expand Down
17 changes: 9 additions & 8 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (

type (
PublicHouse struct {
ID string `json:"id"`
Title string `json:"title"`
URL string `json:"url"`
ThumbURL string `json:"thumb_url"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Views int `json:"views"`
ID string `json:"id"`
Title string `json:"title"`
URL string `json:"url"`
thumbHost string `json:"-"`
ThumbURL string `json:"thumb_url"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Views int `json:"views"`
}

HouseStats struct {
Expand All @@ -30,6 +31,6 @@ type (
func (h *PublicHouse) process(app *app) {
h.URL = fmt.Sprintf("%s/%s.html", app.cfg.HostName, h.ID)
if h.ThumbURL != "" {
h.ThumbURL = "https://peeper.html.house/" + h.ThumbURL
h.ThumbURL = fmt.Sprintf("%s/%s", app.cfg.PreviewsHost, h.ThumbURL)
}
}
2 changes: 1 addition & 1 deletion templates/browse.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h1>Browse HTMLhouse</h1>
</header>

{{ range .Houses }}<div class="open-house">
<a href="/{{.ID}}.html"><img src="https://peeper.html.house/{{.ThumbURL}}" />
<a href="/{{.ID}}.html"><img src="{{.thumbHost}}/{{.ThumbURL}}" />
<div class="house-name">{{.Title}}</div></a>
</div>{{end}}

Expand Down

0 comments on commit d924964

Please sign in to comment.