diff --git a/app/app.yaml b/app/app.yaml index c72cd72..0824bd5 100644 --- a/app/app.yaml +++ b/app/app.yaml @@ -6,7 +6,6 @@ api_version: go1 handlers: - url: /static static_dir: static - application_readable: true - url: /digest/cron script: _go_app login: admin diff --git a/app/config/styles.json b/app/config/styles.json new file mode 100644 index 0000000..32d1a61 --- /dev/null +++ b/app/config/styles.json @@ -0,0 +1,61 @@ +{ + "digest": { + "font-family": "Helvetica, Arial, sans-serif", + "font-size": "10pt", + "color": "#000", + "max-width": "800px", + "margin": "0" + }, + "link": { + "text-decoration": "none", + "color": "#4183c4" + }, + "intro-paragraph": { + "font-size": "12pt", + "user-link": { + "font-weight": "bold", + "color": "#000" + }, + "user-avatar": { + "vertical-align": "bottom", + "padding-right": "3px" + } + }, + "interval-header": { + "font-size": "24pt", + "font-weight": "bold", + "margin": ".75em 0 .5em 0", + "border-bottom": "solid 1px #ddd" + }, + "repository-header": { + "font-size": "18pt", + "font-weight": "bold", + "margin": ".5em 0" + }, + "commit": { + "background": "#fafafa", + "border": "solid 1px #ccc", + "border-radius": "3px", + "margin": "1em 0", + "title": { + "padding": "8px", + "margin": "0" + }, + "message": { + "margin": "0", + "padding": "0 8px 8px" + }, + "footer": { + "background": "#fff", + "border-top": "solid 1px #ddd", + "padding": "8px", + "date": { + "color": "#666" + }, + "link": { + "font-family": "monospace", + "float": "right" + } + } + } +} diff --git a/app/githop.go b/app/githop.go index 96778eb..dc1d23c 100644 --- a/app/githop.go +++ b/app/githop.go @@ -74,6 +74,7 @@ func initGithubOAuthConfig() { } func initTemplates() { + styles := loadStyles() funcMap := template.FuncMap{ "routeUrl": func(name string) (string, error) { url, err := router.Get(name).URL() @@ -82,6 +83,12 @@ func initTemplates() { } return url.String(), nil }, + "style": func(names ...string) (result template.CSS) { + for _, name := range names { + result += styles[name] + } + return + }, } sharedFileNames, err := filepath.Glob("templates/shared/*.html") if err != nil { @@ -111,6 +118,39 @@ func initTemplates() { } } +func loadStyles() (result map[string]template.CSS) { + stylesBytes, err := ioutil.ReadFile("config/styles.json") + if err != nil { + log.Panicf("Could not read styles JSON: %s", err.Error()) + } + var stylesJson interface{} + err = json.Unmarshal(stylesBytes, &stylesJson) + if err != nil { + log.Panicf("Could not parse styles JSON %s: %s", stylesBytes, err.Error()) + } + result = make(map[string]template.CSS) + var parse func(string, map[string]interface{}, *string) + parse = func(path string, stylesJson map[string]interface{}, currentStyle *string) { + if path != "" { + path += "." + } + for k, v := range stylesJson { + switch v.(type) { + case string: + *currentStyle += k + ":" + v.(string) + ";" + case map[string]interface{}: + nestedStyle := "" + parse(path+k, v.(map[string]interface{}), &nestedStyle) + result[path+k] = template.CSS(nestedStyle) + default: + log.Panicf("Unexpected type for %s in styles JSON", k) + } + } + } + parse("", stylesJson.(map[string]interface{}), nil) + return +} + func signInHandler(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, githubOauthConfig.AuthCodeURL(""), http.StatusFound) } @@ -231,7 +271,6 @@ func sendDigestForAccount(account *Account, c appengine.Context) (bool, error) { } var data = map[string]interface{}{ - "Styles": getDigestStyles(), "Digest": digest, } var digestHtml bytes.Buffer @@ -265,14 +304,6 @@ func sendDigestForAccount(account *Account, c appengine.Context) (bool, error) { return true, err } -func getDigestStyles() template.CSS { - b, err := ioutil.ReadFile("static/digest.css") - if err != nil { - log.Panicf("Could not read digest CSS: %s", err.Error()) - } - return template.CSS(string(b[:])) -} - func githubOAuthCallbackHandler(w http.ResponseWriter, r *http.Request) { code := r.FormValue("code") c := appengine.NewContext(r) diff --git a/app/static/digest.css b/app/static/digest.css deleted file mode 100644 index 8c04dbe..0000000 --- a/app/static/digest.css +++ /dev/null @@ -1,83 +0,0 @@ -/* The strange format of these selectors is due to Gmail's limited CSS support --- only tag names may be used. Therefore the entire digest is in a mostly- -harmless
tag so that all selectors may be scoped. For more details, see: -http://codeascraft.com/2014/03/13/responsive-emails-that-really-work/ */ - -dl { - font-family: Helvetica, Arial, sans-serif; - font-size: 10pt; - color: #000; - max-width: 800px; - margin: 0; -} - -dl a { - text-decoration: none; - color: #4183c4; -} - -/* Digest intro paragraph */ -dl > p { - font-size: 12pt; -} - -/* User link */ -dl > p > a { - font-weight: bold; - color: #000; -} - -dl > p > a img { - vertical-align: bottom; - padding-right: 3px; -} - -/* Interval header */ -dl > h1 { - font-size: 24pt; - font-weight: bold; - margin: .75em 0 .5em 0; - border-bottom: solid 1px #ddd; -} - -/* Repository header */ -dl > h2 { - font-size: 18pt; - font-weight: bold; - margin: .5em 0; -} - -/* Commit */ -dl > div > div { - background: #fafafa; - border: solid 1px #ccc; - border-radius: 3px; - margin: 1em 0; -} - -/* Commit message */ -dl > div > div > h3 { - padding: 8px; - margin: 0; -} - -dl > div > div > pre { - margin: 0; - padding: 0 8px 8px; -} - -/* Commit footer */ -dl > div > div > div { - background: #fff; - border-top: solid 1px #ddd; - padding: 8px; -} - -dl > div > div > div > i { - color: #666; -} - -dl > div > div > div > a { - font-family: monospace; - float: right; -} diff --git a/app/templates/base/page.html b/app/templates/base/page.html index 05ff2d9..b6a32f0 100644 --- a/app/templates/base/page.html +++ b/app/templates/base/page.html @@ -4,7 +4,6 @@ {{template "title" .}} -

{{template "title" .}}

diff --git a/app/templates/digest-email.html b/app/templates/digest-email.html index 4dae7d1..cf405f9 100644 --- a/app/templates/digest-email.html +++ b/app/templates/digest-email.html @@ -1,8 +1 @@ - - - - - - {{template "digest" .Digest}} - - +{{template "digest" .Digest}} diff --git a/app/templates/shared/digest.html b/app/templates/shared/digest.html index 3be415b..81bd270 100644 --- a/app/templates/shared/digest.html +++ b/app/templates/shared/digest.html @@ -1,29 +1,42 @@ {{define "digest"}} -
+
-

GitHub activity time machine for {{.User.Login}}.

+

+ GitHub activity time machine for + + {{.User.Login}} + . +

{{range .IntervalDigests }} -

{{.Header}}

+

{{.Header}}

{{.Description}}

{{range .RepoDigests}} -

- {{.Repo.FullName}} +

+ {{.Repo.FullName}}

{{range .Commits }} -
-

{{.Title}}

+
+

{{.Title}}

{{if .Message}} -
{{.Message}}
+
{{.Message}}
{{end}} -
- {{.DisplaySHA}} - {{.DisplayDate}} +
+ {{.DisplaySHA}} + {{.DisplayDate}}
{{end}} @@ -32,6 +45,6 @@ {{end}} -
+ {{end}}