Add separate project and build pages
This commit is contained in:
parent
68164655c9
commit
643c6ebad0
4
main.css
4
main.css
|
@ -42,8 +42,8 @@ a {
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-item a {
|
.nav-item a {
|
||||||
padding-left: 1.2em;
|
padding-left: 1.8em;
|
||||||
padding-right: 1.2em;
|
padding-right: 1.8em;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
transition: 0.3s;
|
transition: 0.3s;
|
||||||
}
|
}
|
||||||
|
|
62
main.go
62
main.go
|
@ -38,12 +38,10 @@ const HTML_HEADER = `<!doctype html5>
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
<div class="nav-wrapper">
|
<div class="nav-wrapper">
|
||||||
<div class="nav-item">
|
<div class="nav-item"><a href="/">Home</a></div>
|
||||||
<a href="/">Home</a>
|
<div class="nav-item"><a href="/projects.md">Projects</a></div>
|
||||||
</div>
|
<div class="nav-item"><a href="/builds.md">Builds</a></div>
|
||||||
<div class="nav-item">
|
<div class="nav-item"><a href="/resume/resume-KelvinLy-hardware.pdf">Resume</a></div>
|
||||||
<a href="/resume/resume-KelvinLy-hardware.pdf">Resume</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<article class="markdown-body entry-content" style="padding:2em;">
|
<article class="markdown-body entry-content" style="padding:2em;">
|
||||||
|
@ -58,32 +56,38 @@ by Kelvin Ly, source available <a href="https://github.com/cactorium/kelvinly-se
|
||||||
</body>
|
</body>
|
||||||
</html>`
|
</html>`
|
||||||
|
|
||||||
func serveMarkdown(w http.ResponseWriter, r *http.Request, path string) {
|
func serveMarkdown(w http.ResponseWriter, r *http.Request, paths ...string) {
|
||||||
if b, err := ioutil.ReadFile(path); err != nil {
|
bs := make([][]byte, 0, len(paths))
|
||||||
w.WriteHeader(404)
|
for _, path := range paths {
|
||||||
w.Write([]byte(fmt.Sprintf("file %s not found", path)))
|
if b, err := ioutil.ReadFile(path); err != nil {
|
||||||
return
|
w.WriteHeader(404)
|
||||||
} else {
|
w.Write([]byte(fmt.Sprintf("file %s not found", path)))
|
||||||
w.Header().Add("Content-Type", "text/html; charset=utf-8")
|
return
|
||||||
title := ""
|
} else {
|
||||||
if s := bytes.Index(b, []byte("# ")); s != -1 {
|
bs = append(bs, b)
|
||||||
t := b[s+2:]
|
|
||||||
if e := bytes.Index(t, []byte("\n")); e != -1 {
|
|
||||||
t = t[:e]
|
|
||||||
title = string(t)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
w.Write([]byte(fmt.Sprintf(HTML_HEADER, string(title), r.Host)))
|
}
|
||||||
|
w.Header().Add("Content-Type", "text/html; charset=utf-8")
|
||||||
|
title := ""
|
||||||
|
if s := bytes.Index(bs[0], []byte("# ")); s != -1 {
|
||||||
|
t := bs[0][s+2:]
|
||||||
|
if e := bytes.Index(t, []byte("\n")); e != -1 {
|
||||||
|
t = t[:e]
|
||||||
|
title = string(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.Write([]byte(fmt.Sprintf(HTML_HEADER, string(title), r.Host)))
|
||||||
|
for _, b := range bs {
|
||||||
html := gfm.Markdown(b)
|
html := gfm.Markdown(b)
|
||||||
w.Write(html)
|
w.Write(html)
|
||||||
w.Write([]byte(HTML_FOOTER))
|
|
||||||
}
|
}
|
||||||
|
w.Write([]byte(HTML_FOOTER))
|
||||||
}
|
}
|
||||||
|
|
||||||
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
if r.URL.Path == "/" {
|
if r.URL.Path == "/" {
|
||||||
serveMarkdown(w, r, "static/README.md")
|
serveMarkdown(w, r, "static/intro.md", "static/projects.md", "static/builds.md")
|
||||||
} else if strings.HasSuffix(r.URL.Path, ".md") {
|
} else if strings.HasSuffix(r.URL.Path, ".md") {
|
||||||
if strings.Contains(r.URL.Path, "..") {
|
if strings.Contains(r.URL.Path, "..") {
|
||||||
w.WriteHeader(403)
|
w.WriteHeader(403)
|
||||||
|
@ -116,9 +120,9 @@ func main() {
|
||||||
PidFilePerm: 0644,
|
PidFilePerm: 0644,
|
||||||
LogFileName: "/tmp/kelvinly-server-log",
|
LogFileName: "/tmp/kelvinly-server-log",
|
||||||
LogFilePerm: 0640,
|
LogFilePerm: 0640,
|
||||||
WorkDir: "/home/kelvin/kelvinly-server/",
|
//WorkDir: "/home/kelvin/kelvinly-server/",
|
||||||
//WorkDir: ".",
|
WorkDir: ".",
|
||||||
Umask: 027,
|
Umask: 027,
|
||||||
}
|
}
|
||||||
// TODO: figure out the daemonizing stuff
|
// TODO: figure out the daemonizing stuff
|
||||||
|
|
||||||
|
@ -188,11 +192,11 @@ func startServer(srv *http.Server) {
|
||||||
srv.Addr = ":8443"
|
srv.Addr = ":8443"
|
||||||
srv.Handler = serveMux
|
srv.Handler = serveMux
|
||||||
log.Print("starting server")
|
log.Print("starting server")
|
||||||
log.Fatal(srv.ListenAndServeTLS("/etc/letsencrypt/live/"+DOMAIN_NAME+"/fullchain.pem",
|
|
||||||
"/etc/letsencrypt/live/"+DOMAIN_NAME+"/privkey.pem"))
|
|
||||||
/*
|
/*
|
||||||
log.Fatal(srv.ListenAndServe())
|
log.Fatal(srv.ListenAndServeTLS("/etc/letsencrypt/live/"+DOMAIN_NAME+"/fullchain.pem",
|
||||||
|
"/etc/letsencrypt/live/"+DOMAIN_NAME+"/privkey.pem"))
|
||||||
*/
|
*/
|
||||||
|
log.Fatal(srv.ListenAndServe())
|
||||||
close(serverShutdown)
|
close(serverShutdown)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
static
2
static
|
@ -1 +1 @@
|
||||||
Subproject commit 3ca8cb6aa95f2cf76bcc2037ff601a6c377a6c0f
|
Subproject commit 872650095e73e1c2008d0e5919051c84df1e7630
|
Loading…
Reference in New Issue