forked from jason/cpolis
Compare commits
63 Commits
259a2088a8
...
feature/id
| Author | SHA1 | Date | |
|---|---|---|---|
| ed1d456912 | |||
| 7cc4ef3d48 | |||
| 547c9a5567 | |||
| ed9c002b67 | |||
| 6567c34834 | |||
| f9e16c7c36 | |||
| 351a1d2f77 | |||
| faa69ed9a9 | |||
| c13b947628 | |||
| e0fa31b7a1 | |||
| ed614026ec | |||
| 87f8786c43 | |||
| acae07b8f3 | |||
| 1b100483de | |||
| e03fd78ea9 | |||
| 370ef205a9 | |||
| d328ddb749 | |||
| 5dc5590da9 | |||
| 364112a0a4 | |||
| a38523e933 | |||
| 200672dae2 | |||
| 3d3aad88c8 | |||
| e4e43d1a83 | |||
| 737a9ec314 | |||
| 1ebe0380ee | |||
| d62d71b5d1 | |||
| b36e0ea503 | |||
| bc4d8fa37e | |||
| d2b21e7405 | |||
| e3c192359f | |||
| 46532e4c85 | |||
| c722135a56 | |||
| 887fa863bc | |||
| 74d71cfb6a | |||
| ca7e7cddd3 | |||
| 94431a2aa9 | |||
| 5b1f20c5bc | |||
| d0c566f8df | |||
| 5e586aa49a | |||
| 66b2743d3d | |||
| 3723b2b5e6 | |||
| ce788bfd50 | |||
| 230a6278cc | |||
| 42d6e0c198 | |||
| e1af2979af | |||
| f6dedc6f10 | |||
| cdf0a49550 | |||
| c3c0650210 | |||
| d077f700d8 | |||
| ec752b1c66 | |||
| 46aef4f12f | |||
| 1b29e328cf | |||
| e50cb819f3 | |||
| c32e38ca10 | |||
| d7c8c7a43a | |||
| 1cd3edc90c | |||
| 0e768c9f61 | |||
| 1fcd775cc5 | |||
| 203a1ed147 | |||
| ef1914ee5c | |||
| 084b101e31 | |||
| b2db128aa9 | |||
| 081e880fb6 |
@@ -356,12 +356,26 @@ func (db *DB) GetAllArticles() ([]*Article, error) {
|
||||
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, &article.Created, &article.BannerLink, &article.Summary, &article.Published, &article.CreatorID, &article.IssueID, &article.EditedID, &article.Clicks, &article.IsInIssue, &article.AutoGenerated, &article.UUID); err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ func newConfig() *Config {
|
||||
MaxImgWidth: 1920,
|
||||
PDFDir: "/var/www/cpolis/pdfs",
|
||||
Port: ":1664",
|
||||
Version: "v0.16.1",
|
||||
Version: "v0.16.2",
|
||||
WebDir: "/var/www/cpolis/web",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,35 @@ import (
|
||||
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"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) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := goldmark.Convert([]byte(md), &buf); err != nil {
|
||||
// Goldmark-Instanz mit GFM und aktivierter Attribute-Unterstützung initialisieren.
|
||||
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)
|
||||
}
|
||||
|
||||
// Bluemonday-Policy anpassen, sodass id-Attribute auf h1-h6 erlaubt sind.
|
||||
p := bluemonday.UGCPolicy()
|
||||
p.AllowAttrs("id").OnElements("h1", "h2", "h3", "h4", "h5", "h6")
|
||||
html := p.Sanitize(buf.String())
|
||||
|
||||
return html, nil
|
||||
|
||||
@@ -840,7 +840,7 @@ func DeleteArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFun
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.Remove(filepath.Join(c.ArticleDir, fmt.Sprint(article.UUID, ".md"))); err != nil {
|
||||
if err = os.Remove(filepath.Join(c.ArticleDir, article.UUID.String()+".md")); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user