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