Compare commits

...

7 Commits

16 changed files with 82 additions and 51 deletions

View File

@ -3,42 +3,52 @@ testdata_dir = "testdata"
tmp_dir = "tmp" tmp_dir = "tmp"
[build] [build]
args_bin = [] args_bin = [
bin = "./tmp/main -key tmp/key.gob -log tmp/cpolis.log -pics tmp/pics -rss tmp/orientexpress_alle.rss -web web" "-desc 'Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität'",
cmd = "go build -o ./tmp/main ./cmd/main.go" "-domain localhost:8080",
delay = 0 "-key tmp/key.gob",
exclude_dir = ["assets", "tmp", "vendor", "testdata"] "-link https://distrikt-ni-st.de",
exclude_file = [] "-log tmp/cpolis.log",
exclude_regex = ["_test.go"] "-pics tmp/pics",
exclude_unchanged = false "-rss tmp/orientexpress_alle.rss",
follow_symlink = false "-title 'Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt'",
full_bin = "" "-web web"
include_dir = [] ]
include_ext = ["go", "tpl", "tmpl", "html", "css"] bin = "./tmp/main"
include_file = [] cmd = "go build -o ./tmp/main ./cmd/main.go"
kill_delay = "0s" delay = 0
log = "build-errors.log" exclude_dir = ["assets", "tmp", "vendor", "testdata"]
poll = false exclude_file = []
poll_interval = 0 exclude_regex = ["_test.go"]
rerun = false exclude_unchanged = false
rerun_delay = 500 follow_symlink = false
send_interrupt = false full_bin = ""
stop_on_error = false include_dir = []
include_ext = ["go", "tpl", "tmpl", "html", "css"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
[color] [color]
app = "" app = ""
build = "yellow" build = "yellow"
main = "magenta" main = "magenta"
runner = "green" runner = "green"
watcher = "cyan" watcher = "cyan"
[log] [log]
main_only = false main_only = false
time = false time = false
[misc] [misc]
clean_on_exit = false clean_on_exit = false
[screen] [screen]
clear_on_rebuild = false clear_on_rebuild = false
keep_scroll = true keep_scroll = true

View File

@ -7,12 +7,16 @@ import (
) )
type CliArgs struct { type CliArgs struct {
Description string
DBName string DBName string
Domain string
KeyFile string KeyFile string
Link string
LogFile string LogFile string
Port string Port string
PicsDir string PicsDir string
RSSFile string RSSFile string
Title string
WebDir string WebDir string
} }
@ -21,11 +25,15 @@ func HandleCliArgs() (*CliArgs, error) {
cliArgs := new(CliArgs) cliArgs := new(CliArgs)
flag.StringVar(&cliArgs.DBName, "db", "cpolis", "DB name") flag.StringVar(&cliArgs.DBName, "db", "cpolis", "DB name")
flag.StringVar(&cliArgs.Description, "desc", "Description", "Channel description")
flag.StringVar(&cliArgs.Domain, "domain", "", "domain name")
keyFile := flag.String("key", "/var/www/cpolis/cpolis.key", "key file") keyFile := flag.String("key", "/var/www/cpolis/cpolis.key", "key file")
flag.StringVar(&cliArgs.Link, "link", "Link", "Channel Link")
logFile := flag.String("log", "/var/log/cpolis.log", "log file") logFile := flag.String("log", "/var/log/cpolis.log", "log file")
flag.StringVar(&cliArgs.PicsDir, "pics", "pics", "pictures directory") flag.StringVar(&cliArgs.PicsDir, "pics", "pics", "pictures directory")
port := flag.Int("port", 8080, "port") port := flag.Int("port", 8080, "port")
rssFile := flag.String("rss", "/var/www/cpolis/cpolis.rss", "RSS file") rssFile := flag.String("rss", "/var/www/cpolis/cpolis.rss", "RSS file")
flag.StringVar(&cliArgs.Title, "title", "Title", "Channel title")
webDir := flag.String("web", "/var/www/cpolis/web", "web directory") webDir := flag.String("web", "/var/www/cpolis/web", "web directory")
flag.Parse() flag.Parse()

View File

@ -97,7 +97,7 @@ func GenerateRSS(db *model.DB, title, link, desc string) (*string, error) {
channel.Items = append(channel.Items, &rss.Item{ channel.Items = append(channel.Items, &rss.Item{
Title: articleTitle, Title: articleTitle,
Author: user.FirstName + user.LastName, Author: user.FirstName + " " + user.LastName,
PubDate: article.Created.Format(time.RFC1123Z), PubDate: article.Created.Format(time.RFC1123Z),
Description: articleDescription, Description: articleDescription,
Content: &rss.Content{Value: articleContent}, Content: &rss.Content{Value: articleContent},

View File

@ -9,8 +9,10 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/google/uuid"
"streifling.com/jason/cpolis/cmd/control" "streifling.com/jason/cpolis/cmd/control"
"streifling.com/jason/cpolis/cmd/model" "streifling.com/jason/cpolis/cmd/model"
) )
@ -336,12 +338,7 @@ func PublishArticle(c *control.CliArgs, db *model.DB, s *control.CookieStore) ht
return return
} }
feed, err := control.GenerateRSS( feed, err := control.GenerateRSS(db, c.Title, c.Link, c.Description)
db,
"Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
"https://distrikt-ni-st.de",
"Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität",
)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
@ -413,8 +410,9 @@ func UploadImage(c *control.CliArgs) http.HandlerFunc {
} }
defer file.Close() defer file.Close()
filename := fmt.Sprint(time.Now().Format("2006-01-02_15:04:05"), "-", nameStrings := strings.Split(header.Filename, ".")
header.Filename) extension := "." + nameStrings[len(nameStrings)-1]
filename := fmt.Sprint(uuid.New(), extension)
absFilepath, err := filepath.Abs(fmt.Sprint(c.PicsDir, "/", filename)) absFilepath, err := filepath.Abs(fmt.Sprint(c.PicsDir, "/", filename))
if err != nil { if err != nil {
log.Println(err) log.Println(err)
@ -436,7 +434,8 @@ func UploadImage(c *control.CliArgs) http.HandlerFunc {
return return
} }
imgMD := fmt.Sprint("![", header.Filename, "](/pics/", filename, ")") alt := strings.Join(nameStrings[0:len(nameStrings)-1], " ")
imgMD := fmt.Sprint("![", alt, "](", c.Domain, "/pics/", filename, ")")
tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html") tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html")
template.Must(tmpl, err).ExecuteTemplate(w, "editor-images", imgMD) template.Must(tmpl, err).ExecuteTemplate(w, "editor-images", imgMD)
} }

1
go.mod
View File

@ -5,6 +5,7 @@ go 1.22.0
require ( require (
git.streifling.com/jason/rss v0.1.2 git.streifling.com/jason/rss v0.1.2
github.com/go-sql-driver/mysql v1.7.1 github.com/go-sql-driver/mysql v1.7.1
github.com/google/uuid v1.6.0
github.com/gorilla/sessions v1.2.2 github.com/gorilla/sessions v1.2.2
github.com/microcosm-cc/bluemonday v1.0.26 github.com/microcosm-cc/bluemonday v1.0.26
github.com/yuin/goldmark v1.7.0 github.com/yuin/goldmark v1.7.0

2
go.sum
View File

@ -6,6 +6,8 @@ github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrt
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA= github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=

View File

@ -1,5 +1,6 @@
{{define "page-content"}} {{define "page-content"}}
<h2>Neuer Benutzer</h2> <h2>Neuer Benutzer</h2>
<form> <form>
<div class="grid grid-cols-3 gap-4"> <div class="grid grid-cols-3 gap-4">
<div> <div>

View File

@ -1,4 +1,6 @@
{{define "page-content"}} {{define "page-content"}}
<h2>Aktuelle Artikel</h2>
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
{{range .}} {{range .}}
<div class="border px-2 py-1 rounded-md"> <div class="border px-2 py-1 rounded-md">

View File

@ -1,4 +1,6 @@
{{define "page-content"}} {{define "page-content"}}
<h2>Benutzerdaten bearbeiten</h2>
<form> <form>
<div class="grid grid-cols-3 gap-4"> <div class="grid grid-cols-3 gap-4">
<div> <div>

View File

@ -1,5 +1,6 @@
{{define "page-content"}} {{define "page-content"}}
<h2>Editor</h2> <h2>Editor</h2>
<form> <form>
<div class="flex flex-col gap-y-1"> <div class="flex flex-col gap-y-1">
<label for="article-title">Titel</label> <label for="article-title">Titel</label>

View File

@ -1,3 +0,0 @@
{{define "page-content"}}
{{.}}
{{end}}

View File

@ -1,5 +1,6 @@
{{define "page-content"}} {{define "page-content"}}
<h2>Anmeldung</h2> <h2>Anmeldung</h2>
<form> <form>
<div class="btn-area"> <div class="btn-area">
<input class="w-full" name="username" placeholder="Benutzername" type="text" /> <input class="w-full" name="username" placeholder="Benutzername" type="text" />

View File

@ -1,4 +1,6 @@
{{define "page-content"}} {{define "page-content"}}
<h2>Abgelehnte Artikel</h2>
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
{{range .RejectedArticles}} {{range .RejectedArticles}}
{{if index $.MyIDs .ID}} {{if index $.MyIDs .ID}}

View File

@ -1,5 +1,6 @@
{{define "page-content"}} {{define "page-content"}}
<h2>Editor</h2> <h2>Editor</h2>
<form> <form>
<div class="flex flex-col gap-y-1"> <div class="flex flex-col gap-y-1">
<label for="article-title">Titel</label> <label for="article-title">Titel</label>

View File

@ -1,4 +1,6 @@
{{define "page-content"}} {{define "page-content"}}
<h2>Artikel veröffentlichen</h2>
<div> <div>
<span>Titel</span> <span>Titel</span>
<div class="bg-white border mb-3 px-2 py-2 rounded-md w-full"> <div class="bg-white border mb-3 px-2 py-2 rounded-md w-full">

View File

@ -1,4 +1,6 @@
{{define "page-content"}} {{define "page-content"}}
<h2>Unveröffentlichte Artikel</h2>
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
{{range .}} {{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">