diff --git a/assets/public/index.html b/assets/public/index.html
index 383de39..e0f2e9a 100644
--- a/assets/public/index.html
+++ b/assets/public/index.html
@@ -11,7 +11,7 @@
NoteHub
Pastebin for One-Off Markdown Publishing
- See Demo Note
+ See Demo Note
New Note
diff --git a/assets/public/style.css b/assets/public/style.css
index cbd7c63..38580f8 100644
--- a/assets/public/style.css
+++ b/assets/public/style.css
@@ -9,8 +9,7 @@ html, body {
margin: 0;
color: #b0b0b0;
background: #353a3a;
- font-family: monospace;
- font-size: 1.1em;
+ font-family: Menlo, Consolas, monospace;
}
#hero {
@@ -38,6 +37,7 @@ html, body {
a {
color: #097;
+ text-decoration: none;
}
a:hover {
@@ -181,13 +181,24 @@ blockquote {
outline: 0px none transparent;
}
+pre, code {
+ font-family: monospace;
+ border-radius: 3px;
+ background-color: #303535;
+ font-size: 1.2em;
+}
+
+pre {
+ padding: 1em;
+}
+
table {
border-collapse: collapse;
width: 100%;
}
th {
- background-color: #efefef;
+ background-color: #303535;
line-height: 2.5em;
padding: 0.3em;
}
@@ -195,7 +206,7 @@ th {
td {
line-height: 2.5em;
padding: 0.3em;
- border-top: 1px solid #aaa;
+ border-top: 1px solid #404545;
}
.middot {
@@ -222,9 +233,6 @@ td {
margin-bottom: 0.5em;
margin-top: 0.5em;
}
- #previewPane {
- display: none !important;
- }
}
textarea {
diff --git a/server.go b/server.go
index 3e4a389..d2d334f 100644
--- a/server.go
+++ b/server.go
@@ -31,9 +31,20 @@ func main() {
e.Renderer = &Template{templates: template.Must(template.ParseGlob("assets/templates/*.html"))}
- e.Static("/", "assets/public")
- e.GET("/TOS.md", func(c echo.Context) error { return c.Render(http.StatusOK, "Page", md2html(c, "TOS")) })
- e.GET("/:id", func(c echo.Context) error { return c.Render(http.StatusOK, "Note", note(c, db)) })
+ e.File("/favicon.ico", "assets/public/favicon.ico")
+ e.File("/robots.txt", "assets/public/robots.txt")
+ e.File("/style.css", "assets/public/style.css")
+ e.File("/index.html", "assets/public/index.html")
+ e.File("/", "assets/public/index.html")
+
+ e.GET("/TOS.md", func(c echo.Context) error {
+ n, code := md2html(c, "TOS")
+ return c.Render(code, "Page", n)
+ })
+ e.GET("/:id", func(c echo.Context) error {
+ n, code := note(c, db)
+ return c.Render(code, "Note", n)
+ })
e.Logger.Fatal(e.Start(":3000"))
}
@@ -45,11 +56,12 @@ type Note struct {
Content template.HTML
}
-func note(c echo.Context, db *sql.DB) Note {
- stmt, err := db.Prepare("select id, text, strftime('%s', published) as published, strftime('%s',edited) as edited, password, views from notes where id = ?")
+func note(c echo.Context, db *sql.DB) (Note, int) {
+ stmt, err := db.Prepare("select id, text, strftime('%s', published) as published," +
+ " strftime('%s',edited) as edited, password, views from notes where id = ?")
if err != nil {
c.Logger().Error(err)
- return Note{}
+ return note503, http.StatusServiceUnavailable
}
defer stmt.Close()
row := stmt.QueryRow(c.Param("id"))
@@ -57,22 +69,28 @@ func note(c echo.Context, db *sql.DB) Note {
var views int
if err := row.Scan(&id, &text, &published, &edited, &password, &views); err != nil {
c.Logger().Error(err)
- return Note{} // TODO: use predefined error notes
+ return note404, http.StatusNotFound
}
// cand := regexp.MustCompile("[\n\r]").Split(text, 1)
// fmt.Println("CANDIDATE", cand[0])
return Note{
ID: id,
- Content: template.HTML(string(blackfriday.Run([]byte(text)))),
- }
+ Content: mdTmplHTML([]byte(text)),
+ }, http.StatusOK
}
-func md2html(c echo.Context, name string) Note {
+func md2html(c echo.Context, name string) (Note, int) {
path := "assets/markdown/" + name + ".md"
mdContent, err := ioutil.ReadFile(path)
if err != nil {
c.Logger().Errorf("couldn't open markdown page %q: %v", path, err)
- return Note{}
+ return note503, http.StatusServiceUnavailable
}
- return Note{Title: name, Content: template.HTML(string(blackfriday.Run(mdContent)))}
+ return Note{Title: name, Content: mdTmplHTML(mdContent)}, http.StatusOK
}
+
+func mdTmplHTML(content []byte) template.HTML { return template.HTML(string(blackfriday.Run(content))) }
+
+// error notes
+var note404 = Note{Title: "Not found", Content: mdTmplHTML([]byte("# 404 NOT FOUND"))}
+var note503 = Note{Title: "Service unavailable", Content: mdTmplHTML([]byte("# 503 SERVICE UNAVAILABLE"))}