Browse Source

Added Icons, and improved serving of static files.

main
Nichole Mattera 1 year ago
parent
commit
fb10fc4fcb
  1. 28
      main.go
  2. BIN
      static/images/icon-128x128.png
  3. BIN
      static/images/icon-144x144.png
  4. BIN
      static/images/icon-192x192.png
  5. BIN
      static/images/icon-72x72.png
  6. BIN
      static/images/icon-96x96.png
  7. 23
      static/manifest.json
  8. 2
      templates/main.tmpl

28
main.go

@ -3,6 +3,9 @@ package main
import (
"log"
"net/http"
"os"
"path/filepath"
"strings"
"text/template"
)
@ -13,13 +16,36 @@ type TemplateData struct {
IncludeServiceWorker bool
}
func fileExists(path string) bool {
info, err := os.Stat(path)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func main() {
cwd, err := os.Getwd()
if err != nil {
log.Fatal("Error: Unable to get current working directory.")
}
mainTemplate, err := template.ParseFiles("./templates/main.tmpl")
if err != nil {
log.Fatal("Error: Unable to parse the template file.")
}
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
// Serve static files.
if fileExists("./static" + req.URL.Path) {
path, err := filepath.Abs("./static" + req.URL.Path)
if err == nil && strings.HasPrefix(path, cwd + "/static") {
http.ServeFile(w, req, "./static" + req.URL.Path)
return
}
}
// Templates & Redirect
if req.URL.Path == "/smatter" || req.URL.Path == "/smatter/offline.html" {
data := TemplateData {
Title: "Do Blue Lives Matter?",
@ -38,8 +64,6 @@ func main() {
}
mainTemplate.Execute(w, data)
} else if req.URL.Path == "/robots.txt" || req.URL.Path == "/service-worker.js" || req.URL.Path == "/manifest.json" {
http.ServeFile(w, req, "./static" + req.URL.Path)
} else {
scheme := "http"
if req.TLS != nil {

BIN
static/images/icon-128x128.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
static/images/icon-144x144.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
static/images/icon-192x192.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
static/images/icon-72x72.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
static/images/icon-96x96.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

23
static/manifest.json

@ -7,6 +7,27 @@
"display": "minimal-ui",
"Scope": "/",
"start_url": "/smatter",
"icons": [],
"icons": [
{
"src": "/images/icon-72x72.png",
"sizes": "72x72",
"type": "image/png"
},
{
"src": "/images/icon-96x96.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "/images/icon-128x128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "/images/icon-144x144.png",
"sizes": "144x144",
"type": "image/png"
}
],
"splash_pages": null
}

2
templates/main.tmpl

@ -3,6 +3,7 @@
<head>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="{{ .Description }}" />
<meta name="theme-color" content="#FDD835" />
<meta property="og:title" content="{{ .Title }}" />
<meta property="og:site_name" content="{{ .Title }}" />
@ -16,6 +17,7 @@
<title>{{ .Title }}</title>
<link rel="manifest" href="/manifest.json">
<link rel="apple-touch-icon" href="/images/icon-192x192.png">
<style>
body {

Loading…
Cancel
Save