forked from jason/cpolis
Store article content outside of DB and convert and serve on request from respective file
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
b "streifling.com/jason/cpolis/cmd/backend"
|
||||
@ -30,6 +31,24 @@ func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprint(w, article.Content)
|
||||
if !article.Published {
|
||||
return
|
||||
}
|
||||
|
||||
contentBytes, err := os.ReadFile(article.Link)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
content, err := b.ConvertToHTML(string(contentBytes))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprint(w, content)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user