Skip to content

Commit

Permalink
[update] Add wordcount
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepla committed Feb 12, 2022
1 parent 9788d66 commit e36f62f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ type SearchResult struct {
Query struct {
Search []struct {
Title string `json:"title"`
Pageid int `json:"pageid"`
Pageid int64 `json:"pageid"`
Snippet string `json:"snippet"`
Timestamp time.Time `json:"timestamp"`
Wordcount int64 `json:"wordcount"`
} `json:"search"`
} `json:"query"`
}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ func createPreview(i, w, h int, result *client.SearchResult) string {
title := result.Query.Search[i].Title
snippet := result.Query.Search[i].Snippet
timestamp := result.Query.Search[i].Timestamp
wordcount := result.Query.Search[i].Wordcount
if s, err := html2text(snippet); err == nil {
snippet = s
}
return fmt.Sprintf(
"%s\n\n%s\n\n%s",
"%s\n\n%s\n\n%s, %s words",
title,
runewidth.Wrap(snippet, w/2-5),
humanize.Time(timestamp),
humanize.Comma(wordcount),
)
}

Expand Down

0 comments on commit e36f62f

Please sign in to comment.