diff --git a/blog.tmpl b/blog.tmpl index 59f9099..ecc3186 100644 --- a/blog.tmpl +++ b/blog.tmpl @@ -25,6 +25,8 @@
{{template "about" .}}
{{else if eq .CurrentPage "past"}}
{{template "past" .}}
+ {{else if eq .CurrentPage "contact"}} +
{{template "contact" .}}
{{end}} diff --git a/contact.tmpl b/contact.tmpl new file mode 100644 index 0000000..38f6fd0 --- /dev/null +++ b/contact.tmpl @@ -0,0 +1,9 @@ +{{define "contact"}} +
+ +
+{{end}} diff --git a/past.tmpl b/past.tmpl index 4e82bff..6c78776 100644 --- a/past.tmpl +++ b/past.tmpl @@ -1,9 +1,9 @@ {{define "past"}}
-
{{end}} diff --git a/postCollection.go b/postCollection.go index f45b9b9..8c8c4f4 100644 --- a/postCollection.go +++ b/postCollection.go @@ -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 } } diff --git a/style.tmpl b/style.tmpl index 9076a00..c49c957 100644 --- a/style.tmpl +++ b/style.tmpl @@ -8,6 +8,10 @@ html, body { background-color: #506692; } +.title { + padding: 20px; +} + .title:hover { background-color: #687fad; } diff --git a/websiteTemplate.go b/websiteTemplate.go index cff301f..5fb24d1 100644 --- a/websiteTemplate.go +++ b/websiteTemplate.go @@ -24,7 +24,7 @@ var sections = []template.HTML{ `past`, `contact`, } -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)