Browse Source

Added Icons, and improved serving of static files.

main
Nichole Mattera 7 months ago
parent
commit
fb10fc4fcb
8 changed files with 50 additions and 3 deletions
  1. +26
    -2
      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. +22
    -1
      static/manifest.json
  8. +2
    -0
      templates/main.tmpl

+ 26
- 2
main.go View File

@ -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 View File

Before After
Width: 128  |  Height: 128  |  Size: 2.9 KiB

BIN
static/images/icon-144x144.png View File

Before After
Width: 144  |  Height: 144  |  Size: 2.8 KiB

BIN
static/images/icon-192x192.png View File

Before After
Width: 192  |  Height: 192  |  Size: 2.9 KiB

BIN
static/images/icon-72x72.png View File

Before After
Width: 72  |  Height: 72  |  Size: 1.9 KiB

BIN
static/images/icon-96x96.png View File

Before After
Width: 96  |  Height: 96  |  Size: 2.3 KiB

+ 22
- 1
static/manifest.json View File

@ -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
- 0
templates/main.tmpl View File

@ -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