M article.go => article.go +1 -1
@@ 16,7 16,7 @@ type Article struct {
TopImage image.Image
}
-func NewArticle(link string, client *http.Client) (*readability.Article, error) {
+func newArticle(link string, client *http.Client) (*readability.Article, error) {
req, err := http.NewRequest("GET", link, nil)
if err != nil {
return nil, err
M card.go => card.go +4 -4
@@ 42,7 42,7 @@ func (cards Cards) Swap(i, k int) {
cards[i], cards[k] = cards[k], cards[i]
}
-func (card *Card) saveImage() func(image.Image) {
+func (card *Card) SaveImage() func(image.Image) {
return func(img image.Image) {
card.ItemImage = img
/*
@@ 63,7 63,7 @@ func (card *Card) OpenArticle() {
return
}
if card.Article == nil {
- article, err := NewArticle(card.Item.Link, card.photon.httpClient)
+ article, err := newArticle(card.Item.Link, card.photon.httpClient)
if err != nil {
log.Println("ERROR: scraping link:", err)
return
@@ 72,10 72,10 @@ func (card *Card) OpenArticle() {
if len(card.Article.TextContent) < len(card.Item.Description) {
card.Article.TextContent = card.Item.Description
}
- card.photon.cb.ArticleChanged(article)
}
- card.photon.OpenedArticle.Article = card.Article
+ card.photon.OpenedArticle = &Article{Article: card.Article}
card.photon.OpenedArticle.Link = card.Item.Link
+ card.photon.cb.ArticleChanged(card.photon.OpenedArticle)
if card.photon.OpenedArticle.Image != "" {
card.photon.ImgDownloader.Download(
card.photon.OpenedArticle.Image,
M image_downloader.go => image_downloader.go +4 -12
@@ 24,12 24,10 @@ type imgDownloadReq struct {
Callback func(image.Image)
}
-type ImgDownloaderOption func(d *ImgDownloader)
-
-func NewImgDownloader(options ...ImgDownloaderOption) *ImgDownloader {
- d := &ImgDownloader{receiveCh: make(chan imgDownloadReq, 1024)}
- for _, o := range options {
- o(d)
+func newImgDownloader(client *http.Client) *ImgDownloader {
+ d := &ImgDownloader{
+ client: client,
+ receiveCh: make(chan imgDownloadReq, 1024),
}
reqCh := make(chan imgDownloadReq, 1024)
//receiver
@@ 81,12 79,6 @@ func NewImgDownloader(options ...ImgDownloaderOption) *ImgDownloader {
return d
}
-func WithClient(client *http.Client) ImgDownloaderOption {
- return func(d *ImgDownloader) {
- d.client = client
- }
-}
-
func (d *ImgDownloader) Download(url string, callback func(image.Image)) {
img, ok := d.imgCache.Load(url)
if !ok || img == nil {
M libphoton.go => libphoton.go +6 -7
@@ 16,7 16,6 @@ import (
"git.sr.ht/~ghost08/libphoton/keybindings"
"git.sr.ht/~ghost08/libphoton/media"
"git.sr.ht/~ghost08/libphoton/states"
- "github.com/cixtor/readability"
"github.com/mmcdole/gofeed"
)
@@ 44,7 43,7 @@ type Callbacks interface {
SelectedCardMoveUp()
SelectedCardMoveRight()
SelectedCardMoveLeft()
- ArticleChanged(*readability.Article)
+ ArticleChanged(*Article)
}
func New(cb Callbacks, paths []string, options ...Option) (*Photon, error) {
@@ 60,16 59,16 @@ func New(cb Callbacks, paths []string, options ...Option) (*Photon, error) {
return nil, fmt.Errorf("no feeds")
}
p.feedInputs = feedInputs
- p.mediaExtractor = &media.Extractor{}
- p.ImgDownloader = NewImgDownloader()
+ p.mediaExtractor = &media.Extractor{Client: p.httpClient}
+ p.ImgDownloader = newImgDownloader(p.httpClient)
for _, o := range options {
o(p)
}
if p.httpClient == nil {
p.httpClient = http.DefaultClient
}
- p.ImgDownloader.client = p.httpClient
p.mediaExtractor.Client = p.httpClient
+ p.ImgDownloader.client = p.httpClient
if err = p.loadPlugins(); err != nil {
log.Fatal("ERROR:", err)
}
@@ 154,8 153,8 @@ func (p *Photon) RefreshFeed() {
go func() {
fp := gofeed.NewParser()
fp.Client = p.httpClient
- fp.AtomTranslator = NewCustomAtomTranslator()
- fp.RSSTranslator = NewCustomRSSTranslator()
+ fp.AtomTranslator = newCustomAtomTranslator()
+ fp.RSSTranslator = newCustomRSSTranslator()
var err error
var f *gofeed.Feed
switch {
M translators.go => translators.go +8 -8
@@ 90,17 90,17 @@ func findImage(item *gofeed.Item) {
}
}
-type CustomAtomTranslator struct {
+type customAtomTranslator struct {
defaultTranslator *gofeed.DefaultAtomTranslator
}
-func NewCustomAtomTranslator() *CustomAtomTranslator {
- t := &CustomAtomTranslator{}
+func newCustomAtomTranslator() *customAtomTranslator {
+ t := &customAtomTranslator{}
t.defaultTranslator = &gofeed.DefaultAtomTranslator{}
return t
}
-func (ct *CustomAtomTranslator) Translate(feed interface{}) (*gofeed.Feed, error) {
+func (ct *customAtomTranslator) Translate(feed interface{}) (*gofeed.Feed, error) {
atom, found := feed.(*atom.Feed)
if !found {
return nil, fmt.Errorf("Feed did not match expected type of *atom.Feed")
@@ 143,17 143,17 @@ func (ct *CustomAtomTranslator) Translate(feed interface{}) (*gofeed.Feed, error
return f, nil
}
-type CustomRSSTranslator struct {
+type customRSSTranslator struct {
defaultTranslator *gofeed.DefaultRSSTranslator
}
-func NewCustomRSSTranslator() *CustomRSSTranslator {
- t := &CustomRSSTranslator{}
+func newCustomRSSTranslator() *customRSSTranslator {
+ t := &customRSSTranslator{}
t.defaultTranslator = &gofeed.DefaultRSSTranslator{}
return t
}
-func (ct *CustomRSSTranslator) Translate(feed interface{}) (*gofeed.Feed, error) {
+func (ct *customRSSTranslator) Translate(feed interface{}) (*gofeed.Feed, error) {
rss, found := feed.(*rss.Feed)
if !found {
return nil, fmt.Errorf("Feed did not match expected type of *rss.Feed")