package main import ( "context" "fmt" "io" "os" "github.com/urfave/cli/v3" "gitea.stevedudenhoeffer.com/steve/go-extractor" "gitea.stevedudenhoeffer.com/steve/go-extractor/cmd/browser/pkg/browser" ) func deferClose(cl io.Closer) { _ = cl.Close() } func main() { cmd := &cli.Command{ Name: "browser", Flags: browser.Flags, Usage: "", Action: func(ctx context.Context, cli *cli.Command) error { target := cli.Args().First() if target == "" { return fmt.Errorf("no url specified") } b, err := browser.FromCommand(ctx, cli) if err != nil { return err } defer deferClose(b) // now open the user specified url doc, err := b.Open(ctx, target, extractor.OpenPageOptions{}) if err != nil { return err } defer deferClose(doc) article, err := extractor.Readability(ctx, doc) if err != nil { return err } content := "" if article.Content != "" { if len(article.Content) > 32 { content = article.Content[:32] + "..." } else { content = article.Content } } fmt.Println("Title:", article.Title) fmt.Println("Byline:", article.Byline) fmt.Println("Site:", article.SiteName) fmt.Println("Published:", article.PublishedTime) fmt.Println("Excerpt:", article.Excerpt) fmt.Println("Length:", article.Length) fmt.Println("Lang:", article.Lang) fmt.Println("Content:", content) fmt.Println("TextContent:", article.TextContent) return nil }, } err := cmd.Run(context.Background(), os.Args) if err != nil { panic(err) } }