Update main.go
This commit is contained in:
@@ -18,13 +18,12 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
markdown "github.com/markdownit/markdown-it-go"
|
"github.com/gomarkdown/markdown"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
sessionStore *sessions.CookieStore
|
sessionStore *sessions.CookieStore
|
||||||
markdownParser *markdown.MarkdownIt
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Models
|
// Models
|
||||||
@@ -71,9 +70,6 @@ func init() {
|
|||||||
// Load environment variables
|
// Load environment variables
|
||||||
godotenv.Load()
|
godotenv.Load()
|
||||||
|
|
||||||
// Initialize markdown parser
|
|
||||||
markdownParser = markdown.New()
|
|
||||||
|
|
||||||
// Initialize session store
|
// Initialize session store
|
||||||
sessionStore = sessions.NewCookieStore([]byte(getEnv("SESSION_KEY", "dev-session-key")))
|
sessionStore = sessions.NewCookieStore([]byte(getEnv("SESSION_KEY", "dev-session-key")))
|
||||||
}
|
}
|
||||||
@@ -250,7 +246,7 @@ func handleViewPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render markdown
|
// Render markdown
|
||||||
post.Content = markdownParser.Render(post.Content)
|
post.Content = string(markdown.ToHTML([]byte(post.Content), nil, nil))
|
||||||
|
|
||||||
// Get tags
|
// Get tags
|
||||||
tagRows, _ := db.Query("SELECT tag FROM tags WHERE post_id = ?", post.ID)
|
tagRows, _ := db.Query("SELECT tag FROM tags WHERE post_id = ?", post.ID)
|
||||||
|
|||||||
Reference in New Issue
Block a user