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() {
|
||||
verifyFolderModification()
|
||||
initializeCollection()
|
||||
go acquirePosts(100)
|
||||
go acquirePosts(10)
|
||||
}
|
||||
|
||||
func initializeCollection() {
|
||||
PostsCollection = nil
|
||||
filepath.Walk("./posts", newPost)
|
||||
fmt.Println(len(PostsCollection))
|
||||
PostsCollection = reversePosts()
|
||||
}
|
||||
|
||||
func acquirePosts(duration time.Duration) {
|
||||
for {
|
||||
if verifyFolderModification() == true {
|
||||
fmt.Println("updated")
|
||||
initializeCollection()
|
||||
PostsCollection = reversePosts()
|
||||
setPostsCollection()
|
||||
}
|
||||
time.Sleep(duration * time.Second)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ func main() {
|
|||
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir("images"))))
|
||||
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))
|
||||
|
||||
posts = PostsCollection[:]
|
||||
//posts = PostsCollection[:]
|
||||
setPostsCollection()
|
||||
|
||||
if os.Args[1] == "local" {
|
||||
http.ListenAndServe(":8080", nil)
|
||||
|
@ -44,6 +45,10 @@ func main() {
|
|||
|
||||
}
|
||||
|
||||
func setPostsCollection() {
|
||||
posts = PostsCollection[:]
|
||||
}
|
||||
|
||||
func errorHandler(w http.ResponseWriter, req *http.Request, status int) {
|
||||
w.WriteHeader(status)
|
||||
if status == http.StatusNotFound {
|
||||
|
@ -57,6 +62,7 @@ func blogHandler(w http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
length := len(posts)
|
||||
fmt.Println("Hi, blog handler here. There are ", length, " posts.")
|
||||
posts = posts[:3]
|
||||
//posts = getNewestPosts(3)
|
||||
page := Page{name, posts, "blog"}
|
||||
|
|
Loading…
Reference in New Issue
Block a user