-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathreader.go
36 lines (25 loc) · 978 Bytes
/
reader.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
package reader
import (
"fmt"
"time"
"clx/reader/markdown/postprocessor"
"clx/reader/markdown/terminal"
"clx/reader/markdown/html"
"clx/reader/markdown/parser"
"github.com/go-shiori/go-readability"
)
func GetArticle(url string, title string, width int, indentationSymbol string) (string, error) {
articleInRawHTML, httpErr := readability.FromURL(url, 5*time.Second)
if httpErr != nil {
return "", fmt.Errorf("could not fetch url: %w", httpErr)
}
articleInMarkdown, mdErr := html.ConvertToMarkdown(articleInRawHTML.Content)
if mdErr != nil {
return "", fmt.Errorf("could not fetch url: %w", httpErr)
}
markdownBlocks := parser.ConvertToMarkdownBlocks(articleInMarkdown)
articleInTerminalFormal := terminal.ConvertToTerminalFormat(markdownBlocks, width, indentationSymbol)
header := terminal.CreateHeader(title, url, width)
articleInTerminalFormal = postprocessor.Process(header+articleInTerminalFormal, url)
return articleInTerminalFormal, nil
}