5 コミット

作成者 SHA1 メッセージ 日付
  Matt Baer 4327421cfb Support dynamic Status page in footer 3年前
  Matt Baer 5e11c443eb Log host name for each request 3年前
  Matt Baer b969e40fb4 Add 404 pages 3年前
  Matt Baer 67f93826b1 Add developers.snap.as site 3年前
  Matt Baer 6580b70596 Ignore developers binary 3年前
11個のファイルの変更113行の追加28行の削除
分割表示
  1. +1
    -0
      .gitignore
  2. +22
    -16
      handlers.go
  3. +14
    -0
      pages/snapas/404.tmpl
  4. +33
    -0
      pages/snapas/index.tmpl
  5. +14
    -0
      pages/writeas/404.tmpl
  6. +0
    -0
      pages/writeas/index.tmpl
  7. +0
    -0
      pages/writeas/markdown.tmpl
  8. +22
    -7
      platform/platforms.go
  9. +2
    -1
      server.go
  10. +2
    -2
      templates.go
  11. +3
    -2
      templates/base.tmpl

+ 1
- 0
.gitignore ファイルの表示

@@ -1 +1,2 @@
*.swp
developers

+ 22
- 16
handlers.go ファイルの表示

@@ -19,7 +19,7 @@ func viewPage(w http.ResponseWriter, r *http.Request) {
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:]
@@ -27,41 +27,47 @@ func viewPage(w http.ResponseWriter, r *http.Request) {
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
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 {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

w.WriteHeader(http.StatusNotFound)
err = t.ExecuteTemplate(w, "base", nil)
err = t.ExecuteTemplate(w, "base", p)
if err != nil {
log.Info("Unable to render 404 page: %s", err)
}
return
} 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
t, err := getTemplate(name)
t, err := getTemplate(pl.SiteDir, p.Path)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
p := struct {
Path string
Platform platform.Platform
}{
Path: name,
Platform: platform.WriteAs,
}

err = t.ExecuteTemplate(w, "base", p)
if err != nil {


+ 14
- 0
pages/snapas/404.tmpl ファイルの表示

@@ -0,0 +1,14 @@
{{define "head"}}<title>No such file &mdash; 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="/">&larr; Back to home</a></p>
</div>
</div>
{{end}}

+ 33
- 0
pages/snapas/index.tmpl ファイルの表示

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

+ 14
- 0
pages/writeas/404.tmpl ファイルの表示

@@ -0,0 +1,14 @@
{{define "head"}}<title>No such file &mdash; 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="/">&larr; Back to home</a></p>
</div>
</div>
{{end}}

pages/index.tmpl → pages/writeas/index.tmpl ファイルの表示


pages/markdown.tmpl → pages/writeas/markdown.tmpl ファイルの表示


+ 22
- 7
platform/platforms.go ファイルの表示

@@ -5,19 +5,34 @@ type Platform struct {
URL string
LogoURL string
StyleSheetURL string
StatusURL string
CodeAsName string
GitHubName string
MatomoID int

SiteDir string
}

var (
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",
}
)

+ 2
- 1
server.go ファイルの表示

@@ -15,9 +15,10 @@ const (
staticDir = "static"
)

var portPtr = flag.Int("p", 8080, "Port to listen on.")

func main() {
// Parse config options
portPtr := flag.Int("p", 8080, "Port to listen on.")
flag.Parse()

// Add routes


+ 2
- 2
templates.go ファイルの表示

@@ -5,9 +5,9 @@ import (
"path/filepath"
)

func getTemplate(name string) (*template.Template, error) {
func getTemplate(siteDir string, name string) (*template.Template, error) {
return template.New("").ParseFiles(
filepath.Join(pagesDir, name+".tmpl"),
filepath.Join(pagesDir, siteDir, name+".tmpl"),
filepath.Join(templatesDir, "base.tmpl"),
)
}

+ 3
- 2
templates/base.tmpl ファイルの表示

@@ -3,7 +3,8 @@
<head>
{{ template "head" . }}
<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" />
</head>
<body {{template "body-attrs" .}}>
@@ -72,7 +73,7 @@
<ul>
<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://status.write.as">status</a></li>
<li><a href="{{.Platform.StatusURL}}">status</a></li>
<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>
</li>


読み込み中…
キャンセル
保存