forked from ohayo-jacob/takunomi-blog
took care of linting
This commit is contained in:
parent
59c54ed10a
commit
dfa7a280f0
|
@ -1,13 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
//Post : Is exported
|
||||
type Post struct {
|
||||
Date time.Time
|
||||
Title string
|
||||
|
@ -15,29 +16,29 @@ type Post struct {
|
|||
Content template.HTML
|
||||
}
|
||||
|
||||
var lewd string = "Lewd Interlude"
|
||||
var reveries string = "Takunomi Coffee Reveries, Vol. I"
|
||||
var romantic string = "Romantic Japanese Christmas Takunomi Saturday Recap"
|
||||
var lewd = "Lewd Interlude"
|
||||
var reveries = "Takunomi Coffee Reveries, Vol. I"
|
||||
var romantic = "Romantic Japanese Christmas Takunomi Saturday Recap"
|
||||
|
||||
func spaceToHyphen (s string) string {
|
||||
func spaceToHyphen(s string) string {
|
||||
return strings.Replace(s, " ", "-", -1)
|
||||
}
|
||||
|
||||
func setDate (year int, month time.Month, day int) time.Time {
|
||||
func setDate(year int, month time.Month, day int) time.Time {
|
||||
return time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
|
||||
}
|
||||
|
||||
func newPost (date time.Time, title string) Post {
|
||||
func newPost(date time.Time, title string) Post {
|
||||
return Post{date, title, spaceToHyphen(title), getPostContent(title)}
|
||||
}
|
||||
|
||||
var postsCollection = []Post {
|
||||
newPost (setDate(2017, time.September, 12), lewd),
|
||||
var postsCollection = []Post{
|
||||
newPost(setDate(2017, time.September, 12), lewd),
|
||||
newPost(setDate(2017, time.March, 4), reveries),
|
||||
newPost(setDate(2017, time.April, 23), romantic),
|
||||
}
|
||||
|
||||
func getPostByURLTitle (title string) Post {
|
||||
func getPostByURLTitle(title string) Post {
|
||||
for _, post := range postsCollection {
|
||||
if post.URLTitle == title {
|
||||
return post
|
||||
|
@ -46,7 +47,7 @@ func getPostByURLTitle (title string) Post {
|
|||
return Post{}
|
||||
}
|
||||
|
||||
func getPostContent (title string) template.HTML {
|
||||
func getPostContent(title string) template.HTML {
|
||||
content, err := ioutil.ReadFile("posts/" + title)
|
||||
if err != nil {
|
||||
fmt.Println(content)
|
||||
|
@ -55,7 +56,7 @@ func getPostContent (title string) template.HTML {
|
|||
return template.HTML(string(content[:len(content)]))
|
||||
}
|
||||
|
||||
func getNewestPosts (numberOfPosts int) []Post {
|
||||
func getNewestPosts(numberOfPosts int) []Post {
|
||||
var posts []Post
|
||||
for i := 0; i < numberOfPosts; i++ {
|
||||
post := postsCollection[i]
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strings"
|
||||
"os"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//Page : Is exported to PostCollection
|
||||
type Page struct {
|
||||
Title string
|
||||
MenuItems []string
|
||||
Posts []Post
|
||||
}
|
||||
|
||||
var name string = "takunomi"
|
||||
var name = "takunomi"
|
||||
var posts []Post
|
||||
var sections = []string {"about","past", "contact"}
|
||||
var sections = []string{"about", "past", "contact"}
|
||||
var templates = template.Must(template.ParseFiles("blog.tmpl", "blog_roll.tmpl", "style.tmpl", "post.tmpl"))
|
||||
|
||||
func main() {
|
||||
|
@ -32,8 +33,6 @@ func main() {
|
|||
http.ListenAndServe(":35291", nil)
|
||||
}
|
||||
|
||||
//http.ListenAndServe(":8080", nil)
|
||||
|
||||
}
|
||||
|
||||
func errorHandler(w http.ResponseWriter, req *http.Request, status int) {
|
||||
|
@ -49,18 +48,18 @@ func blogHandler(w http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
posts = getNewestPosts(3)
|
||||
page := Page {name, sections, posts}
|
||||
page := Page{name, sections, posts}
|
||||
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/")
|
||||
posts := []Post{getPostByURLTitle(title)}
|
||||
page := Page {name, sections, posts}
|
||||
page := Page{name, sections, posts}
|
||||
renderTemplates(w, page)
|
||||
}
|
||||
|
||||
func renderTemplates (w http.ResponseWriter, p Page) {
|
||||
func renderTemplates(w http.ResponseWriter, p Page) {
|
||||
s1 := templates.Lookup("blog.tmpl")
|
||||
s1.ExecuteTemplate(w, "blog", p)
|
||||
s2 := templates.Lookup("blog_roll.tmpl")
|
||||
|
@ -68,4 +67,3 @@ func renderTemplates (w http.ResponseWriter, p Page) {
|
|||
s3 := templates.Lookup("post.tmpl")
|
||||
s3.ExecuteTemplate(w, "post", nil)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user