Added static "blog" pages
Fixed some minor bugs Added cors
This commit is contained in:
@@ -61,6 +61,9 @@ func blogHandle(w http.ResponseWriter, r *http.Request, blog string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func blogElement(b *blog.Blog) (out string) {
|
func blogElement(b *blog.Blog) (out string) {
|
||||||
|
if b.StaticPage {
|
||||||
|
return b.Blog
|
||||||
|
}
|
||||||
out = fmt.Sprintf(blogTitle, b.ID, b.ID, b.Title)
|
out = fmt.Sprintf(blogTitle, b.ID, b.ID, b.Title)
|
||||||
auth, err := blogApp.GetAuthor(b)
|
auth, err := blogApp.GetAuthor(b)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -21,13 +21,16 @@ type Blog struct {
|
|||||||
Favicon string `json:"favicon" bson:"favicon"`
|
Favicon string `json:"favicon" bson:"favicon"`
|
||||||
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"`
|
||||||
CreateTime int64 `json:"createTime" bson:"createTime"`
|
CreateTime int64 `json:"createTime" bson:"createTime"`
|
||||||
UpdateTime int64 `json:"updateTime" bson:"updateTime"`
|
UpdateTime int64 `json:"updateTime" bson:"updateTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlogApp) ConvertBlog(blog *Blog) {
|
func (b *BlogApp) ConvertBlog(blog *Blog) {
|
||||||
//TODO: parse BBCode/Markdown from blog
|
//TODO: parse BBCode/Markdown from blog
|
||||||
|
if !blog.StaticPage {
|
||||||
blog.Blog = b.conv.Convert(blog.Blog)
|
blog.Blog = b.conv.Convert(blog.Blog)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlogApp) GetAuthor(blog *Blog) (*Author, error) {
|
func (b *BlogApp) GetAuthor(blog *Blog) (*Author, error) {
|
||||||
@@ -175,7 +178,7 @@ 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{}, options.Find().
|
res, err := b.blogCol.Find(context.Background(), bson.M{"staticPage": false}, options.Find().
|
||||||
SetSort(bson.M{"createTime": 1}).
|
SetSort(bson.M{"createTime": 1}).
|
||||||
SetLimit(5).
|
SetLimit(5).
|
||||||
SetSkip(page*5))
|
SetSkip(page*5))
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupMongo(uri string) {
|
func setupMongo(uri string) {
|
||||||
mongoCert, err := tls.LoadX509KeyPair(filepath.Join(flag.Arg(0), "mongo.pem"), filepath.Join(flag.Arg(0)+"key.pem"))
|
mongoCert, err := tls.LoadX509KeyPair(filepath.Join(flag.Arg(0), "mongo.pem"), filepath.Join(flag.Arg(0), "key.pem"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("error loading mongo keys:", err)
|
log.Fatal("error loading mongo keys:", err)
|
||||||
}
|
}
|
||||||
@@ -80,6 +80,7 @@ func setupBackend(mux *http.ServeMux) {
|
|||||||
swApp,
|
swApp,
|
||||||
cdrApp,
|
cdrApp,
|
||||||
)
|
)
|
||||||
|
back.AddCorsAddress("darkstorm.tech")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("error setting up backend:", err)
|
log.Fatal("error setting up backend:", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user