Author | SHA1 | Message | Date |
---|---|---|---|
Matt Baer | 4327421cfb | Support dynamic Status page in footer | 3 years ago |
Matt Baer | 5e11c443eb | Log host name for each request | 3 years ago |
Matt Baer | b969e40fb4 | Add 404 pages | 3 years ago |
Matt Baer | 67f93826b1 |
Add developers.snap.as site
This adds the Snap.as developer center and updates the project structure to support dev center sites for other products. |
3 years ago |
Matt Baer | 6580b70596 | Ignore developers binary | 3 years ago |
@@ -1 +1,2 @@ | |||||
*.swp | *.swp | ||||
developers |
@@ -19,7 +19,7 @@ func viewPage(w http.ResponseWriter, r *http.Request) { | |||||
http.Error(w, "Error", http.StatusInternalServerError) | http.Error(w, "Error", http.StatusInternalServerError) | ||||
} | } | ||||
log.Info(fmt.Sprintf("\"%s %s\" %s \"%s\"", r.Method, r.RequestURI, time.Since(start), r.UserAgent())) | |||||
log.Info(fmt.Sprintf("\"%s %s\" %s \"%s\" \"%s\"", r.Method, r.RequestURI, time.Since(start), r.UserAgent(), r.Host)) | |||||
}() | }() | ||||
name := r.URL.Path[1:] | name := r.URL.Path[1:] | ||||
@@ -27,41 +27,47 @@ func viewPage(w http.ResponseWriter, r *http.Request) { | |||||
name = "index" | name = "index" | ||||
} | } | ||||
pl := &platform.WriteAs | |||||
if r.Host == "developers.snap.as" || r.Host == fmt.Sprintf("devsnap.local:%d", *portPtr) { | |||||
pl = &platform.SnapAs | |||||
} | |||||
p := struct { | |||||
Path string | |||||
Platform *platform.Platform | |||||
}{ | |||||
Path: name, | |||||
Platform: pl, | |||||
} | |||||
// Make sure the page exists | // Make sure the page exists | ||||
if _, err := os.Stat(filepath.Join(pagesDir, name+".tmpl")); os.IsNotExist(err) { | |||||
log.Info(filepath.Join(pagesDir, name, "index.tmpl")) | |||||
if _, err := os.Stat(filepath.Join(pagesDir, name, "index.tmpl")); os.IsNotExist(err) { | |||||
t, err := getTemplate("404") | |||||
if _, err := os.Stat(filepath.Join(pagesDir, pl.SiteDir, p.Path+".tmpl")); os.IsNotExist(err) { | |||||
log.Info(filepath.Join(pagesDir, pl.SiteDir, p.Path, "index.tmpl")) | |||||
if _, err := os.Stat(filepath.Join(pagesDir, pl.SiteDir, p.Path, "index.tmpl")); os.IsNotExist(err) { | |||||
t, err := getTemplate(pl.SiteDir, "404") | |||||
if err != nil { | if err != nil { | ||||
http.Error(w, err.Error(), http.StatusInternalServerError) | http.Error(w, err.Error(), http.StatusInternalServerError) | ||||
return | return | ||||
} | } | ||||
w.WriteHeader(http.StatusNotFound) | w.WriteHeader(http.StatusNotFound) | ||||
err = t.ExecuteTemplate(w, "base", nil) | |||||
err = t.ExecuteTemplate(w, "base", p) | |||||
if err != nil { | if err != nil { | ||||
log.Info("Unable to render 404 page: %s", err) | log.Info("Unable to render 404 page: %s", err) | ||||
} | } | ||||
return | return | ||||
} else { | } else { | ||||
name = filepath.Join(name, "index") | |||||
log.Info("name is now %s", name) | |||||
p.Path = filepath.Join(p.Path, "index") | |||||
log.Info("name is now %s", p.Path) | |||||
} | } | ||||
} | } | ||||
// Render the page | // Render the page | ||||
t, err := getTemplate(name) | |||||
t, err := getTemplate(pl.SiteDir, p.Path) | |||||
if err != nil { | if err != nil { | ||||
http.Error(w, err.Error(), http.StatusInternalServerError) | http.Error(w, err.Error(), http.StatusInternalServerError) | ||||
return | return | ||||
} | } | ||||
p := struct { | |||||
Path string | |||||
Platform platform.Platform | |||||
}{ | |||||
Path: name, | |||||
Platform: platform.WriteAs, | |||||
} | |||||
err = t.ExecuteTemplate(w, "base", p) | err = t.ExecuteTemplate(w, "base", p) | ||||
if err != nil { | if err != nil { | ||||
@@ -0,0 +1,14 @@ | |||||
{{define "head"}}<title>No such file — Snap.as Developer Center</title> | |||||
{{end}} | |||||
{{define "body-attrs"}}{{end}} | |||||
{{define "content"}} | |||||
<div class="content-container" style="text-align: center;"> | |||||
<div class="heading"> | |||||
<h1>No such page.</h1> | |||||
<p style="font-size: 1.2em">That's a 404.</p> | |||||
<p><a href="/">← Back to home</a></p> | |||||
</div> | |||||
</div> | |||||
{{end}} |
@@ -0,0 +1,33 @@ | |||||
{{define "head"}}<title>Snap.as Developer Center</title> | |||||
<style type="text/css"> | |||||
.content-container ul { | |||||
list-style: none; | |||||
text-indent: 0; | |||||
margin: 0; | |||||
padding: 0 !important; | |||||
} | |||||
.content-container li { | |||||
margin: 1em 0 !important; | |||||
} | |||||
</style> | |||||
{{end}} | |||||
{{define "body-attrs"}}id="promo"{{end}} | |||||
{{define "content"}} | |||||
<div class="content-container" style="text-align: center; font-size: 1em;"> | |||||
<div class="heading"> | |||||
<h1>Snap.as Developer Center</h1> | |||||
<p style="font-size: 1.2em">Build your own apps and utilities on the Snap.as platform.</p> | |||||
</div> | |||||
<div class="clearfix blurbs"> | |||||
<div class="half"> | |||||
<h2>Documentation</h2> | |||||
<ul> | |||||
<li><a href="/docs/api/">API Documentation</a></li> | |||||
</ul> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
{{end}} |
@@ -0,0 +1,14 @@ | |||||
{{define "head"}}<title>No such file — Write.as Developer Center</title> | |||||
{{end}} | |||||
{{define "body-attrs"}}{{end}} | |||||
{{define "content"}} | |||||
<div class="content-container" style="text-align: center;"> | |||||
<div class="heading"> | |||||
<h1>No such page.</h1> | |||||
<p style="font-size: 1.2em">That's a 404.</p> | |||||
<p><a href="/">← Back to home</a></p> | |||||
</div> | |||||
</div> | |||||
{{end}} |
@@ -5,19 +5,34 @@ type Platform struct { | |||||
URL string | URL string | ||||
LogoURL string | LogoURL string | ||||
StyleSheetURL string | StyleSheetURL string | ||||
StatusURL string | |||||
CodeAsName string | CodeAsName string | ||||
GitHubName string | GitHubName string | ||||
MatomoID int | MatomoID int | ||||
SiteDir string | |||||
} | } | ||||
var ( | var ( | ||||
WriteAs = Platform{ | WriteAs = Platform{ | ||||
Name: "Write.as", | |||||
URL: "https://write.as", | |||||
LogoURL: "https://write.as/img/w-sq.svg", | |||||
StyleSheetURL: "https://write.as/css/write.css", | |||||
CodeAsName: "writeas", | |||||
GitHubName: "writeas", | |||||
MatomoID: 7, | |||||
Name: "Write.as", | |||||
URL: "https://write.as", | |||||
LogoURL: "https://write.as/img/w-sq.svg", | |||||
StatusURL: "https://status.write.as", | |||||
CodeAsName: "writeas", | |||||
GitHubName: "writeas", | |||||
MatomoID: 7, | |||||
SiteDir: "writeas", | |||||
} | |||||
SnapAs = Platform{ | |||||
Name: "Snap.as", | |||||
URL: "https://snap.as", | |||||
LogoURL: "https://snap.as/img/logo-mark-sm.png", | |||||
StyleSheetURL: "https://v2.snap.as/css/snap.css", | |||||
StatusURL: "https://status.snap.as", | |||||
CodeAsName: "snapas", | |||||
GitHubName: "snapas", | |||||
MatomoID: 20, | |||||
SiteDir: "snapas", | |||||
} | } | ||||
) | ) |
@@ -15,9 +15,10 @@ const ( | |||||
staticDir = "static" | staticDir = "static" | ||||
) | ) | ||||
var portPtr = flag.Int("p", 8080, "Port to listen on.") | |||||
func main() { | func main() { | ||||
// Parse config options | // Parse config options | ||||
portPtr := flag.Int("p", 8080, "Port to listen on.") | |||||
flag.Parse() | flag.Parse() | ||||
// Add routes | // Add routes | ||||
@@ -5,9 +5,9 @@ import ( | |||||
"path/filepath" | "path/filepath" | ||||
) | ) | ||||
func getTemplate(name string) (*template.Template, error) { | |||||
func getTemplate(siteDir string, name string) (*template.Template, error) { | |||||
return template.New("").ParseFiles( | return template.New("").ParseFiles( | ||||
filepath.Join(pagesDir, name+".tmpl"), | |||||
filepath.Join(pagesDir, siteDir, name+".tmpl"), | |||||
filepath.Join(templatesDir, "base.tmpl"), | filepath.Join(templatesDir, "base.tmpl"), | ||||
) | ) | ||||
} | } |
@@ -3,7 +3,8 @@ | |||||
<head> | <head> | ||||
{{ template "head" . }} | {{ template "head" . }} | ||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||||
<link rel="stylesheet" type="text/css" href="{{.Platform.StyleSheetURL}}" /> | |||||
<link rel="stylesheet" type="text/css" href="https://write.as/css/write.css" /> | |||||
{{if .Platform.StyleSheetURL}}<link rel="stylesheet" type="text/css" href="{{.Platform.StyleSheetURL}}" />{{end}} | |||||
<link rel="stylesheet" type="text/css" href="/css/dev.css" /> | <link rel="stylesheet" type="text/css" href="/css/dev.css" /> | ||||
</head> | </head> | ||||
<body {{template "body-attrs" .}}> | <body {{template "body-attrs" .}}> | ||||
@@ -72,7 +73,7 @@ | |||||
<ul> | <ul> | ||||
<li><a href="/docs/api/">api</a></li> | <li><a href="/docs/api/">api</a></li> | ||||
<li><a href="https://discuss.write.as/c/development/7">community</a></li> | <li><a href="https://discuss.write.as/c/development/7">community</a></li> | ||||
<li><a href="https://status.write.as">status</a></li> | |||||
<li><a href="{{.Platform.StatusURL}}">status</a></li> | |||||
<li class="icons"> | <li class="icons"> | ||||
<a href="https://m.abunchtell.com/@writeas_dev" rel="me"><img src="https://write.as/img/mastodon.svg" alt="@writeas_dev on the fediverse" /></a> | <a href="https://m.abunchtell.com/@writeas_dev" rel="me"><img src="https://write.as/img/mastodon.svg" alt="@writeas_dev on the fediverse" /></a> | ||||
</li> | </li> | ||||