forked from jason/cpolis
Compare commits
1 Commits
feature/id
...
v0.16.0
Author | SHA1 | Date | |
---|---|---|---|
5afd6b771a |
@ -345,47 +345,6 @@ func (db *DB) DeleteArticle(id int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetAllArticles() ([]*Article, error) {
|
|
||||||
query := `
|
|
||||||
SELECT title, created, banner_link, summary, published, creator_id, issue_id, edited_id, clicks, is_in_issue, auto_generated, uuid
|
|
||||||
FROM articles
|
|
||||||
`
|
|
||||||
|
|
||||||
rows, err := db.Query(query)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error querying DB: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var created []byte
|
|
||||||
var uuidString string
|
|
||||||
|
|
||||||
articles := make([]*Article, 0)
|
|
||||||
for rows.Next() {
|
|
||||||
article := new(Article)
|
|
||||||
if err = rows.Scan(&article.Title, &created, &article.BannerLink, &article.Summary, &article.Published, &article.CreatorID, &article.IssueID, &article.EditedID, &article.Clicks, &article.IsInIssue, &article.AutoGenerated, &uuidString); err != nil {
|
|
||||||
return nil, fmt.Errorf("error scanning rows: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
article.Created, err = time.Parse("2006-01-02 15:04:05", string(created))
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error parsing created: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
article.UUID, err = uuid.Parse(uuidString)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error parsing uuid: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
articles = append(articles, article)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := rows.Err(); err != nil {
|
|
||||||
return nil, fmt.Errorf("error iterating over rows: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return articles, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func WriteArticleToFile(c *Config, articleUUID uuid.UUID, content []byte) error {
|
func WriteArticleToFile(c *Config, articleUUID uuid.UUID, content []byte) error {
|
||||||
articlePath := filepath.Join(c.ArticleDir, fmt.Sprint(articleUUID, ".md"))
|
articlePath := filepath.Join(c.ArticleDir, fmt.Sprint(articleUUID, ".md"))
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ func newConfig() *Config {
|
|||||||
MaxImgWidth: 1920,
|
MaxImgWidth: 1920,
|
||||||
PDFDir: "/var/www/cpolis/pdfs",
|
PDFDir: "/var/www/cpolis/pdfs",
|
||||||
Port: ":1664",
|
Port: ":1664",
|
||||||
Version: "v0.16.2",
|
Version: "v0.16.0",
|
||||||
WebDir: "/var/www/cpolis/web",
|
WebDir: "/var/www/cpolis/web",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,20 +56,7 @@ func checkImageUsage(c *Config, db *DB, name string) (bool, error) {
|
|||||||
|
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
if name == user.ProfilePicLink {
|
if name == user.ProfilePicLink {
|
||||||
imageWasFound = true
|
return true, nil
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !imageWasFound {
|
|
||||||
articles, err := db.GetAllArticles()
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("error getting all articles: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, article := range articles {
|
|
||||||
if name == article.BannerLink {
|
|
||||||
imageWasFound = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,35 +6,16 @@ import (
|
|||||||
|
|
||||||
"github.com/microcosm-cc/bluemonday"
|
"github.com/microcosm-cc/bluemonday"
|
||||||
"github.com/yuin/goldmark"
|
"github.com/yuin/goldmark"
|
||||||
"github.com/yuin/goldmark/extension"
|
|
||||||
"github.com/yuin/goldmark/parser"
|
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConvertToHTML(md string) (string, error) {
|
func ConvertToHTML(md string) (string, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
||||||
// Goldmark-Instanz mit GFM und aktivierter Attribute-Unterstützung initialisieren.
|
if err := goldmark.Convert([]byte(md), &buf); err != nil {
|
||||||
gm := goldmark.New(
|
|
||||||
goldmark.WithExtensions(
|
|
||||||
extension.GFM,
|
|
||||||
),
|
|
||||||
goldmark.WithParserOptions(
|
|
||||||
parser.WithAttribute(),
|
|
||||||
),
|
|
||||||
goldmark.WithRendererOptions(
|
|
||||||
html.WithUnsafe(), // Falls du HTML-Inhalte erlauben möchtest
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Markdown in HTML konvertieren.
|
|
||||||
if err := gm.Convert([]byte(md), &buf); err != nil {
|
|
||||||
return "", fmt.Errorf("error converting markdown to html: %v", err)
|
return "", fmt.Errorf("error converting markdown to html: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bluemonday-Policy anpassen, sodass id-Attribute auf h1-h6 erlaubt sind.
|
|
||||||
p := bluemonday.UGCPolicy()
|
p := bluemonday.UGCPolicy()
|
||||||
p.AllowAttrs("id").OnElements("h1", "h2", "h3", "h4", "h5", "h6")
|
|
||||||
html := p.Sanitize(buf.String())
|
html := p.Sanitize(buf.String())
|
||||||
|
|
||||||
return html, nil
|
return html, nil
|
||||||
|
@ -840,7 +840,7 @@ func DeleteArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFun
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.Remove(filepath.Join(c.ArticleDir, article.UUID.String()+".md")); err != nil {
|
if err = os.Remove(filepath.Join(c.ArticleDir, fmt.Sprint(article.UUID, ".md"))); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user