templating added
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
<footer>
|
||||
<a href="/">⌂ notehub</a> ·
|
||||
<a href="%LINK%/stats">statistics</a> ·
|
||||
<a href="%LINK%/edit">edit</a> ·
|
||||
<a href="%LINK%/export">export</a> ·
|
||||
<a href="/TOS.md">terms of service</a>
|
||||
</footer>
|
||||
@@ -1,36 +0,0 @@
|
||||
# Demo Note
|
||||
|
||||
## Text Formatting
|
||||
|
||||
This is a _short_ note demonstrating the **capabilities** of Markdown. [Markdown](http://en.wikipedia.org/wiki/Markdown) is a _markup language_ with plain text
|
||||
formatting syntax. But you also can use <u>standard HTML</u> tags.
|
||||
|
||||
## Backquotes, Lists & Code
|
||||
|
||||
This is a backquote:
|
||||
|
||||
> _"Our greatest glory is not in never falling but in rising every time we fall."_
|
||||
> — Confucius
|
||||
|
||||
To create simple lists, just enumerate all items using a dash in the prefix:
|
||||
|
||||
- Alpha
|
||||
- Beta
|
||||
- Gamma
|
||||
|
||||
Also you can either mark some special `words` or write entire `code` blocks:
|
||||
|
||||
(defn fact [n]
|
||||
(if (< n 2) 1
|
||||
(* n (fact (- n 1)))))
|
||||
|
||||
## Tables
|
||||
|
||||
Also simple tables is a piece of cake:
|
||||
|
||||
Column 1 | Column 2 | Column 3
|
||||
--- | --- | ---
|
||||
Text 1 | Text 3 | <s>Text 5</s>
|
||||
Text 2 | Text 4 | <mark>Text 6</mark>
|
||||
|
||||
Take a look at the [source code](/Demo.md/export) of this page, to see how it works.
|
||||
@@ -18,7 +18,7 @@
|
||||
<article class="bottom-space">
|
||||
<h2>Changelog</h2>
|
||||
<ul>
|
||||
<li><strong>2017-08</strong>: NoteHub 3.0 released: rewritten in Go; all features but essential dropped.</li>
|
||||
<li><strong>2017-08</strong>: NoteHub 3.0.</li>
|
||||
<li><strong>2016-03</strong>: Note deletion feature added.</li>
|
||||
<li><strong>2015-10</strong>: NoteHub rewritten in Node.js.</li>
|
||||
<li><strong>2015-10</strong>: NoteHub API and note styling discontinued due to low adoption.</li>
|
||||
|
||||
@@ -10,6 +10,7 @@ html, body {
|
||||
color: #b0b0b0;
|
||||
background: #353a3a;
|
||||
font-family: monospace;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
#hero {
|
||||
@@ -36,7 +37,6 @@ html, body {
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #097;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ a:hover {
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #075;
|
||||
color: #086;
|
||||
}
|
||||
|
||||
.button {
|
||||
@@ -103,7 +103,8 @@ footer a {
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-weight: 400;
|
||||
font-weight: bold;
|
||||
font-family: "Arial";
|
||||
}
|
||||
|
||||
h1 {
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>NoteHub — %TITLE%</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||
<link href="/style.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
%HEADER%
|
||||
<article>
|
||||
%CONTENT%
|
||||
</article>
|
||||
%FOOTER%
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>NoteHub — {{.Title}}</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||
<link href="/style.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<article>
|
||||
{{.Content}}
|
||||
</article>
|
||||
<footer>
|
||||
<a href="/">⌂ notehub</a> ·
|
||||
<a href="{{.ID}}/stats">statistics</a> ·
|
||||
<a href="{{.ID}}/edit">edit</a> ·
|
||||
<a href="{{.ID}}/export">export</a> ·
|
||||
<a href="/TOS.md">terms of service</a>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,19 @@
|
||||
{{define "Page"}}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>NoteHub — {{.Title}}</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||
<link href="/style.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<article>
|
||||
{{.Content}}
|
||||
</article>
|
||||
<footer>
|
||||
<a href="/">⌂ notehub</a>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
@@ -8,26 +10,31 @@ import (
|
||||
"github.com/russross/blackfriday"
|
||||
)
|
||||
|
||||
type Template struct{ templates *template.Template }
|
||||
|
||||
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
||||
return t.templates.ExecuteTemplate(w, name, data)
|
||||
}
|
||||
|
||||
func main() {
|
||||
e := echo.New()
|
||||
|
||||
e.Renderer = &Template{templates: template.Must(template.ParseGlob("assets/templates/*.html"))}
|
||||
e.Static("/", "assets/public")
|
||||
|
||||
e.GET("/Demo.md", func(c echo.Context) error { return c.String(http.StatusOK, mdPage(c, "Demo")) })
|
||||
e.GET("/TOS.md", func(c echo.Context) error { return c.String(http.StatusOK, mdPage(c, "TOS")) })
|
||||
|
||||
e.GET("/", func(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "Hello, World!")
|
||||
})
|
||||
e.GET("/TOS.md", func(c echo.Context) error { return c.Render(http.StatusOK, "Page", md2html(c, "TOS")) })
|
||||
e.Logger.Fatal(e.Start(":3000"))
|
||||
}
|
||||
|
||||
func mdPage(c echo.Context, name string) string {
|
||||
type Note struct {
|
||||
ID, Title string
|
||||
Content template.HTML
|
||||
}
|
||||
|
||||
func md2html(c echo.Context, name string) *Note {
|
||||
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 ""
|
||||
return nil
|
||||
}
|
||||
return string(blackfriday.Run(mdContent))
|
||||
return &Note{Content: template.HTML(string(blackfriday.Run(mdContent)))}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user