-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebContent.go
42 lines (37 loc) · 1.05 KB
/
WebContent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"log"
"time"
nurl "net/url"
"github.com/caninodev/hackernewsterm/hnapi"
"github.com/go-shiori/go-readability"
"github.com/rivo/tview"
)
// WebContent is a page that will render the selected item's url
func WebContent(nextSlide func()) (title string, content tview.Primitive) {
app.gui.content = tview.NewTextView()
app.gui.content.
SetScrollable(true).
SetDynamicColors(true).
SetBorderPadding(1, 1, 5, 5)
return "WebContent", app.gui.content
}
func (gui *GUI) parseWebContent(item hnapi.Item) {
gui.console.SetText("Loading page...")
app.main.QueueUpdateDraw(func() {
if parsedURL, err := nurl.Parse(item.URL); err != nil {
log.Print(err)
gui.console.SetText("URL parsing error!")
} else {
article, err := readability.FromURL(parsedURL.String(), 7*time.Second)
if err != nil {
log.Print(err)
consoleStr := fmt.Sprintf("Content parsing error: %s", err)
gui.errorStatus(consoleStr)
}
gui.content.Write([]byte(article.TextContent))
gui.infoStatus("Page successfully loaded.")
}
})
}