Compare commits
3 Commits
v0.11.1
...
372882a252
Author | SHA1 | Date | |
---|---|---|---|
372882a252 | |||
2d0b53a254 | |||
2447f50bac |
18
cmd/articles/markdown.go
Normal file
18
cmd/articles/markdown.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package articles
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ConvertToHTML(md string) (string, error) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
|
||||||
|
if err := goldmark.Convert([]byte(md), &buf); err != nil {
|
||||||
|
return "", fmt.Errorf("error: cmd/articles/markdown.go ConvertToHTML goldmark.Convert(): %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.String(), nil
|
||||||
|
}
|
39
cmd/feed/rss.go
Normal file
39
cmd/feed/rss.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package feed
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/feeds"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Feed struct {
|
||||||
|
*feeds.Feed
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFeed(title, link, desc string) Feed {
|
||||||
|
return Feed{
|
||||||
|
Feed: &feeds.Feed{
|
||||||
|
Title: title,
|
||||||
|
Link: &feeds.Link{Href: link},
|
||||||
|
Description: desc,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddToFeed(feed Feed, title, content string) error {
|
||||||
|
item := feeds.Item{
|
||||||
|
Title: title,
|
||||||
|
Created: time.Now(),
|
||||||
|
Content: content,
|
||||||
|
}
|
||||||
|
feed.Add(&item)
|
||||||
|
|
||||||
|
rss, err := feed.ToRss()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error cmd/feed/rss.go AddToFeed feed.ToRss(): %v", err)
|
||||||
|
}
|
||||||
|
fmt.Println(rss)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
25
cmd/handlers/editor.go
Normal file
25
cmd/handlers/editor.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"streifling.com/jason/cpolis/cmd/articles"
|
||||||
|
"streifling.com/jason/cpolis/cmd/feed"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HandleFinishedEdit(f feed.Feed) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
title := r.PostFormValue("editor-title")
|
||||||
|
mdContent := r.PostFormValue("editor-text")
|
||||||
|
|
||||||
|
content, err := articles.ConvertToHTML(mdContent)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
log.Panicln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
feed.AddToFeed(f, title, content)
|
||||||
|
// template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "html-result", rssItem)
|
||||||
|
}
|
||||||
|
}
|
5
go.mod
5
go.mod
@ -1,3 +1,8 @@
|
|||||||
module streifling.com/jason/cpolis
|
module streifling.com/jason/cpolis
|
||||||
|
|
||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gorilla/feeds v1.1.2
|
||||||
|
github.com/yuin/goldmark v1.7.0
|
||||||
|
)
|
||||||
|
10
go.sum
Normal file
10
go.sum
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
github.com/gorilla/feeds v1.1.2 h1:pxzZ5PD3RJdhFH2FsJJ4x6PqMqbgFk1+Vez4XWBW8Iw=
|
||||||
|
github.com/gorilla/feeds v1.1.2/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
|
github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
|
||||||
|
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
22
main.go
22
main.go
@ -1,8 +1,26 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "net/http"
|
import (
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"streifling.com/jason/cpolis/cmd/feed"
|
||||||
|
"streifling.com/jason/cpolis/cmd/handlers"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
http.ListenAndServe(":8080", mux)
|
feed := feed.NewFeed("Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
|
||||||
|
"https://distrikt-ni-st.de",
|
||||||
|
"Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität")
|
||||||
|
|
||||||
|
mux.Handle("/web/static/", http.StripPrefix("/web/static/", http.FileServer(http.Dir("web/static/"))))
|
||||||
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
template.Must(template.ParseFiles("web/templates/index.html", "web/templates/editor.html")).Execute(w, nil)
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.HandleFunc("POST /finished-edit/", handlers.HandleFinishedEdit(feed))
|
||||||
|
|
||||||
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
||||||
}
|
}
|
||||||
|
0
web/static/css/style.css
Normal file
0
web/static/css/style.css
Normal file
1
web/static/js/htmx.min.js
vendored
Normal file
1
web/static/js/htmx.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
11
web/templates/editor.html
Normal file
11
web/templates/editor.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{{define "page-content"}}
|
||||||
|
<form>
|
||||||
|
<input type="text" name="editor-title" value="Titel">
|
||||||
|
<textarea name="editor-text"></textarea>
|
||||||
|
<input type="submit" value="Senden" hx-post="/finished-edit/" hx-target="#page-content">
|
||||||
|
</form>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
{{define "html-result"}}
|
||||||
|
{{.}}
|
||||||
|
{{end}}
|
21
web/templates/index.html
Normal file
21
web/templates/index.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Orient Editor</title>
|
||||||
|
<link href="web/static/css/style.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Orient Editor</h1>
|
||||||
|
|
||||||
|
<div id="page-content">
|
||||||
|
{{template "page-content" .}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="web/static/js/htmx.min.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Reference in New Issue
Block a user