Compare commits
No commits in common. "372882a252c3fb1f9b1e060606f9b394b5108e7e" and "2447f50bac0f052d2abd5adbc56fcfdeab3143bf" have entirely different histories.
372882a252
...
2447f50bac
@ -7,10 +7,10 @@ import (
|
|||||||
"github.com/yuin/goldmark"
|
"github.com/yuin/goldmark"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConvertToHTML(md string) (string, error) {
|
func ConvertToHTML(markdown string) (string, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
||||||
if err := goldmark.Convert([]byte(md), &buf); err != nil {
|
if err := goldmark.Convert([]byte(markdown), &buf); err != nil {
|
||||||
return "", fmt.Errorf("error: cmd/articles/markdown.go ConvertToHTML goldmark.Convert(): %v", err)
|
return "", fmt.Errorf("error: cmd/articles/markdown.go ConvertToHTML goldmark.Convert(): %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
@ -1,25 +1,23 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"streifling.com/jason/cpolis/cmd/articles"
|
"streifling.com/jason/cpolis/cmd/articles"
|
||||||
"streifling.com/jason/cpolis/cmd/feed"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleFinishedEdit(f feed.Feed) http.HandlerFunc {
|
func HandleFinishedEdit() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
title := r.PostFormValue("editor-title")
|
md := r.PostFormValue("editor-textarea")
|
||||||
mdContent := r.PostFormValue("editor-text")
|
|
||||||
|
|
||||||
content, err := articles.ConvertToHTML(mdContent)
|
html, err := articles.ConvertToHTML(md)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
feed.AddToFeed(f, title, content)
|
fmt.Println(html)
|
||||||
// template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "html-result", rssItem)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
go.mod
5
go.mod
@ -2,7 +2,4 @@ module streifling.com/jason/cpolis
|
|||||||
|
|
||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
require (
|
require github.com/yuin/goldmark v1.7.0
|
||||||
github.com/gorilla/feeds v1.1.2
|
|
||||||
github.com/yuin/goldmark v1.7.0
|
|
||||||
)
|
|
||||||
|
8
go.sum
8
go.sum
@ -1,10 +1,2 @@
|
|||||||
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 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
|
||||||
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||||
|
6
main.go
6
main.go
@ -5,22 +5,18 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"streifling.com/jason/cpolis/cmd/feed"
|
|
||||||
"streifling.com/jason/cpolis/cmd/handlers"
|
"streifling.com/jason/cpolis/cmd/handlers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
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.Handle("/web/static/", http.StripPrefix("/web/static/", http.FileServer(http.Dir("web/static/"))))
|
||||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
template.Must(template.ParseFiles("web/templates/index.html", "web/templates/editor.html")).Execute(w, nil)
|
template.Must(template.ParseFiles("web/templates/index.html", "web/templates/editor.html")).Execute(w, nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
mux.HandleFunc("POST /finished-edit/", handlers.HandleFinishedEdit(feed))
|
mux.HandleFunc("POST /finished-edit/", handlers.HandleFinishedEdit())
|
||||||
|
|
||||||
log.Fatalln(http.ListenAndServe(":8080", mux))
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
{{define "page-content"}}
|
{{define "page-content"}}
|
||||||
<form>
|
<form>
|
||||||
<input type="text" name="editor-title" value="Titel">
|
<textarea name="editor-textarea"></textarea>
|
||||||
<textarea name="editor-text"></textarea>
|
<input type="submit" value="Senden" hx-post="/finished-edit/">
|
||||||
<input type="submit" value="Senden" hx-post="/finished-edit/" hx-target="#page-content">
|
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "html-result"}}
|
|
||||||
{{.}}
|
|
||||||
{{end}}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user