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