Compare commits

..

8 Commits

Author SHA1 Message Date
ed1d456912 Merge branch 'devel' into feature/id-for-hmtl-headers 2025-02-13 17:41:19 +01:00
7cc4ef3d48 merge upstream 2025-02-13 17:39:39 +01:00
547c9a5567 revert variable name 2025-02-13 17:29:01 +01:00
ed9c002b67 Update version number 2025-02-12 17:29:04 +01:00
6567c34834 Fix bug in db.GetAllArticles 2025-02-12 17:27:56 +01:00
f9e16c7c36 make headers id great again 2025-02-10 23:58:39 +01:00
351a1d2f77 merge upstream 2025-02-10 23:46:40 +01:00
faa69ed9a9 merge upstream 2025-02-09 22:35:41 +01:00
4 changed files with 37 additions and 4 deletions

View File

@ -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)
}

View File

@ -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",
}
}

View File

@ -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

View File

@ -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