Added static "blog" pages

Fixed some minor bugs
Added cors
This commit is contained in:
Caleb Gardner
2024-08-06 22:10:25 -05:00
parent 65a1834e9d
commit bb44e26dd4
3 changed files with 10 additions and 3 deletions
+3
View File
@@ -61,6 +61,9 @@ func blogHandle(w http.ResponseWriter, r *http.Request, blog string) {
}
func blogElement(b *blog.Blog) (out string) {
if b.StaticPage {
return b.Blog
}
out = fmt.Sprintf(blogTitle, b.ID, b.ID, b.Title)
auth, err := blogApp.GetAuthor(b)
if err == nil {
+4 -1
View File
@@ -21,14 +21,17 @@ type Blog struct {
Favicon string `json:"favicon" bson:"favicon"`
Title string `json:"title" bson:"title"`
Blog string `json:"blog" bson:"blog"`
StaticPage bool `json:"staticPage" bson:"staticPage"`
CreateTime int64 `json:"createTime" bson:"createTime"`
UpdateTime int64 `json:"updateTime" bson:"updateTime"`
}
func (b *BlogApp) ConvertBlog(blog *Blog) {
//TODO: parse BBCode/Markdown from blog
if !blog.StaticPage {
blog.Blog = b.conv.Convert(blog.Blog)
}
}
func (b *BlogApp) GetAuthor(blog *Blog) (*Author, error) {
res := b.authCol.FindOne(context.Background(), bson.M{"_id": blog.Author})
@@ -175,7 +178,7 @@ func (b *BlogApp) updateBlog(w http.ResponseWriter, r *http.Request) {
}
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}).
SetLimit(5).
SetSkip(page*5))
+2 -1
View File
@@ -57,7 +57,7 @@ func main() {
}
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 {
log.Fatal("error loading mongo keys:", err)
}
@@ -80,6 +80,7 @@ func setupBackend(mux *http.ServeMux) {
swApp,
cdrApp,
)
back.AddCorsAddress("darkstorm.tech")
if err != nil {
log.Fatal("error setting up backend:", err)
}