added contact page and prettified
This commit is contained in:
parent
0dd50e9233
commit
767f6a650b
|
@ -25,6 +25,8 @@
|
|||
<div>{{template "about" .}}</div>
|
||||
{{else if eq .CurrentPage "past"}}
|
||||
<div>{{template "past" .}}</div>
|
||||
{{else if eq .CurrentPage "contact"}}
|
||||
<div>{{template "contact" .}}</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</body>
|
||||
|
|
9
contact.tmpl
Normal file
9
contact.tmpl
Normal file
|
@ -0,0 +1,9 @@
|
|||
{{define "contact"}}
|
||||
<article class="post">
|
||||
<ul style="list-style: none;">
|
||||
<li>twitter: <b>@sketchwhale</b></li>
|
||||
<li>email: <b>ohayo dot jacob at gmail</b></li>
|
||||
<li>git repo: <b>gitfub.space/ohayo-jacob</b></li>
|
||||
</ul>
|
||||
</article>
|
||||
{{end}}
|
|
@ -1,9 +1,9 @@
|
|||
{{define "past"}}
|
||||
<article class="post">
|
||||
<ul>
|
||||
<ul style="list-style: none;">
|
||||
{{with .Posts}}
|
||||
{{range .}}
|
||||
<li><a class="no-link" style="text-decoration: none; color: inherit" href="/post/{{.URLTitle}}">{{.Title}}</a></li>{{end}}{{end}}
|
||||
<li><a class="no-link" style="text-decoration: none; color: inherit" href="/post/{{.URLTitle}}"><b>{{.Title}}</b></a> - {{.NormalDate}}</li>{{end}}{{end}}
|
||||
</ul>
|
||||
</article>
|
||||
{{end}}
|
||||
|
|
|
@ -13,13 +13,15 @@ import (
|
|||
|
||||
//Post : Is exported
|
||||
type Post struct {
|
||||
Date time.Time
|
||||
Title string
|
||||
URLTitle string
|
||||
Content template.HTML
|
||||
Date time.Time
|
||||
NormalDate string
|
||||
Title string
|
||||
URLTitle string
|
||||
Content template.HTML
|
||||
}
|
||||
|
||||
const layout = "2006-01-02"
|
||||
const htmlDateLayout = "2006-01-02"
|
||||
const normalDateLayout = "02 Jan 2006"
|
||||
|
||||
var modTime time.Time
|
||||
var postsCollection []Post
|
||||
|
@ -76,8 +78,11 @@ func newPost(path string, f os.FileInfo, err error) error {
|
|||
}
|
||||
s := string(content)
|
||||
doc, _ := html.Parse(strings.NewReader(s))
|
||||
dateParsed := getDate(doc)
|
||||
dateFormatted := dateParsed.Format(normalDateLayout)
|
||||
var p = Post{
|
||||
getDate(doc),
|
||||
dateParsed,
|
||||
dateFormatted,
|
||||
title,
|
||||
strings.Replace(title, " ", "-", -1),
|
||||
template.HTML(string(content[:len(content)])),
|
||||
|
@ -94,7 +99,7 @@ func getDate(n *html.Node) time.Time {
|
|||
if n.Type == html.ElementNode && n.Data == "time" {
|
||||
for _, a := range n.Attr {
|
||||
if a.Key == "datetime" {
|
||||
t, _ = time.Parse(layout, a.Val)
|
||||
t, _ = time.Parse(htmlDateLayout, a.Val)
|
||||
return t
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,10 @@ html, body {
|
|||
background-color: #506692;
|
||||
}
|
||||
|
||||
.title {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.title:hover {
|
||||
background-color: #687fad;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ var sections = []template.HTML{
|
|||
`<a class="no-link menuElement" style="text-decoration: none; color: inherit" href=/past>past</a>`,
|
||||
`<a class="no-link menuElement" style="text-decoration: none; color: inherit" href=/contact>contact</a>`,
|
||||
}
|
||||
var templates = template.Must(template.ParseFiles("blog.tmpl", "about.tmpl", "past.tmpl", "blog_roll.tmpl", "style.tmpl", "post.tmpl"))
|
||||
var templates = template.Must(template.ParseFiles("blog.tmpl", "about.tmpl", "past.tmpl", "contact.tmpl", "blog_roll.tmpl", "style.tmpl", "post.tmpl"))
|
||||
|
||||
func main() {
|
||||
|
||||
|
@ -32,6 +32,7 @@ func main() {
|
|||
|
||||
http.HandleFunc("/about/", aboutHandler)
|
||||
http.HandleFunc("/past/", pastHandler)
|
||||
http.HandleFunc("/contact/", contactHandler)
|
||||
http.HandleFunc("/post/", postHandler)
|
||||
http.HandleFunc("/", blogHandler)
|
||||
|
||||
|
@ -79,6 +80,11 @@ func pastHandler(w http.ResponseWriter, r *http.Request) {
|
|||
renderTemplates(w, page)
|
||||
}
|
||||
|
||||
func contactHandler(w http.ResponseWriter, r *http.Request) {
|
||||
page := Page{name, sections, []Post{}, "contact"}
|
||||
renderTemplates(w, page)
|
||||
}
|
||||
|
||||
func renderTemplates(w http.ResponseWriter, p Page) {
|
||||
s1 := templates.Lookup("blog.tmpl")
|
||||
err := s1.ExecuteTemplate(w, "blog", p)
|
||||
|
|
Loading…
Reference in New Issue
Block a user