mirror of
https://gitgud.io/yats/libkiwi.git
synced 2026-06-17 08:35:25 -04:00
Even more refactoring n shit
This commit is contained in:
@@ -126,11 +126,6 @@ func (kf *KF) GetPost(ctx context.Context, postID uint32) (Post, error) {
|
|||||||
return Post{}, errors.New("Failed to parse post message body.")
|
return Post{}, errors.New("Failed to parse post message body.")
|
||||||
}
|
}
|
||||||
|
|
||||||
bh, err := body.Html()
|
|
||||||
if err != nil {
|
|
||||||
return Post{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
author, err := parsePostAuthor(article)
|
author, err := parsePostAuthor(article)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Post{}, err
|
return Post{}, err
|
||||||
@@ -138,8 +133,6 @@ func (kf *KF) GetPost(ctx context.Context, postID uint32) (Post, error) {
|
|||||||
|
|
||||||
post := Post{
|
post := Post{
|
||||||
Author: author,
|
Author: author,
|
||||||
Text: bytes.TrimSpace([]byte(body.Text())),
|
|
||||||
HTML: bytes.TrimSpace([]byte(bh)),
|
|
||||||
|
|
||||||
article: article,
|
article: article,
|
||||||
body: body,
|
body: body,
|
||||||
|
|||||||
+7
-6
@@ -88,19 +88,20 @@ func parsePostAuthor(article *gq.Selection) (User, error) {
|
|||||||
|
|
||||||
type Post struct {
|
type Post struct {
|
||||||
Author User
|
Author User
|
||||||
Text []byte
|
|
||||||
|
|
||||||
HTML []byte
|
|
||||||
|
|
||||||
article *gq.Selection
|
article *gq.Selection
|
||||||
body *gq.Selection
|
body *gq.Selection
|
||||||
}
|
}
|
||||||
|
|
||||||
func (post *Post) TextContent() (io.Reader, error) {
|
func (post *Post) TextContent() io.Reader {
|
||||||
postHTML, err := post.body.Html()
|
return strings.NewReader(strings.TrimSpace(post.body.Text()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (post *Post) HTML() (io.Reader, error) {
|
||||||
|
postHTML, err := post.article.Html()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.NewReader(postHTML), nil
|
return strings.NewReader(strings.TrimSpace(postHTML)), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ func TestGetPost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Post author: %+v\n", post.Author)
|
t.Logf("Post author: %+v\n", post.Author)
|
||||||
|
t.Logf("Post text: %s\n", post.TextContent())
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestKF() (*KF, error) {
|
func newTestKF() (*KF, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user