diff --git a/pkg/random/random.go b/pkg/random/random.go index 076c5b5b..aead9330 100644 --- a/pkg/random/random.go +++ b/pkg/random/random.go @@ -4,8 +4,21 @@ import ( "fmt" "math/rand" "time" + "unicode" ) +func randomCaps(input string) string { + output := []rune{} + for _, c := range input { + if rand.Intn(2) == 0 { + output = append(output, unicode.ToUpper(c)) + } else { + output = append(output, c) + } + } + return string(output) +} + var wotds = []string{ "une gomme", "une pomme", "phazms", "08 36 65 65 65", "le mot du jour", "cool", "trop de la balle", "coucou", "salut les copains", @@ -20,7 +33,7 @@ var wotds = []string{ // WOTD returns the word of the day func WOTD() string { - return wotds[time.Now().YearDay()%len(wotds)] + return randomCaps(wotds[time.Now().YearDay()%len(wotds)]) } var alternateLogos = []string{ @@ -43,5 +56,49 @@ var alternateLogos = []string{ func AlternateLogo() string { file := alternateLogos[rand.Intn(len(alternateLogos))] - return fmt.Sprintf("https://camembertaulaitcrew.github.io/assets/logo-alternate-300/%s", file) + return fmt.Sprintf("/img/logo-alternate-300/%s", file) +} + +func MotDebileQuiSeMange() string { + mots := []string{ + "beurre", "lait", "yahourt", "pain", "gruyere", "margarine", + "curcumin", "d'épinard", "banane", "salade", "brioche", + "sucre", "chips", "laitage", "lukum", "flotte", "chupa-chups", + "yogourt", + } + return mots[rand.Intn(len(mots))] +} + +func MotCool() string { + mots := []string{ + "cool", "sympa", "gentil", "genial", "excellent", "superbe", "super", + "vraiment tres bien", "bien", "qui en a dans le pantalon", "top", + } + return mots[rand.Intn(len(mots))] +} + +func MotPasCool() string { + return "pas tres " + MotCool() +} + +func RandomColor(dark bool, light bool, limit int) string { + if limit == 0 { + limit = 80 + } + + var r, g, b int + for good := false; !good; { + r = rand.Intn(256) + g = rand.Intn(256) + b = rand.Intn(256) + + if dark { + good = r < limit || g < limit || b < limit + } else if light { + good = r > 256-limit || g > 256-limit || b > 256-limit + } else { + good = true + } + } + return fmt.Sprintf("#%X%X%X", r, g, b) } diff --git a/templates/layout/base.tmpl b/templates/layout/base.tmpl index aecf5ac2..a1403081 100644 --- a/templates/layout/base.tmpl +++ b/templates/layout/base.tmpl @@ -14,23 +14,19 @@ - -{{/* - {% set sharing_image_url = sharing_image_url | default('http://www.camembertaulaitcrew.biz/static/img/logo-300.png') %} - {% set sharing_description = sharing_description | default('C\'est cool') %} - {% set active_page = active_page | default('home') %} - {% set current_url = request.url %} - {# {% set current_url = url_for(request.endpoint, _external=True) %} #} - + - {# viewport ? #} - - + + + + + + + - {# FACEBOOK #} - + + @@ -39,13 +35,13 @@ - {# GEOLOC #} + - {# TWITTER #} + @@ -54,28 +50,20 @@ + + + - {% assets filters="cssmin", output="bundles/base.css", - "components/bootstrap/dist/css/bootstrap.min.css", - "css/calc.css" - %} - - {% endassets %} + - {% block extra_css %}{% endblock %} -*/}} + + {{ block "extra_css" . }}{{ end }} - {{template "content" .}} -{{/*
- {% include 'includes/main_logo.html' %} - {# #} + + + +
- {% include 'includes/le_mot_du_jour.html' %} - {# #} +
+

Le mot du jour est + {{ mot_du_jour }} +

+
+
- {% include 'includes/social_links.html' %} + +
@@ -165,8 +208,8 @@

- Page générée avec {{ megahertz() }} - mégahertz et beaucoup de {{ mot_debile_qui_se_mange() }}. + Page générée avec {{ megahertz }} + mégahertz et beaucoup de {{ mot_debile_qui_se_mange }}. Salut mec ! @@ -174,26 +217,17 @@

- {% if neige %}{% endif %} - {% assets filters="jsmin", output="bundles/base.js", - "components/jquery/dist/jquery.min.js", - "components/bootstrap/dist/js/bootstrap.min.js", - "components/jquery-cookie/jquery.cookie.js", - "components/konami-js/konami.js", - "components/instantclick/instantclick.js", - "js/calc.js" - %} - - {% endassets %} - - {% if neige %} - {% assets filters="jsmin", output="bundles/neige.js", "js/snow4.js"%} - - {% endassets %} - {% endif %} - - {% block extra_js %}{% endblock %} -*/}} + {{ if neige }}{{end}} + + + + + + + + {{ if neige }}{{end}} + + {{ block "extra_js" . }}{{ end }} {{ end }} diff --git a/templates/old/includes/le_mot_du_jour.html b/templates/old/includes/le_mot_du_jour.html deleted file mode 100644 index 19ea1b82..00000000 --- a/templates/old/includes/le_mot_du_jour.html +++ /dev/null @@ -1,5 +0,0 @@ -
-

Le mot du jour est - {{ mot_du_jour() }} -

-
diff --git a/templates/old/includes/main_logo.html b/templates/old/includes/main_logo.html deleted file mode 100644 index 540f6a64..00000000 --- a/templates/old/includes/main_logo.html +++ /dev/null @@ -1,6 +0,0 @@ - - - diff --git a/templates/old/includes/social_links.html b/templates/old/includes/social_links.html deleted file mode 100644 index b3b2373b..00000000 --- a/templates/old/includes/social_links.html +++ /dev/null @@ -1,41 +0,0 @@ - diff --git a/views/funcmap.go b/views/funcmap.go index 1508bb39..dff1d00b 100644 --- a/views/funcmap.go +++ b/views/funcmap.go @@ -3,16 +3,69 @@ package views import ( "html/template" "math/rand" + + "go.uber.org/zap" + "ultre.me/calcbiz/pkg/random" ) -func funcmap(opts *Options) template.FuncMap { +func getFuncmap(opts *Options) template.FuncMap { + f := funcmap{opts: opts} return template.FuncMap{ - "yomyman_style": yomymanStyle, - "devel": func() bool { return opts.Debug }, + "yomyman_style": f.yomymanStyle, + "devel": f.devel, + "sharing_image_url": f.sharingImageURL, + "sharing_description": f.sharingDescription, + "current_url": f.currentURL, + "active_page": f.activePage, + "resize": f.resize, + "page_title": f.pageTitle, + "invalid_cache": f.invalidCache, + "logo_alternate": random.AlternateLogo, + "mot_du_jour": random.WOTD, + "megahertz": f.megahertz, + "mot_debile_qui_se_mange": random.MotDebileQuiSeMange, + "neige": func() bool { return false }, } } -func yomymanStyle() string { +type funcmap struct{ opts *Options } + +func (f *funcmap) devel() bool { return f.opts.Debug } + +func (f *funcmap) sharingImageURL() string { + return "http://www.camembertaulaitcrew.biz/static/img/logo-300.png" // FIXME: make it dynamic +} + +func (f *funcmap) activePage() string { return "home" } // FIXME: make it dynamic + +func (f *funcmap) pageTitle() string { return "Camembert au lait crew" } // FIXME: make it dynamic + +func (f *funcmap) sharingDescription() string { return "c'est cool" } + +func (f *funcmap) currentURL() string { + return "https://www.camembertaulaitcrew.biz/" + // FIXME: make it flexible (should be canonical url +} + +func (f *funcmap) resize(opts ...string) string { + path := opts[len(opts)-1] + opts = opts[:len(opts)-1] + zap.L().Debug("redize", zap.String("path", path), zap.Strings("opts", opts)) + // FIXME: apply transform + cache + give new URL + return path +} + +func (f *funcmap) yomymanStyle() string { styles := []string{"cachou", "jambon", "epinard", "lasagne", "haricot", "sandwich"} return "cool-style-" + styles[rand.Intn(len(styles))] } + +func (f *funcmap) invalidCache() string { + // FIXME: use random string (once per server start) + // FIXME: or create a new func that returns file content hash + return "no_cache_please" +} + +func (f *funcmap) megahertz() float64 { + return rand.Float64() * 100 +} diff --git a/views/util.go b/views/util.go index 2f911461..188f12ba 100644 --- a/views/util.go +++ b/views/util.go @@ -40,7 +40,8 @@ func loadTemplates(opts *Options) error { } // generate optimized templates - mainTemplate := template.New("main").Funcs(funcmap(opts)) + funcmap := getFuncmap(opts) + mainTemplate := template.New("main").Funcs(funcmap) mainTemplate = template.Must(mainTemplate.Parse(`{{define "main"}}{{template "base" .}}{{end}}`)) mainTemplate = template.Must(mainTemplate.Parse(layoutContent)) for filepath, content := range pageContents { diff --git a/views/views.go b/views/views.go index 956e2f48..ba5eca5c 100644 --- a/views/views.go +++ b/views/views.go @@ -18,7 +18,7 @@ func Setup(opts *Options) error { opts.Router.HandleFunc("/", homeHandler) opts.Router.HandleFunc("/muzik", muzikHandler) opts.Router.HandleFunc("/hackz", hackzHandler) - opts.Router.HandleFunc("/copains", copaingsHandler) + opts.Router.HandleFunc("/copaings", copaingsHandler) return nil }