fixes styling, adds predefined error notes
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
<h1>NoteHub</h1>
|
<h1>NoteHub</h1>
|
||||||
<h2>Pastebin for One-Off Markdown Publishing</h2>
|
<h2>Pastebin for One-Off Markdown Publishing</h2>
|
||||||
<br>
|
<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>
|
<a class="landing-button" href="/new" style="color: white">New Note</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="dashed-line"></div>
|
<div id="dashed-line"></div>
|
||||||
|
|||||||
+15
-7
@@ -9,8 +9,7 @@ html, body {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
color: #b0b0b0;
|
color: #b0b0b0;
|
||||||
background: #353a3a;
|
background: #353a3a;
|
||||||
font-family: monospace;
|
font-family: Menlo, Consolas, monospace;
|
||||||
font-size: 1.1em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#hero {
|
#hero {
|
||||||
@@ -38,6 +37,7 @@ html, body {
|
|||||||
|
|
||||||
a {
|
a {
|
||||||
color: #097;
|
color: #097;
|
||||||
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover {
|
a:hover {
|
||||||
@@ -181,13 +181,24 @@ blockquote {
|
|||||||
outline: 0px none transparent;
|
outline: 0px none transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pre, code {
|
||||||
|
font-family: monospace;
|
||||||
|
border-radius: 3px;
|
||||||
|
background-color: #303535;
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
padding: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
th {
|
th {
|
||||||
background-color: #efefef;
|
background-color: #303535;
|
||||||
line-height: 2.5em;
|
line-height: 2.5em;
|
||||||
padding: 0.3em;
|
padding: 0.3em;
|
||||||
}
|
}
|
||||||
@@ -195,7 +206,7 @@ th {
|
|||||||
td {
|
td {
|
||||||
line-height: 2.5em;
|
line-height: 2.5em;
|
||||||
padding: 0.3em;
|
padding: 0.3em;
|
||||||
border-top: 1px solid #aaa;
|
border-top: 1px solid #404545;
|
||||||
}
|
}
|
||||||
|
|
||||||
.middot {
|
.middot {
|
||||||
@@ -222,9 +233,6 @@ td {
|
|||||||
margin-bottom: 0.5em;
|
margin-bottom: 0.5em;
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
}
|
}
|
||||||
#previewPane {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
|
|||||||
@@ -31,9 +31,20 @@ func main() {
|
|||||||
|
|
||||||
e.Renderer = &Template{templates: template.Must(template.ParseGlob("assets/templates/*.html"))}
|
e.Renderer = &Template{templates: template.Must(template.ParseGlob("assets/templates/*.html"))}
|
||||||
|
|
||||||
e.Static("/", "assets/public")
|
e.File("/favicon.ico", "assets/public/favicon.ico")
|
||||||
e.GET("/TOS.md", func(c echo.Context) error { return c.Render(http.StatusOK, "Page", md2html(c, "TOS")) })
|
e.File("/robots.txt", "assets/public/robots.txt")
|
||||||
e.GET("/:id", func(c echo.Context) error { return c.Render(http.StatusOK, "Note", note(c, db)) })
|
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"))
|
e.Logger.Fatal(e.Start(":3000"))
|
||||||
}
|
}
|
||||||
@@ -45,11 +56,12 @@ type Note struct {
|
|||||||
Content template.HTML
|
Content template.HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
func note(c echo.Context, db *sql.DB) Note {
|
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 = ?")
|
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 {
|
if err != nil {
|
||||||
c.Logger().Error(err)
|
c.Logger().Error(err)
|
||||||
return Note{}
|
return note503, http.StatusServiceUnavailable
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
row := stmt.QueryRow(c.Param("id"))
|
row := stmt.QueryRow(c.Param("id"))
|
||||||
@@ -57,22 +69,28 @@ func note(c echo.Context, db *sql.DB) Note {
|
|||||||
var views int
|
var views int
|
||||||
if err := row.Scan(&id, &text, &published, &edited, &password, &views); err != nil {
|
if err := row.Scan(&id, &text, &published, &edited, &password, &views); err != nil {
|
||||||
c.Logger().Error(err)
|
c.Logger().Error(err)
|
||||||
return Note{} // TODO: use predefined error notes
|
return note404, http.StatusNotFound
|
||||||
}
|
}
|
||||||
// cand := regexp.MustCompile("[\n\r]").Split(text, 1)
|
// cand := regexp.MustCompile("[\n\r]").Split(text, 1)
|
||||||
// fmt.Println("CANDIDATE", cand[0])
|
// fmt.Println("CANDIDATE", cand[0])
|
||||||
return Note{
|
return Note{
|
||||||
ID: id,
|
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"
|
path := "assets/markdown/" + name + ".md"
|
||||||
mdContent, err := ioutil.ReadFile(path)
|
mdContent, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Logger().Errorf("couldn't open markdown page %q: %v", path, err)
|
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"))}
|
||||||
|
|||||||
Reference in New Issue
Block a user