Browse Source

fixes styling, adds predefined error notes

master
Christian Müller 8 years ago
parent
commit
b7875667f0
  1. 2
      assets/public/index.html
  2. 22
      assets/public/style.css
  3. 42
      server.go

2
assets/public/index.html

@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
<h1>NoteHub</h1>
<h2>Pastebin for One-Off Markdown Publishing</h2>
<br>
<a class="landing-button demo" href="/Demo.md" style="color: white">See Demo Note</a>
<a class="landing-button demo" href="/demo" style="color: white">See Demo Note</a>
<a class="landing-button" href="/new" style="color: white">New Note</a>
</div>
<div id="dashed-line"></div>

22
assets/public/style.css

@ -9,8 +9,7 @@ html, body { @@ -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 { @@ -38,6 +37,7 @@ html, body {
a {
color: #097;
text-decoration: none;
}
a:hover {
@ -181,13 +181,24 @@ blockquote { @@ -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 { @@ -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 { @@ -222,9 +233,6 @@ td {
margin-bottom: 0.5em;
margin-top: 0.5em;
}
#previewPane {
display: none !important;
}
}
textarea {

42
server.go

@ -31,9 +31,20 @@ func main() { @@ -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 { @@ -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 { @@ -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"))}

Loading…
Cancel
Save