Skip to content

Commit

Permalink
feat: add track page
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jan 27, 2019
1 parent 2aa3738 commit d8bbb75
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 66 deletions.
30 changes: 15 additions & 15 deletions templates/layout/base.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<!-- favicon -->
<link rel="image_src" content="{{ sharing_image_url }}" />
<link rel="shortcut icon" href="/favicon.ico" sizes="32x32">
<link rel="apple-touch-icon" sizes="152x152" href="apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="120x120" href="apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="76x76" href="apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" href="apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" href="/apple-touch-icon-60x60.png">

<!-- REFRESH at least once per hour -->
<meta http-equiv="refresh" content="3600;URL={{ current_url }}" />
Expand Down Expand Up @@ -51,13 +51,13 @@
<meta name="twitter:url" content="{{ current_url }}" />

<!-- FIXME: bundle .css files + minify -->
<link href="components/bootstrap/dist/css/bootstrap.min.css?{{invalid_cache}}" rel="stylesheet" data-no-instant />
<link href="/components/bootstrap/dist/css/bootstrap.min.css?{{invalid_cache}}" rel="stylesheet" data-no-instant />
<link href="/css/calc.css?{{invalid_cache}}" rel="stylesheet" data-no-instant />

<!-- FIXME: bundle .js files + minify -->
<!--[if lt IE 9]>
<script type="text/javascript" src="components/html5shiv/dist/html5shiv.min.js" data-no-instant></script>
<script type="text/javascript" src="components/respond/dest/respond.min.js" data-no-instant></script>
<script type="text/javascript" src="/components/html5shiv/dist/html5shiv.min.js" data-no-instant></script>
<script type="text/javascript" src="/components/respond/dest/respond.min.js" data-no-instant></script>
<![endif]-->

{{ block "extra_css" . }}{{ end }}
Expand Down Expand Up @@ -217,14 +217,14 @@
</div>
</div>
{{ if neige }}<canvas id="neige"></canvas>{{end}}
<script type="text/javascript" src="components/jquery/dist/jquery.min.js" data-no-instant></script>
<script type="text/javascript" src="components/bootstrap/dist/js/bootstrap.min.js" data-no-instant></script>
<script type="text/javascript" src="components/jquery-cookie/jquery.cookie.js" data-no-instant></script>
<script type="text/javascript" src="components/konami-js/konami.js" data-no-instant></script>
<script type="text/javascript" src="components/instantclick/instantclick.js" data-no-instant></script>
<script type="text/javascript" src="js/calc.js" data-no-instant></script>

{{ if neige }}<script type="text/javascript" src="js/snow4.js" data-no-instant></script>{{end}}
<script type="text/javascript" src="/components/jquery/dist/jquery.min.js" data-no-instant></script>
<script type="text/javascript" src="/components/bootstrap/dist/js/bootstrap.min.js" data-no-instant></script>
<script type="text/javascript" src="/components/jquery-cookie/jquery.cookie.js" data-no-instant></script>
<script type="text/javascript" src="/components/konami-js/konami.js" data-no-instant></script>
<script type="text/javascript" src="/components/instantclick/instantclick.js" data-no-instant></script>
<script type="text/javascript" src="/js/calc.js" data-no-instant></script>

{{ if neige }}<script type="text/javascript" src="/js/snow4.js" data-no-instant></script>{{end}}

{{ block "extra_js" . }}{{ end }}
</body>
Expand Down
41 changes: 0 additions & 41 deletions templates/old/track.html

This file was deleted.

45 changes: 45 additions & 0 deletions templates/track.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{define "title"}}{{.track.Title}}{{end}}
{{define "h1"}}Du son {{ mot_cool }}{{end}}
{{define "h1small"}}{{.track.Title}}{{end}}

{{define "content"}}

<!--<pre>{{.track|toPrettyJson}}</pre>-->

<iframe
width="100%"
height="600"
scrolling="no"
frameborder="no"
src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/{{ .track.ID }}&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true">
</iframe>

{{ if .track.Description }}
<pre class="track_description">{{ .track.Description | linkify }}</pre>
{{end}}
{{end}}

{{/*
{% block main_column %}
{% endblock %}

{% block secondary_column %}
<a href="{{ track.ext_url }}" target="_blank">
<img src="{{ track.img | cache_external_assets }}" alt="{{ track.title }}"
class="img-responsive img-rounded rotate-random" />
</a>

<div class="track_date">
{{ track.created_at }}
</div>

{# FIXME: handle tags etc in html headers for SEO #}

<div class="track_tags">
{% for tag in track.tags %}
<span class="label label-primary">#{{ tag }}</span>
{% endfor %}
</div>

{% endblock %}
*/}}
30 changes: 21 additions & 9 deletions views/funcmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ func getFuncmap(opts *Options) *ctxFuncmap {
fm["invalid_cache"] = f.invalidCache
fm["logo_alternate"] = random.AlternateLogo
fm["mot_du_jour"] = random.WOTD
fm["mot_cool"] = random.MotCool
fm["megahertz"] = f.megahertz
fm["mot_debile_qui_se_mange"] = random.MotDebileQuiSeMange
fm["neige"] = func() bool { return false }
fm["cache_external_asset"] = f.cacheExternalAsset
fm["linkify"] = f.linkify
f.fm = fm
return f
}
Expand All @@ -50,6 +52,11 @@ type ctxFuncmap struct {
req *http.Request
}

func (f *ctxFuncmap) linkify(input string) string {
// FIXME: replace URLs with links
return input
}

func (f *ctxFuncmap) devel() bool { return f.opts.Debug }

func (f *ctxFuncmap) sharingImageURL() string {
Expand All @@ -61,16 +68,17 @@ func (f *ctxFuncmap) activePage() string {
}

func (f *ctxFuncmap) activeMenu() string {
switch f.req.URL.Path {
case "/":
switch path := f.req.URL.Path; {
case path == "/":
return "home"
case "/muzik":
// FIXME: support albums, songs
case path == "/muzik" ||
strings.HasPrefix(f.req.URL.Path, "/track/") ||
strings.HasPrefix(f.req.URL.Path, "/album/"):
return "muzik"
case "/copaings":
case path == "/copaings":
return "copaings"
case "/hackz":
// FIXME: support hackz URLs
case path == "/hackz" ||
strings.HasPrefix(f.req.URL.Path, "/hackz"):
return "hackz"
default:
return "home"
Expand Down Expand Up @@ -118,6 +126,10 @@ func (f *ctxFuncmap) cacheExternalAsset(input string) (string, error) {
func (f *ctxFuncmap) resize(opts ...string) string {
path := opts[len(opts)-1]
opts = opts[:len(opts)-1]
urlAppend := ""
if f.opts.Debug {
urlAppend += "?src=" + path
}

var err error
if path, err = f.cacheExternalAsset(path); err != nil {
Expand All @@ -131,7 +143,7 @@ func (f *ctxFuncmap) resize(opts ...string) string {
newpath := fmt.Sprintf("./static/img/cache/%x%s", h, filepath.Ext(path))

if _, err := os.Stat(newpath); !os.IsNotExist(err) {
return strings.Replace(newpath, "./static/", "./", -1)
return strings.Replace(newpath, "./static/", "/", -1) + urlAppend
}

logger := zap.L().With(
Expand Down Expand Up @@ -184,7 +196,7 @@ func (f *ctxFuncmap) resize(opts ...string) string {
logger.Warn("failed to save resized image", zap.Error(err))
return path
}
return strings.Replace(newpath, "./static/", "./", -1)
return strings.Replace(newpath, "./static/", "/", -1) + urlAppend
}

func (f *ctxFuncmap) yomymanStyle() string {
Expand Down
21 changes: 20 additions & 1 deletion views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package views

import (
"net/http"
"strconv"
"sync"

"github.com/gorilla/mux"
Expand All @@ -24,6 +25,7 @@ func Setup(opts *Options) error {
opts.Router.HandleFunc("/muzik", handlers.muzikHandler)
opts.Router.HandleFunc("/hackz", handlers.hackzHandler)
opts.Router.HandleFunc("/copaings", handlers.copaingsHandler)
opts.Router.HandleFunc("/track/{track_id:[0-9]+}", handlers.trackHandler)

//
// old routes (to be imported)
Expand All @@ -44,7 +46,6 @@ func Setup(opts *Options) error {
// /hackz/moijaime
// /hackz/phazms GET/POST
// /album/<int:album_id>
// /track/<int:track_id>
// /scorz/inc/<string:user>/<string:what>/<int:points>
// /sitemap.xml

Expand Down Expand Up @@ -92,6 +93,24 @@ func (h *handlers) muzikHandler(w http.ResponseWriter, r *http.Request) {
h.render(w, r, "muzik.tmpl", data)
}

func (h *handlers) trackHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
trackId, err := strconv.ParseUint(vars["track_id"], 10, 64)
if err != nil {
h.renderError(w, r, err)
return
}
track, err := h.opts.Svc.SoundcloudTrack(r.Context(), &api.SoundcloudTrackInput{
TrackId: trackId,
})
if err != nil {
h.renderError(w, r, err)
return
}
data := renderData{"track": track}
h.render(w, r, "track.tmpl", data)
}

func (h *handlers) copaingsHandler(w http.ResponseWriter, r *http.Request) {
h.setDefaultHeaders(w)
data := renderData{"friends": crew.CALC.Friends}
Expand Down

0 comments on commit d8bbb75

Please sign in to comment.