Skip to content

Commit

Permalink
feat: add more info in /open, add prettyDate helper, add anti-cache a…
Browse files Browse the repository at this point in the history
…ssets suffix
  • Loading branch information
moul committed Jul 12, 2020
1 parent b263f78 commit 2d6c2f4
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/sgtm/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (svc *Service) Ping(context.Context, *sgtmpb.Ping_Request) (*sgtmpb.Ping_Re
func (svc *Service) Status(context.Context, *sgtmpb.Status_Request) (*sgtmpb.Status_Response, error) {
hostname, _ := os.Hostname()
return &sgtmpb.Status_Response{
Uptime: int32(time.Since(svc.startedAt).Seconds()),
Uptime: int32(time.Since(svc.StartedAt).Seconds()),
Hostname: hostname,
}, nil
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/sgtm/http_pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func (svc *Service) newTemplateData(r *http.Request) (*templateData, error) {
Opts: svc.opts.Filtered(),
Lang: "en", // FIXME: dynamic
Request: r,
Service: svc,
}
if svc.opts.DevMode {
data.Title += " (dev)"
Expand Down Expand Up @@ -459,6 +460,9 @@ func loadTemplate(box *packr.Box, filepath string) *template.Template {
funcmap["prettyDuration"] = func(input time.Duration) string {
return durafmt.Parse(input).LimitFirstN(2).String()
}
funcmap["prettyDate"] = func(input time.Time) string {
return input.Format("2006-01-02 15:04")
}
tmpl, err := template.New("tmpl").Funcs(funcmap).Parse(allInOne)
if err != nil {
panic(err)
Expand All @@ -478,6 +482,7 @@ type templateData struct {
Lang string
User *sgtmpb.User
Error string
Service *Service `json:"-"`
Request *http.Request `json:"-"`

// specific
Expand Down
4 changes: 2 additions & 2 deletions pkg/sgtm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Service struct {
opts Opts
ctx context.Context
cancel func()
startedAt time.Time
StartedAt time.Time

/// drivers

Expand All @@ -37,7 +37,7 @@ func New(db *gorm.DB, opts Opts) (Service, error) {
opts: opts,
ctx: ctx,
cancel: cancel,
startedAt: time.Now(),
StartedAt: time.Now(),
}
svc.logger.Info("service initialized", zap.Bool("dev-mode", opts.DevMode))
return svc, nil
Expand Down
8 changes: 4 additions & 4 deletions static/_layouts/base.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" />
<link rel="stylesheet" href="/_assets/css/style.css" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="/_assets/css/style.css?t={{.Service.StartedAt | unixEpoch}}" />
<title>{{.Title}}</title>
<!--<meta name="description" content="">-->
<meta name="author" content="Manfred Touron">
Expand Down Expand Up @@ -33,7 +33,7 @@
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous" defer></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js" integrity="sha384-1CmrxMRARb6aLqgBO7yyAxTOQE2AKb9GfXnEo760AUcUmFx3ibVJJAzGytlQcNXd" crossorigin="anonymous" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/turbolinks/5.2.0/turbolinks.js" integrity="sha512-G3jAqT2eM4MMkLMyQR5YBhvN5/Da3IG6kqgYqU9zlIH4+2a+GuMdLb5Kpxy6ItMdCfgaKlo2XFhI0dHtMJjoRw==" crossorigin="anonymous" defer></script>
<script src="/_assets/js/script.js" defer></script>
<script src="/_assets/js/script.js?t={{.Service.StartedAt | unixEpoch}}" defer></script>
</head>
<body>

Expand Down Expand Up @@ -89,7 +89,7 @@ <h4 class="text-white">@{{.User.Slug}}</h4>
</li>
<li class="nav-item ml-2">
<!-- FIXME: open join modal -->
<a class="btn btn-primary" href="/join">Join SGTM</a>
<a class="btn btn-primary disabled" href="/join">Sign up (coming soon)</a>
</li>
</ul>
{{end}}
Expand Down
1 change: 0 additions & 1 deletion static/_layouts/home.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ <h2>🎶 Last Tracks</h2>
{{with .Genre}}<div>📁 Genre: <span class="badge badge-secondary">{{.}}</span></div>{{end}}
{{if .Duration}}<div>⏱ Duration: <span data-toggle="tooltip" data-placement="right" title="{{.GoDuration}}">{{.GoDuration | prettyDuration}}</span></div>{{end}}
{{with .DownloadURL}}<div><a href="{{.}}" class="btn">⬇️ Download</a></div>{{end}}
<!--<div>📆 Added: {{.CreatedAt | fromUnixNano | date "2006-01-02"}}</div>-->
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions static/_layouts/open.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<li>Users: {{.Open.Users}}</li>
<li>Tracks: {{.Open.Tracks}}</li>
<li>Track drafts: {{.Open.TrackDrafts}}</li>
<li>Uptime: <span data-toggle="tooltip" data-placement="right" title="{{.Service.StartedAt | prettyDate}}">{{.Service.StartedAt | prettyAgo}}</span></li>
</ul>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion static/_layouts/post.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>{{.Post.Post.Title}}</h1>
{{with .Post.Post.Genre}}<div>📁 Genre: <span class="badge badge-secondary">{{.}}</span></div>{{end}}
{{if .Post.Post.Duration}}<div>⏱ Duration: <span data-toggle="tooltip" data-placement="right" title="{{.Post.Post.GoDuration}}">{{.Post.Post.GoDuration | prettyDuration}}</span></div>{{end}}
{{with .Post.Post.DownloadURL}}<div><a href="{{.}}" class="btn">⬇️ Download</a></div>{{end}}
<div>📆 Added <span data-toggle="tooltip" data-placement="right" title="{{.Post.Post.SortDate | fromUnixNano | date "2006-01-02 15:04"}}">{{.Post.Post.SortDate | fromUnixNano | prettyAgo}}</span></div>
<div>📆 Added <span data-toggle="tooltip" data-placement="right" title="{{.Post.Post.SortDate | fromUnixNano | prettyDate}}">{{.Post.Post.SortDate | fromUnixNano | prettyAgo}}</span></div>
</div>
</div>
</div>
Expand Down
5 changes: 1 addition & 4 deletions static/_layouts/profile.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ <h2>🎶 Last Tracks</h2>
{{with .Genre}}<div>📁 Genre: <span class="badge badge-secondary">{{.}}</span></div>{{end}}
{{if .Duration}}<div>⏱ Duration: <span data-toggle="tooltip" data-placement="right" title="{{.GoDuration}}">{{.GoDuration | prettyDuration}}</span></div>{{end}}
{{with .DownloadURL}}<div><a href="{{.}}" class="btn">⬇️ Download</a></div>{{end}}
<!--<div>📆 Added: {{.CreatedAt | fromUnixNano | date "2006-01-02"}}</div>-->
</div>
</div>
</div>
Expand All @@ -35,9 +34,7 @@ <h2>🎶 Last Tracks</h2>
<div class="col-md-4">
<h1>{{.Profile.User.DisplayName}}</h1>
<div><img src="{{.Profile.User.Avatar}}" class="mb-3" /></div>
<!--<div>📆 Joined: {{.Profile.User.CreatedAt | fromUnixNano | date "2006-01-02"}}</div>-->
<div>📆 Joined <span data-toggle="tooltip" data-placement="top" title="{{.Profile.User.CreatedAt | fromUnixNano | date "2006-01-02 15:04"}}">{{.Profile.User.CreatedAt | fromUnixNano | prettyAgo}}</span></div>
<!--<div>🗣 Language: {{.Profile.User.Locale}}</div>-->
<div>📆 Joined <span data-toggle="tooltip" data-placement="top" title="{{.Profile.User.CreatedAt | fromUnixNano | prettyDate}}">{{.Profile.User.CreatedAt | fromUnixNano | prettyAgo}}</span></div>
<div>🎶 {{.Profile.Stats.Tracks}} tracks</div>
</div>
</div>
Expand Down

0 comments on commit 2d6c2f4

Please sign in to comment.