From 13ec9b207fdd563bedb1ce868c601ffd2feaa829 Mon Sep 17 00:00:00 2001 From: jacobhartmann Date: Sun, 19 Nov 2017 15:02:18 +0100 Subject: [PATCH] has function about and past pages now --- about.tmpl | 5 +++++ blog.tmpl | 14 +++++++++++--- past.tmpl | 9 +++++++++ postCollection.go | 5 ----- style.tmpl | 24 +++++++++++++++++++++++- websiteTemplate.go | 43 ++++++++++++++++++++++++++++++------------- 6 files changed, 78 insertions(+), 22 deletions(-) create mode 100644 about.tmpl create mode 100644 past.tmpl diff --git a/about.tmpl b/about.tmpl new file mode 100644 index 0000000..bef773d --- /dev/null +++ b/about.tmpl @@ -0,0 +1,5 @@ +{{define "about"}} +
+

This is about ME!

+
+{{end}} diff --git a/blog.tmpl b/blog.tmpl index ae30ad6..3999e2e 100644 --- a/blog.tmpl +++ b/blog.tmpl @@ -8,7 +8,7 @@ -

{{.Title}}

+

{{.Title}}

Develop games, play games, talk games

@@ -18,7 +18,15 @@ {{else}}
no rows
{{end}} -
{{template "content" .}}
+
+ {{if eq .CurrentPage "blog"}} +
{{template "content" .}}
+ {{else if eq .CurrentPage "about"}} +
{{template "about" .}}
+ {{else if eq .CurrentPage "past"}} +
{{template "past" .}}
+ {{end}} +
-{{end}} \ No newline at end of file +{{end}} diff --git a/past.tmpl b/past.tmpl new file mode 100644 index 0000000..4e82bff --- /dev/null +++ b/past.tmpl @@ -0,0 +1,9 @@ +{{define "past"}} +
+ +
+{{end}} diff --git a/postCollection.go b/postCollection.go index 56a9375..f45b9b9 100644 --- a/postCollection.go +++ b/postCollection.go @@ -84,10 +84,6 @@ func newPost(path string, f os.FileInfo, err error) error { } postsCollection = insertPostAccordingToDate(p, postsCollection) - fmt.Println(len(postsCollection)) - for _, d := range postsCollection { - fmt.Println("dates are ", d.Date) - } return nil } @@ -133,7 +129,6 @@ func getPostByURLTitle(title string) Post { } func insertPostAccordingToDate(post Post, arr []Post) []Post { - fmt.Println(post.Title) for i, p := range arr { if p.Date.After(post.Date) { s := make([]Post, len(arr)+1, cap(arr)+1) diff --git a/style.tmpl b/style.tmpl index 02fef10..a8eca48 100644 --- a/style.tmpl +++ b/style.tmpl @@ -8,6 +8,10 @@ html, body { background-color: #506692; } +.title:hover { + background-color: #687fad; +} + article { margin-right: auto; margin-left: auto; @@ -49,6 +53,16 @@ p { text-indent: 25px; } +a { + class="no-link" + text-decoration: none; + color: inherit +} + +a:hover { + background-color: #ffffff; +} + img { max-width: 500px; } @@ -72,6 +86,10 @@ ul { padding: 20px; } +.menuElement:hover { + background-color: #687fad; +} + #menu ul{ float: center; text-align: center; @@ -79,4 +97,8 @@ ul { } #menu li{ display: inline-block; -}{{end}} \ No newline at end of file +} + + + +{{end}} diff --git a/websiteTemplate.go b/websiteTemplate.go index ca649f7..cff301f 100644 --- a/websiteTemplate.go +++ b/websiteTemplate.go @@ -10,22 +10,30 @@ import ( //Page : Is exported to PostCollection type Page struct { - Title string - MenuItems []string - Posts []Post + Title string + MenuItems []template.HTML + Posts []Post + CurrentPage string } +var style = `` var name = "takunomi" var posts []Post -var sections = []string{"about", "past", "contact"} -var templates = template.Must(template.ParseFiles("blog.tmpl", "blog_roll.tmpl", "style.tmpl", "post.tmpl")) +var sections = []template.HTML{ + `about`, + `past`, + `contact`, +} +var templates = template.Must(template.ParseFiles("blog.tmpl", "about.tmpl", "past.tmpl", "blog_roll.tmpl", "style.tmpl", "post.tmpl")) func main() { NewPostsCollection() - http.HandleFunc("/", blogHandler) + http.HandleFunc("/about/", aboutHandler) + http.HandleFunc("/past/", pastHandler) http.HandleFunc("/post/", postHandler) + http.HandleFunc("/", blogHandler) if os.Args[1] == "local" { http.ListenAndServe(":8080", nil) @@ -50,22 +58,31 @@ func blogHandler(w http.ResponseWriter, req *http.Request) { return } posts = getNewestPosts(3) - page := Page{name, sections, posts} + page := Page{name, sections, posts, "blog"} renderTemplates(w, page) } func postHandler(w http.ResponseWriter, r *http.Request) { title := strings.TrimPrefix(r.URL.Path, "/post/") posts := []Post{getPostByURLTitle(title)} - page := Page{name, sections, posts} + page := Page{name, sections, posts, "blog"} + renderTemplates(w, page) +} + +func aboutHandler(w http.ResponseWriter, r *http.Request) { + page := Page{name, sections, []Post{}, "about"} + renderTemplates(w, page) +} + +func pastHandler(w http.ResponseWriter, r *http.Request) { + page := Page{name, sections, posts, "past"} renderTemplates(w, page) } func renderTemplates(w http.ResponseWriter, p Page) { s1 := templates.Lookup("blog.tmpl") - s1.ExecuteTemplate(w, "blog", p) - s2 := templates.Lookup("blog_roll.tmpl") - s2.ExecuteTemplate(w, "blog_roll", nil) - s3 := templates.Lookup("post.tmpl") - s3.ExecuteTemplate(w, "post", nil) + err := s1.ExecuteTemplate(w, "blog", p) + if err != nil { + fmt.Println("error is ", err) + } }