forked from ohayo-jacob/takunomi-blog
made automatic updates possible
This commit is contained in:
parent
0773a48f2c
commit
87da73a5de
|
@ -29,20 +29,22 @@ var PostsCollection []Post
|
||||||
func NewPostsCollection() {
|
func NewPostsCollection() {
|
||||||
verifyFolderModification()
|
verifyFolderModification()
|
||||||
initializeCollection()
|
initializeCollection()
|
||||||
go acquirePosts(100)
|
go acquirePosts(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeCollection() {
|
func initializeCollection() {
|
||||||
PostsCollection = nil
|
PostsCollection = nil
|
||||||
filepath.Walk("./posts", newPost)
|
filepath.Walk("./posts", newPost)
|
||||||
|
fmt.Println(len(PostsCollection))
|
||||||
PostsCollection = reversePosts()
|
PostsCollection = reversePosts()
|
||||||
}
|
}
|
||||||
|
|
||||||
func acquirePosts(duration time.Duration) {
|
func acquirePosts(duration time.Duration) {
|
||||||
for {
|
for {
|
||||||
if verifyFolderModification() == true {
|
if verifyFolderModification() == true {
|
||||||
|
fmt.Println("updated")
|
||||||
initializeCollection()
|
initializeCollection()
|
||||||
PostsCollection = reversePosts()
|
setPostsCollection()
|
||||||
}
|
}
|
||||||
time.Sleep(duration * time.Second)
|
time.Sleep(duration * time.Second)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,8 @@ func main() {
|
||||||
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir("images"))))
|
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir("images"))))
|
||||||
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))
|
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))
|
||||||
|
|
||||||
posts = PostsCollection[:]
|
//posts = PostsCollection[:]
|
||||||
|
setPostsCollection()
|
||||||
|
|
||||||
if os.Args[1] == "local" {
|
if os.Args[1] == "local" {
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
|
@ -44,6 +45,10 @@ func main() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setPostsCollection() {
|
||||||
|
posts = PostsCollection[:]
|
||||||
|
}
|
||||||
|
|
||||||
func errorHandler(w http.ResponseWriter, req *http.Request, status int) {
|
func errorHandler(w http.ResponseWriter, req *http.Request, status int) {
|
||||||
w.WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
if status == http.StatusNotFound {
|
if status == http.StatusNotFound {
|
||||||
|
@ -57,6 +62,7 @@ func blogHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
length := len(posts)
|
length := len(posts)
|
||||||
|
fmt.Println("Hi, blog handler here. There are ", length, " posts.")
|
||||||
posts = posts[:3]
|
posts = posts[:3]
|
||||||
//posts = getNewestPosts(3)
|
//posts = getNewestPosts(3)
|
||||||
page := Page{name, posts, "blog"}
|
page := Page{name, posts, "blog"}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user