Compare commits

...

3 Commits

4 changed files with 33 additions and 17 deletions

View File

@ -0,0 +1,8 @@
package domain
import "golang.org/x/net/html"
type Content struct {
HTML *html.Node
Text string
}

View File

@ -13,7 +13,7 @@ type Entry struct {
DeletedAt time.Time DeletedAt time.Time
Title string // p-name Title string // p-name
Description string // p-summary Description string // p-summary
Content []byte // e-content Content Content // e-content
PublishedAt time.Time // dt-published PublishedAt time.Time // dt-published
UpdatedAt time.Time // dt-updated UpdatedAt time.Time // dt-updated
// TODO(toby3d): Author string // p-author // TODO(toby3d): Author string // p-author
@ -59,11 +59,11 @@ func TestEntry(tb testing.TB) *Entry {
Title: "Lorem ipsum", Title: "Lorem ipsum",
Description: "Ut enim ad minim veniam, quis nostrud exercitation " + Description: "Ut enim ad minim veniam, quis nostrud exercitation " +
"ullamco laboris nisi ut aliquip ex ea commodo consequat.", "ullamco laboris nisi ut aliquip ex ea commodo consequat.",
Content: []byte("Duis aute irure dolor in reprehenderit in " + Content: Content{Text: "Duis aute irure dolor in reprehenderit in " +
"voluptate velit esse cillum dolore eu fugiat nulla " + "voluptate velit esse cillum dolore eu fugiat nulla " +
"pariatur. Excepteur sint occaecat cupidatat non proident," + "pariatur. Excepteur sint occaecat cupidatat non proident," +
" sut in culpa qui officia deserunt mollit anim id est " + " sut in culpa qui officia deserunt mollit anim id est " +
"laborum."), "laborum."},
Tags: []string{"lorem", "ipsum", "dor"}, Tags: []string{"lorem", "ipsum", "dor"},
} }
} }

View File

@ -15,22 +15,22 @@ type Error struct {
Code int `json:"error"` Code int `json:"error"`
} }
func (err Error) Error() string { func (e Error) Error() string {
return fmt.Sprint(err) return fmt.Sprint(e)
} }
func (err Error) Format(f fmt.State, r rune) { func (e Error) Format(f fmt.State, r rune) {
xerrors.FormatError(err, f, r) xerrors.FormatError(e, f, r)
} }
func (err Error) FormatError(p xerrors.Printer) error { func (e Error) FormatError(p xerrors.Printer) error {
p.Printf("%d: %s", err.Code, err.Description) p.Printf("%d: %s", e.Code, e.Description)
if !p.Detail() { if !p.Detail() {
return err return e
} }
err.Frame.Format(p) e.Frame.Format(p)
return nil return nil
} }

View File

@ -327,7 +327,12 @@ func (h *Handler) handleUpdate(w http.ResponseWriter, r *http.Request) {
req.populate(in) req.populate(in)
out, err := h.entries.Update(r.Context(), req.URL.URL, *in) out, err := h.entries.Update(r.Context(), req.URL.URL, entry.UpdateOptions{
// TODO(toby3d)
// Add: req.Add,
// Replace: req.Replace,
// Delete: req.Delete,
})
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
@ -481,7 +486,8 @@ func (r *RequestCreate) bind(req *http.Request) error {
func (r *RequestCreate) populate(dst *domain.Entry) { func (r *RequestCreate) populate(dst *domain.Entry) {
if len(r.Properties.Content) > 0 { if len(r.Properties.Content) > 0 {
dst.Content = []byte(r.Properties.Content[0].Value) dst.Content.HTML = r.Properties.Content[0].HTML
dst.Content.Text = r.Properties.Content[0].Value
} }
if len(r.Properties.Summary) > 0 { if len(r.Properties.Summary) > 0 {
@ -698,12 +704,13 @@ func NewResponseSource(src *domain.Entry, properties ...string) *ResponseSource
}) })
} }
case "content": case "content":
if len(src.Content) == 0 { if src.Content.Text == "" && src.Content.HTML == nil {
continue continue
} }
out.Properties.Content = append(out.Properties.Content, Content{ out.Properties.Content = append(out.Properties.Content, Content{
Value: string(src.Content), Value: src.Content.Text,
HTML: src.Content.HTML,
}) })
case "category": case "category":
out.Properties.Category = append(out.Properties.Category, src.Tags...) out.Properties.Category = append(out.Properties.Category, src.Tags...)
@ -735,7 +742,8 @@ func (p Properties) CopyTo(dst *domain.Entry) {
} }
if len(p.Content) > 0 { if len(p.Content) > 0 {
dst.Content = []byte(p.Content[0].Value) dst.Content.HTML = p.Content[0].HTML
dst.Content.Text = p.Content[0].Value
} }
if len(p.Name) > 0 { if len(p.Name) > 0 {
@ -796,7 +804,7 @@ func (d Delete) CopyTo(dst *domain.Entry) {
case "category": case "category":
dst.Tags = make([]string, 0) dst.Tags = make([]string, 0)
case "content": case "content":
dst.Content = make([]byte, 0) dst.Content = domain.Content{}
case "name": case "name":
dst.Title = "" dst.Title = ""
case "photo": case "photo":