Compare commits
9 Commits
d62c5a4078
...
8dc8f02504
Author | SHA1 | Date | |
---|---|---|---|
8dc8f02504 | |||
e3ce1d7b55 | |||
532bc6490a | |||
84fa828b38 | |||
a3c53b1b20 | |||
ca70fa6d4d | |||
972b8cac19 | |||
d0605660f7 | |||
5d2d841aba |
@ -107,7 +107,7 @@ func GenerateRSS(db *model.DB, title, link, desc string) (*string, error) {
|
||||
|
||||
feed := rss.NewFeed()
|
||||
feed.Channels = append(feed.Channels, channel)
|
||||
rss, err := feed.ToXML()
|
||||
rss, err := feed.ToXML("UTF-8")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting RSS feed to XML: %v", err)
|
||||
}
|
||||
|
52
cmd/main.go
52
cmd/main.go
@ -49,36 +49,30 @@ func main() {
|
||||
http.FileServer(http.Dir(args.WebDir+"/static/"))))
|
||||
mux.HandleFunc("/", view.HomePage(args, db, store))
|
||||
|
||||
mux.HandleFunc("GET /create-tag/", view.CreateTag(args))
|
||||
mux.HandleFunc("GET /create-user/", view.CreateUser(args))
|
||||
mux.HandleFunc("GET /edit-user/", view.EditUser(args, db, store))
|
||||
mux.HandleFunc("GET /hub/", view.ShowHub(args, db, store))
|
||||
mux.HandleFunc("GET /logout/", view.Logout(args, store))
|
||||
mux.HandleFunc("GET /publish-article/{id}/", view.PublishArticle(args, db, store))
|
||||
mux.HandleFunc("GET /publish-issue/", view.PublishLatestIssue(args, db, store))
|
||||
mux.HandleFunc("GET /reject-article/{id}/", view.RejectArticle(args, db, store))
|
||||
mux.HandleFunc("GET /rejected-articles/", view.ShowRejectedArticles(args, db, store))
|
||||
mux.HandleFunc("GET /review-rejected-article/{id}/", view.ReviewRejectedArticle(args, db, store))
|
||||
mux.HandleFunc("GET /review-unpublished-article/{id}/", view.ReviewUnpublishedArticle(args, db, store))
|
||||
mux.HandleFunc("GET /rss/", view.ShowRSS(
|
||||
args,
|
||||
db,
|
||||
"Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
|
||||
"https://distrikt-ni-st.de",
|
||||
"Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität",
|
||||
))
|
||||
mux.HandleFunc("GET /this-issue/", view.ShowCurrentArticles(args, db))
|
||||
mux.HandleFunc("GET /unpublished-articles/", view.ShowUnpublishedArticles(args, db))
|
||||
mux.HandleFunc("GET /write-article/", view.WriteArticle(args, db))
|
||||
mux.HandleFunc("GET /create-tag", view.CreateTag(args))
|
||||
mux.HandleFunc("GET /create-user", view.CreateUser(args))
|
||||
mux.HandleFunc("GET /edit-user", view.EditUser(args, db, store))
|
||||
mux.HandleFunc("GET /hub", view.ShowHub(args, db, store))
|
||||
mux.HandleFunc("GET /logout", view.Logout(args, store))
|
||||
mux.HandleFunc("GET /publish-article/{id}", view.PublishArticle(args, db, store))
|
||||
mux.HandleFunc("GET /publish-issue", view.PublishLatestIssue(args, db, store))
|
||||
mux.HandleFunc("GET /reject-article/{id}", view.RejectArticle(args, db, store))
|
||||
mux.HandleFunc("GET /rejected-articles", view.ShowRejectedArticles(args, db, store))
|
||||
mux.HandleFunc("GET /review-rejected-article/{id}", view.ReviewRejectedArticle(args, db, store))
|
||||
mux.HandleFunc("GET /review-unpublished-article/{id}", view.ReviewUnpublishedArticle(args, db, store))
|
||||
mux.HandleFunc("GET /rss", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, args.RSSFile) })
|
||||
mux.HandleFunc("GET /this-issue", view.ShowCurrentArticles(args, db))
|
||||
mux.HandleFunc("GET /unpublished-articles", view.ShowUnpublishedArticles(args, db))
|
||||
mux.HandleFunc("GET /write-article", view.WriteArticle(args, db))
|
||||
|
||||
mux.HandleFunc("POST /add-first-user/", view.AddFirstUser(args, db, store))
|
||||
mux.HandleFunc("POST /add-tag/", view.AddTag(args, db, store))
|
||||
mux.HandleFunc("POST /add-user/", view.AddUser(args, db, store))
|
||||
mux.HandleFunc("POST /login/", view.Login(args, db, store))
|
||||
mux.HandleFunc("POST /resubmit-article/{id}/", view.ResubmitArticle(args, db, store))
|
||||
mux.HandleFunc("POST /submit-article/", view.SubmitArticle(args, db, store))
|
||||
mux.HandleFunc("POST /update-user/", view.UpdateUser(args, db, store))
|
||||
mux.HandleFunc("POST /upload-image/", view.UploadImage(args))
|
||||
mux.HandleFunc("POST /add-first-user", view.AddFirstUser(args, db, store))
|
||||
mux.HandleFunc("POST /add-tag", view.AddTag(args, db, store))
|
||||
mux.HandleFunc("POST /add-user", view.AddUser(args, db, store))
|
||||
mux.HandleFunc("POST /login", view.Login(args, db, store))
|
||||
mux.HandleFunc("POST /resubmit-article/{id}", view.ResubmitArticle(args, db, store))
|
||||
mux.HandleFunc("POST /submit-article", view.SubmitArticle(args, db, store))
|
||||
mux.HandleFunc("POST /update-user", view.UpdateUser(args, db, store))
|
||||
mux.HandleFunc("POST /upload-image", view.UploadImage(args))
|
||||
|
||||
log.Fatalln(http.ListenAndServe(args.Port, mux))
|
||||
}
|
||||
|
@ -1,95 +0,0 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.streifling.com/jason/rss"
|
||||
"streifling.com/jason/cpolis/cmd/control"
|
||||
"streifling.com/jason/cpolis/cmd/model"
|
||||
)
|
||||
|
||||
func ShowRSS(c *control.CliArgs, db *model.DB, title, link, desc string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
channel := &rss.Channel{
|
||||
Title: title,
|
||||
Link: link,
|
||||
Description: desc,
|
||||
Items: make([]*rss.Item, 0),
|
||||
}
|
||||
|
||||
articles, err := db.GetCertainArticles(true, false)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for _, article := range articles {
|
||||
tags, err := db.GetArticleTags(article.ID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
tagNames := make([]string, 0)
|
||||
for _, tag := range tags {
|
||||
tagNames = append(tagNames, tag.Name)
|
||||
}
|
||||
tagNames = append(tagNames, fmt.Sprint("Orient Express ", article.IssueID))
|
||||
|
||||
user, err := db.GetUser(article.AuthorID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
articleTitle, err := control.ConvertToPlain(article.Title)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
articleDescription, err := control.ConvertToPlain(article.Description)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
articleContent, err := control.ConvertToHTML(article.Content)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
channel.Items = append(channel.Items, &rss.Item{
|
||||
Title: articleTitle,
|
||||
Author: user.FirstName + user.LastName,
|
||||
PubDate: article.Created.Format(time.RFC1123Z),
|
||||
Description: articleDescription,
|
||||
Content: &rss.Content{Value: articleContent},
|
||||
Categories: tagNames,
|
||||
})
|
||||
}
|
||||
|
||||
feed := rss.NewFeed()
|
||||
feed.Channels = append(feed.Channels, channel)
|
||||
rss, err := feed.ToXML()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
files := []string{c.WebDir + "/templates/index.html", c.WebDir + "/templates/feed.rss"}
|
||||
tmpl, err := template.ParseFiles(files...)
|
||||
template.Must(tmpl, err).Execute(w, rss)
|
||||
}
|
||||
}
|
@ -37,7 +37,7 @@ CREATE TABLE articles (
|
||||
|
||||
CREATE TABLE tags (
|
||||
id INT AUTO_INCREMENT,
|
||||
name VARCHAR(15) NOT NULL UNIQUE,
|
||||
name VARCHAR(50) NOT NULL UNIQUE,
|
||||
PRIMARY KEY(id)
|
||||
);
|
||||
|
||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module streifling.com/jason/cpolis
|
||||
go 1.22.0
|
||||
|
||||
require (
|
||||
git.streifling.com/jason/rss v0.0.0-20240305164907-524bf9676188
|
||||
git.streifling.com/jason/rss v0.1.2
|
||||
github.com/go-sql-driver/mysql v1.7.1
|
||||
github.com/gorilla/sessions v1.2.2
|
||||
github.com/microcosm-cc/bluemonday v1.0.26
|
||||
|
4
go.sum
4
go.sum
@ -1,5 +1,5 @@
|
||||
git.streifling.com/jason/rss v0.0.0-20240305164907-524bf9676188 h1:C8M/j3f+cl5Y7YfGpU/ynb/SC/4tTYMDsyGFt3rswM8=
|
||||
git.streifling.com/jason/rss v0.0.0-20240305164907-524bf9676188/go.mod h1:gpZF0nZbQSstMpyHD9DTAvlQEG7v4pjO5c7aIMWM4Jg=
|
||||
git.streifling.com/jason/rss v0.1.2 h1:UB3UHJXMt5WDDh9y8n0Z6nS1XortbPXjEr7QZTdovY4=
|
||||
git.streifling.com/jason/rss v0.1.2/go.mod h1:gpZF0nZbQSstMpyHD9DTAvlQEG7v4pjO5c7aIMWM4Jg=
|
||||
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||
|
@ -4,8 +4,8 @@
|
||||
<form>
|
||||
<input required name="tag" placeholder="Tag eingeben" type="text" />
|
||||
<div class="btn-area">
|
||||
<input class="action-btn" type="submit" value="Anlegen" hx-post="/add-tag/" hx-target="#page-content" />
|
||||
<button class="btn" hx-get="/hub/" hx-target="#page-content">Abbrechen</button>
|
||||
<input class="action-btn" type="submit" value="Anlegen" hx-post="/add-tag" hx-target="#page-content" />
|
||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
@ -44,8 +44,8 @@
|
||||
</div>
|
||||
|
||||
<div class="btn-area">
|
||||
<input class="action-btn" type="submit" value="Anlegen" hx-post="/add-user/" hx-target="#page-content" />
|
||||
<button class="btn" hx-get="/hub/" hx-target="#page-content">Abbrechen</button>
|
||||
<input class="action-btn" type="submit" value="Anlegen" hx-post="/add-user" hx-target="#page-content" />
|
||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
</div>
|
||||
|
||||
<div class="btn-area">
|
||||
<button class="action-btn" hx-get="/publish-issue/" hx-target="#page-content">Ausgabe publizieren</button>
|
||||
<button class="btn" hx-get="/hub/" hx-target="#page-content">Abbrechen</button>
|
||||
<button class="action-btn" hx-get="/publish-issue" hx-target="#page-content">Ausgabe publizieren</button>
|
||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -28,9 +28,9 @@
|
||||
</div>
|
||||
|
||||
<div class="btn-area">
|
||||
<input class="action-btn" type="submit" value="Aktualisieren" hx-post="/update-user/"
|
||||
<input class="action-btn" type="submit" value="Aktualisieren" hx-post="/update-user"
|
||||
hx-target="#page-content" />
|
||||
<button class="btn" hx-get="/hub/" hx-target="#page-content">Abbrechen</button>
|
||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||
</div>
|
||||
</form>
|
||||
{{end}}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
<div>
|
||||
<span>Tags</span>
|
||||
<div class="flex gap-4">
|
||||
<div class="flex flex-wrap gap-x-4">
|
||||
{{range .}}
|
||||
<div>
|
||||
<input id="{{.Name}}" name="tags" type="checkbox" value="{{.ID}}" />
|
||||
@ -27,13 +27,13 @@
|
||||
</div>
|
||||
|
||||
<div id="editor-images">
|
||||
<input class="mb-2" name="article-image" type="file" hx-encoding="multipart/form-data" hx-post="/upload-image/"
|
||||
<input class="mb-2" name="article-image" type="file" hx-encoding="multipart/form-data" hx-post="/upload-image"
|
||||
hx-swap="beforeend" hx-target="#editor-images" />
|
||||
</div>
|
||||
|
||||
<div class="btn-area">
|
||||
<input class="action-btn" type="submit" value="Senden" hx-post="/submit-article/" hx-target="#page-content" />
|
||||
<button class="btn" hx-get="/hub/" hx-target="#page-content">Abbrechen</button>
|
||||
<input class="action-btn" type="submit" value="Senden" hx-post="/submit-article" hx-target="#page-content" />
|
||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
</div>
|
||||
|
||||
<div class="btn-area">
|
||||
<input class="action-btn" type="submit" value="Anlegen" hx-post="/add-first-user/" hx-target="#page-content" />
|
||||
<input class="action-btn" type="submit" value="Anlegen" hx-post="/add-first-user" hx-target="#page-content" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
{{define "page-content"}}
|
||||
<div class="flex flex-col gap-4">
|
||||
<button class="btn" hx-get="/logout/" hx-target="#page-content">Abmelden</button>
|
||||
<button class="btn" hx-get="/logout" hx-target="#page-content">Abmelden</button>
|
||||
|
||||
<div class="mb-3">
|
||||
<h2>Autor</h2>
|
||||
<div class="grid grid-cols-2 gap-x-4 gap-y-2">
|
||||
<button class="btn" hx-get="/write-article/" hx-target="#page-content">Artikel schreiben</button>
|
||||
<button class="btn" hx-get="/rejected-articles/" hx-target="#page-content">Abgelehnte Artikel</button>
|
||||
<button class="btn" hx-get="/rss/" hx-target="#page-content">RSS Feed</button>
|
||||
<button class="btn" hx-get="/edit-user/" hx-target="#page-content">Benutzer bearbeiten</button>
|
||||
<button class="btn" hx-get="/write-article" hx-target="#page-content">Artikel schreiben</button>
|
||||
<button class="btn" hx-get="/rejected-articles" hx-target="#page-content">Abgelehnte Artikel</button>
|
||||
<a class="btn text-center" href="/rss">RSS Feed</a>
|
||||
<button class="btn" hx-get="/edit-user" hx-target="#page-content">Benutzer bearbeiten</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -16,10 +16,10 @@
|
||||
<div class="mb-3">
|
||||
<h2>Redakteur</h2>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<button class="btn" hx-get="/unpublished-articles/" hx-target="#page-content">
|
||||
<button class="btn" hx-get="/unpublished-articles" hx-target="#page-content">
|
||||
Unveröffentlichte Artikel
|
||||
</button>
|
||||
<button class="btn" hx-get="/create-tag/" hx-target="#page-content">Neuer Tag</button>
|
||||
<button class="btn" hx-get="/create-tag" hx-target="#page-content">Neuer Tag</button>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
@ -28,7 +28,7 @@
|
||||
<div class="mb-3">
|
||||
<h2>Herausgeber</h2>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<button class="btn" hx-get="/this-issue/" hx-target="#page-content">Diese Ausgabe</button>
|
||||
<button class="btn" hx-get="/this-issue" hx-target="#page-content">Diese Ausgabe</button>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
@ -37,7 +37,7 @@
|
||||
<div class="mb-3">
|
||||
<h2>Administrator</h2>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<button class="btn" hx-get="/create-user/" hx-target="#page-content">Benutzer hinzufügen</button>
|
||||
<button class="btn" hx-get="/create-user" hx-target="#page-content">Benutzer hinzufügen</button>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -6,6 +6,6 @@
|
||||
<input class="w-full" name="password" placeholder="Passwort" type="password" />
|
||||
</div>
|
||||
|
||||
<input class="action-btn" type="submit" value="Anmelden" hx-post="/login/" hx-target="#page-content" />
|
||||
<input class="action-btn" type="submit" value="Anmelden" hx-post="/login" hx-target="#page-content" />
|
||||
</form>
|
||||
{{end}}
|
||||
|
@ -2,13 +2,13 @@
|
||||
<div class="flex flex-col gap-4">
|
||||
{{range .RejectedArticles}}
|
||||
{{if index $.MyIDs .ID}}
|
||||
<button class="btn" hx-get="/review-rejected-article/{{.ID}}/" hx-target="#page-content">
|
||||
<button class="btn" hx-get="/review-rejected-article/{{.ID}}" hx-target="#page-content">
|
||||
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
||||
<p>{{.Description}}</p>
|
||||
</button>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
<button class="action-btn" hx-get="/hub/" hx-target="#page-content">Zurück</button>
|
||||
<button class="action-btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
<div>
|
||||
<span>Tags</span>
|
||||
<div class="flex gap-4">
|
||||
<div class="flex flex-wrap gap-x-4">
|
||||
{{range .Tags}}
|
||||
<div>
|
||||
<input id="tag-{{.Name}}" name="tags" type="checkbox" value="{{.ID}}" {{if index $.Selected
|
||||
@ -28,14 +28,14 @@
|
||||
</div>
|
||||
|
||||
<div id="editor-images">
|
||||
<input class="mb-2" name="article-image" type="file" hx-encoding="multipart/form-data" hx-post="/upload-image/"
|
||||
<input class="mb-2" name="article-image" type="file" hx-encoding="multipart/form-data" hx-post="/upload-image"
|
||||
hx-swap="beforeend" hx-target="#editor-images" />
|
||||
</div>
|
||||
|
||||
<div class="btn-area">
|
||||
<input class="action-btn" type="submit" value="Senden" hx-post="/resubmit-article/{{.Article.ID}}/"
|
||||
<input class="action-btn" type="submit" value="Senden" hx-post="/resubmit-article/{{.Article.ID}}"
|
||||
hx-target="#page-content" />
|
||||
<button class="btn" hx-get="/hub/" hx-target="#page-content">Zurück</button>
|
||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
@ -26,10 +26,10 @@
|
||||
</div>
|
||||
|
||||
<div class="btn-area">
|
||||
<input class="action-btn" type="submit" value="Veröffentlichen" hx-get="/publish-article/{{.ID}}/"
|
||||
<input class="action-btn" type="submit" value="Veröffentlichen" hx-get="/publish-article/{{.ID}}"
|
||||
hx-target="#page-content" />
|
||||
<input class="btn" type="submit" value="Ablehnen" hx-get="/reject-article/{{.ID}}/" hx-target="#page-content" />
|
||||
<button class="btn" hx-get="/hub/" hx-target="#page-content">Zurück</button>
|
||||
<input class="btn" type="submit" value="Ablehnen" hx-get="/reject-article/{{.ID}}" hx-target="#page-content" />
|
||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -1,11 +1,11 @@
|
||||
{{define "page-content"}}
|
||||
<div class="flex flex-col gap-4">
|
||||
{{range .}}
|
||||
<button class="btn" hx-get="/review-unpublished-article/{{.ID}}/" hx-target="#page-content">
|
||||
<button class="btn" hx-get="/review-unpublished-article/{{.ID}}" hx-target="#page-content">
|
||||
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
||||
<p>{{.Description}}</p>
|
||||
</button>
|
||||
{{end}}
|
||||
<button class="action-btn" hx-get="/hub/" hx-target="#page-content">Zurück</button>
|
||||
<button class="action-btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||
</div>
|
||||
{{end}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user