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>
|
<style>{{template "style"}}</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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">
|
<div class="tagline">
|
||||||
<p>Develop games, play games, talk games</p>
|
<p>Develop games, play games, talk games</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,7 +18,15 @@
|
||||||
<li class="menuElement">{{ . }}</li>{{else}}<div><strong>no rows</strong></div>{{end}}
|
<li class="menuElement">{{ . }}</li>{{else}}<div><strong>no rows</strong></div>{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
{{end}}
|
{{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)
|
postsCollection = insertPostAccordingToDate(p, postsCollection)
|
||||||
fmt.Println(len(postsCollection))
|
|
||||||
for _, d := range postsCollection {
|
|
||||||
fmt.Println("dates are ", d.Date)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +129,6 @@ func getPostByURLTitle(title string) Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertPostAccordingToDate(post Post, arr []Post) []Post {
|
func insertPostAccordingToDate(post Post, arr []Post) []Post {
|
||||||
fmt.Println(post.Title)
|
|
||||||
for i, p := range arr {
|
for i, p := range arr {
|
||||||
if p.Date.After(post.Date) {
|
if p.Date.After(post.Date) {
|
||||||
s := make([]Post, len(arr)+1, cap(arr)+1)
|
s := make([]Post, len(arr)+1, cap(arr)+1)
|
||||||
|
|
24
style.tmpl
24
style.tmpl
|
@ -8,6 +8,10 @@ html, body {
|
||||||
background-color: #506692;
|
background-color: #506692;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.title:hover {
|
||||||
|
background-color: #687fad;
|
||||||
|
}
|
||||||
|
|
||||||
article {
|
article {
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
|
@ -49,6 +53,16 @@ p {
|
||||||
text-indent: 25px;
|
text-indent: 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
class="no-link"
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
max-width: 500px;
|
max-width: 500px;
|
||||||
}
|
}
|
||||||
|
@ -72,6 +86,10 @@ ul {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.menuElement:hover {
|
||||||
|
background-color: #687fad;
|
||||||
|
}
|
||||||
|
|
||||||
#menu ul{
|
#menu ul{
|
||||||
float: center;
|
float: center;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
@ -79,4 +97,8 @@ ul {
|
||||||
}
|
}
|
||||||
#menu li{
|
#menu li{
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}{{end}}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{{end}}
|
||||||
|
|
|
@ -10,22 +10,30 @@ import (
|
||||||
|
|
||||||
//Page : Is exported to PostCollection
|
//Page : Is exported to PostCollection
|
||||||
type Page struct {
|
type Page struct {
|
||||||
Title string
|
Title string
|
||||||
MenuItems []string
|
MenuItems []template.HTML
|
||||||
Posts []Post
|
Posts []Post
|
||||||
|
CurrentPage string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var style = ``
|
||||||
var name = "takunomi"
|
var name = "takunomi"
|
||||||
var posts []Post
|
var posts []Post
|
||||||
var sections = []string{"about", "past", "contact"}
|
var sections = []template.HTML{
|
||||||
var templates = template.Must(template.ParseFiles("blog.tmpl", "blog_roll.tmpl", "style.tmpl", "post.tmpl"))
|
`<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() {
|
func main() {
|
||||||
|
|
||||||
NewPostsCollection()
|
NewPostsCollection()
|
||||||
|
|
||||||
http.HandleFunc("/", blogHandler)
|
http.HandleFunc("/about/", aboutHandler)
|
||||||
|
http.HandleFunc("/past/", pastHandler)
|
||||||
http.HandleFunc("/post/", postHandler)
|
http.HandleFunc("/post/", postHandler)
|
||||||
|
http.HandleFunc("/", blogHandler)
|
||||||
|
|
||||||
if os.Args[1] == "local" {
|
if os.Args[1] == "local" {
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
|
@ -50,22 +58,31 @@ func blogHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
posts = getNewestPosts(3)
|
posts = getNewestPosts(3)
|
||||||
page := Page{name, sections, posts}
|
page := Page{name, sections, posts, "blog"}
|
||||||
renderTemplates(w, page)
|
renderTemplates(w, page)
|
||||||
}
|
}
|
||||||
|
|
||||||
func postHandler(w http.ResponseWriter, r *http.Request) {
|
func postHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
title := strings.TrimPrefix(r.URL.Path, "/post/")
|
title := strings.TrimPrefix(r.URL.Path, "/post/")
|
||||||
posts := []Post{getPostByURLTitle(title)}
|
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)
|
renderTemplates(w, page)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderTemplates(w http.ResponseWriter, p Page) {
|
func renderTemplates(w http.ResponseWriter, p Page) {
|
||||||
s1 := templates.Lookup("blog.tmpl")
|
s1 := templates.Lookup("blog.tmpl")
|
||||||
s1.ExecuteTemplate(w, "blog", p)
|
err := s1.ExecuteTemplate(w, "blog", p)
|
||||||
s2 := templates.Lookup("blog_roll.tmpl")
|
if err != nil {
|
||||||
s2.ExecuteTemplate(w, "blog_roll", nil)
|
fmt.Println("error is ", err)
|
||||||
s3 := templates.Lookup("post.tmpl")
|
}
|
||||||
s3.ExecuteTemplate(w, "post", nil)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user