Added draft blogs
Fixed paths
This commit is contained in:
@@ -22,6 +22,7 @@ type Blog struct {
|
|||||||
Title string `json:"title" bson:"title"`
|
Title string `json:"title" bson:"title"`
|
||||||
Blog string `json:"blog" bson:"blog"`
|
Blog string `json:"blog" bson:"blog"`
|
||||||
StaticPage bool `json:"staticPage" bson:"staticPage"`
|
StaticPage bool `json:"staticPage" bson:"staticPage"`
|
||||||
|
Draft bool `json:"draft" bson:"draft"`
|
||||||
CreateTime int64 `json:"createTime" bson:"createTime"`
|
CreateTime int64 `json:"createTime" bson:"createTime"`
|
||||||
UpdateTime int64 `json:"updateTime" bson:"updateTime"`
|
UpdateTime int64 `json:"updateTime" bson:"updateTime"`
|
||||||
}
|
}
|
||||||
@@ -47,7 +48,7 @@ func (b *BlogApp) GetAuthor(blog *Blog) (*Author, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlogApp) Blog(ID string) (*Blog, error) {
|
func (b *BlogApp) Blog(ID string) (*Blog, error) {
|
||||||
res := b.blogCol.FindOne(context.Background(), bson.M{"_id": ID})
|
res := b.blogCol.FindOne(context.Background(), bson.M{"_id": ID, "draft": false})
|
||||||
if res.Err() != nil {
|
if res.Err() != nil {
|
||||||
if res.Err() == mongo.ErrNoDocuments {
|
if res.Err() == mongo.ErrNoDocuments {
|
||||||
return nil, backend.ErrNotFound
|
return nil, backend.ErrNotFound
|
||||||
@@ -178,8 +179,8 @@ func (b *BlogApp) updateBlog(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlogApp) LatestBlogs(page int64) ([]*Blog, error) {
|
func (b *BlogApp) LatestBlogs(page int64) ([]*Blog, error) {
|
||||||
res, err := b.blogCol.Find(context.Background(), bson.M{"staticPage": false}, options.Find().
|
res, err := b.blogCol.Find(context.Background(), bson.M{"staticPage": false, "draft": false}, options.Find().
|
||||||
SetSort(bson.M{"createTime": 1}).
|
SetSort(bson.M{"createTime": -1}).
|
||||||
SetLimit(5).
|
SetLimit(5).
|
||||||
SetSkip(page*5))
|
SetSkip(page*5))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -105,14 +105,11 @@ func mainHandle(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
spl := strings.Split(path, "/")
|
spl := strings.Split(path, "/")
|
||||||
stat, err = os.Stat(filepath.Join(*webRoot, spl[0]))
|
|
||||||
if stat.IsDir() {
|
|
||||||
ind := filepath.Join(*webRoot, spl[0], "index.html")
|
ind := filepath.Join(*webRoot, spl[0], "index.html")
|
||||||
stat, err = os.Stat(ind)
|
_, err = os.Stat(ind)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
http.ServeFile(w, r, ind)
|
http.ServeFile(w, r, ind)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
blogHandle(w, r, path)
|
blogHandle(w, r, path)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user