53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
|
package ui
|
||
|
|
||
|
import (
|
||
|
"html/template"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
"time"
|
||
|
|
||
|
"github.com/gorilla/feeds"
|
||
|
"streifling.com/jason/cpolis/cmd/data"
|
||
|
)
|
||
|
|
||
|
func WriteArticle() http.HandlerFunc {
|
||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "page-content", nil)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func FinishEdit(feed *data.Feed) http.HandlerFunc {
|
||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
title, err := data.ConvertToPlain(r.PostFormValue("editor-title"))
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
desc, err := data.ConvertToPlain(r.PostFormValue("editor-desc"))
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
content, err := data.ConvertToHTML(r.PostFormValue("editor-text"))
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
feed.Add(&feeds.Item{
|
||
|
Title: title,
|
||
|
Created: time.Now(),
|
||
|
Description: desc,
|
||
|
Content: content,
|
||
|
})
|
||
|
feed.Save("tmp/rss.gob")
|
||
|
|
||
|
template.Must(template.ParseFiles("web/templates/hub.html")).ExecuteTemplate(w, "page-content", nil)
|
||
|
}
|
||
|
}
|