forked from ohayo-jacob/takunomi-blog
has function about and past pages now
This commit is contained in:
parent
34edb22c65
commit
13ec9b207f
5
about.tmpl
Normal file
5
about.tmpl
Normal file
|
@ -0,0 +1,5 @@
|
|||
{{define "about"}}
|
||||
<article class="post">
|
||||
<p>This is about ME!</p>
|
||||
</article>
|
||||
{{end}}
|
12
blog.tmpl
12
blog.tmpl
|
@ -8,7 +8,7 @@
|
|||
<style>{{template "style"}}</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1><a href="/" style="text-decoration: none; color: inherit">{{.Title}}</a></h1>
|
||||
<h1><a class="title" href="/" style="text-decoration: none; color: inherit">{{.Title}}</a></h1>
|
||||
<div class="tagline">
|
||||
<p>Develop games, play games, talk games</p>
|
||||
</div>
|
||||
|
@ -18,7 +18,15 @@
|
|||
<li class="menuElement">{{ . }}</li>{{else}}<div><strong>no rows</strong></div>{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
<article class="posts">{{template "content" .}}</article>
|
||||
<div class="contents">
|
||||
{{if eq .CurrentPage "blog"}}
|
||||
<article class="posts">{{template "content" .}}</article>
|
||||
{{else if eq .CurrentPage "about"}}
|
||||
<div>{{template "about" .}}</div>
|
||||
{{else if eq .CurrentPage "past"}}
|
||||
<div>{{template "past" .}}</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
9
past.tmpl
Normal file
9
past.tmpl
Normal file
|
@ -0,0 +1,9 @@
|
|||
{{define "past"}}
|
||||
<article class="post">
|
||||
<ul>
|
||||
{{with .Posts}}
|
||||
{{range .}}
|
||||
<li><a class="no-link" style="text-decoration: none; color: inherit" href="/post/{{.URLTitle}}">{{.Title}}</a></li>{{end}}{{end}}
|
||||
</ul>
|
||||
</article>
|
||||
{{end}}
|
|
@ -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)
|
||||
|
|
24
style.tmpl
24
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}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
{{end}}
|
||||
|
|
|
@ -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{
|
||||
`<a class="no-link menuElement" style="text-decoration: none; color: inherit" href=/about>about</a>`,
|
||||
`<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"))
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user