2f31d678d0
Adds two new features to collect and show useful analytics. Usage Statistics: * Begin tracking daily active users who log in and interact with major features of the website each day, such as the chat room, forum and gallery. Demographics page: * For marketing, the home page now shows live statistics about the breakdown of content (explicit vs. non-explicit) on the site, and the /insights page gives a lot more data in detail. * Show the percent split in photo gallery content and how many users opt-in or share explicit content on the site. * Show high-level demographics of the members (by age range, gender, orientation) Misc cleanup: * Rearrange model list in data export to match the auto-create statements. * In data exports, include the forum_memberships, push_notifications and usage_statistics tables.
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package index
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/config"
|
|
"code.nonshy.com/nonshy/website/pkg/log"
|
|
"code.nonshy.com/nonshy/website/pkg/models/demographic"
|
|
"code.nonshy.com/nonshy/website/pkg/templates"
|
|
)
|
|
|
|
// Create the controller.
|
|
func Create() http.HandlerFunc {
|
|
tmpl := templates.Must("index.html")
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/" || r.Method != http.MethodGet {
|
|
log.Error("404 Not Found: %s", r.URL.Path)
|
|
templates.NotFoundPage(w, r)
|
|
return
|
|
}
|
|
|
|
// Get website statistics to show on home page.
|
|
demo, err := demographic.Get()
|
|
if err != nil {
|
|
log.Error("demographic.Get: %s", err)
|
|
}
|
|
|
|
vars := map[string]interface{}{
|
|
"Demographic": demo,
|
|
}
|
|
|
|
if err := tmpl.Execute(w, r, vars); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
})
|
|
}
|
|
|
|
// Favicon
|
|
func Favicon() http.HandlerFunc {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
http.ServeFile(w, r, config.StaticPath+"/favicon.ico")
|
|
})
|
|
}
|
|
|
|
// PWA Manifest
|
|
func Manifest() http.HandlerFunc {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
http.ServeFile(w, r, config.StaticPath+"/manifest.json")
|
|
})
|
|
}
|
|
|
|
// Service Worker for web push.
|
|
func ServiceWorker() http.HandlerFunc {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Add("Content-Type", "application/javascript; charset=UTF-8")
|
|
w.Header().Add("Service-Worker-Allowed", "/")
|
|
http.ServeFile(w, r, config.StaticPath+"/js/service-worker.js")
|
|
})
|
|
}
|