Skip to content

Commit

Permalink
Add option to disable storage of article thumbnails
Browse files Browse the repository at this point in the history
When thumbnails are not stored, the article list falls back to
displaying the original top images from the source
  • Loading branch information
urandom committed Apr 26, 2020
1 parent 026319e commit d6ffad6
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 39 deletions.
6 changes: 3 additions & 3 deletions cmd/readeef/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,17 @@ func initThumbnailGenerator(
log log.Log,
) (thumbnail.Generator, error) {

switch config.ThumbnailGenerator {
switch config.Thumbnail.Generator {
case "extract":
if t, err := thumbnail.FromExtract(service.ThumbnailRepo(), service.ExtractRepo(), extract, processors, log); err == nil {
if t, err := thumbnail.FromExtract(service.ThumbnailRepo(), service.ExtractRepo(), extract, processors, config.Thumbnail.Store, log); err == nil {
return t, nil
} else {
return nil, errors.WithMessage(err, "initializing Extract thumbnail generator")
}
case "description":
fallthrough
default:
return thumbnail.FromDescription(service.ThumbnailRepo(), log), nil
return thumbnail.FromDescription(service.ThumbnailRepo(), config.Thumbnail.Store, log), nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Read(path string) (Config, error) {
return Config{}, err
}

for _, c := range []converter{&c.API, &c.Log, &c.Timeout, &c.FeedManager, &c.Popularity} {
for _, c := range []converter{&c.API, &c.Log, &c.Timeout, &c.FeedManager, &c.Popularity, &c.Content} {
c.Convert()
}

Expand Down
4 changes: 2 additions & 2 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ var DefaultCfg = `
[feed-parser]
processors = ["cleanup", "top-image-marker", "absolutize-urls"]
proxy-http-url-template = "/proxy?url={{ . }}"
[content]
thumbnail-generator = "description"
[content.extract]
generator = "goose" # readability
[content.search]
Expand All @@ -65,6 +63,8 @@ var DefaultCfg = `
[content.article]
processors = ["insert-thumbnail-target"]
proxy-http-url-template = "/proxy?url={{ . }}"
[content.thumbnail]
store = true
[ui]
path = "./rf-ng/ui"
`
18 changes: 17 additions & 1 deletion config/parts.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ type FeedManager struct {
}

type Content struct {
ThumbnailGenerator string `toml:"thumbnail-generator"`
Thumbnail struct {
Generator string `toml:"generator"`
Store bool `toml:"store"`
} `toml:"thumbnail"`

Extract struct {
Generator string `toml:"generator"`
Expand All @@ -127,6 +130,9 @@ type Content struct {
Processors []string `toml:"processors"`
ProxyHTTPURLTemplate string `toml:"proxy-http-url-template"`
} `toml:"article"`

// deprecated
ThumbnailGenerator string `toml:"thumbnail-generator"`
}

type UI struct {
Expand Down Expand Up @@ -183,3 +189,13 @@ func (c *FeedManager) Convert() {
c.Converted.UpdateInterval = 30 * time.Minute
}
}

func (c *Content) Convert() {
if c.Thumbnail.Generator == "" {
if c.ThumbnailGenerator != "" {
c.Thumbnail.Generator = c.ThumbnailGenerator
} else {
c.Thumbnail.Generator = "description"
}
}
}
13 changes: 9 additions & 4 deletions content/thumbnail/description.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (
)

type description struct {
repo repo.Thumbnail
log log.Log
repo repo.Thumbnail
store bool
log log.Log
}

func FromDescription(repo repo.Thumbnail, log log.Log) Generator {
return description{repo: repo, log: log}
func FromDescription(repo repo.Thumbnail, store bool, log log.Log) Generator {
return description{repo: repo, store: store, log: log}
}

func (t description) Generate(a content.Article) error {
Expand All @@ -27,6 +28,10 @@ func (t description) Generate(a content.Article) error {
thumbnail.Thumbnail, thumbnail.Link =
generateThumbnailFromDescription(strings.NewReader(a.Description))

if !t.store {
thumbnail.Thumbnail = ""
}

if err := t.repo.Update(thumbnail); err != nil {
return errors.WithMessage(err, fmt.Sprintf("saving thumbnail of %s", a))
}
Expand Down
12 changes: 10 additions & 2 deletions content/thumbnail/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ext struct {
extractRepo repo.Extract
generator extract.Generator
processors []processor.Article
store bool
log log.Log
}

Expand All @@ -26,6 +27,7 @@ func FromExtract(
extractRepo repo.Extract,
g extract.Generator,
processors []processor.Article,
store bool,
log log.Log,
) (Generator, error) {
if g == nil {
Expand All @@ -34,7 +36,7 @@ func FromExtract(

processors = filterProcessors(processors)

return ext{repo: repo, extractRepo: extractRepo, generator: g, processors: processors, log: log}, nil
return ext{repo: repo, extractRepo: extractRepo, generator: g, processors: processors, store: store, log: log}, nil
}

func (t ext) Generate(a content.Article) error {
Expand All @@ -57,11 +59,17 @@ func (t ext) Generate(a content.Article) error {
t.log.Debugf("Extract for %s doesn't contain a top image", a)
} else {
t.log.Debugf("Generating thumbnail from top image %s of %s\n", extract.TopImage, a)
thumbnail.Thumbnail = generateThumbnailFromImageLink(extract.TopImage)
if t.store {
thumbnail.Thumbnail = generateThumbnailFromImageLink(extract.TopImage)
}
thumbnail.Link = extract.TopImage
}
}

if !t.store {
thumbnail.Thumbnail = ""
}

if err := t.repo.Update(thumbnail); err != nil {
return errors.WithMessage(err, "saving thumbnail to repo")
}
Expand Down
48 changes: 24 additions & 24 deletions fs_files.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/legacy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (c Config) convertToV2() (config.Config, error) {
cfg.Content.Search.ElasticURL = c.Content.ElasticURL
cfg.Content.Extract.Generator = c.Content.Extractor
cfg.Content.Extract.ReadabilityKey = c.Content.ReadabilityKey
cfg.Content.ThumbnailGenerator = c.Content.Thumbnailer
cfg.Content.Thumbnail.Generator = c.Content.Thumbnailer

cfg.Auth.Secret = c.Auth.Secret

Expand Down
1 change: 1 addition & 0 deletions rf-ng/src/app/article-list/list-item.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mat-card-header {
flex: 1 0 auto;
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
}

mat-card-content {
Expand Down
3 changes: 2 additions & 1 deletion rf-ng/src/app/article-list/list-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</mat-card-title>
</mat-card-header>
<div mat-card-image [style.backgroundImage]="'url(' + item.thumbnail + ')'" *ngIf="item.thumbnail"></div>
<div mat-card-image [style.backgroundImage]="'url(' + item.thumbnailLink + ')'" *ngIf="item.thumbnailLink && !item.thumbnail"></div>
<mat-card-content>
<div [innerHTML]="item.stripped"></div>
</mat-card-content>
Expand All @@ -23,4 +24,4 @@
</div>
</div>
</mat-card-actions>
</mat-card>
</mat-card>
1 change: 1 addition & 0 deletions rf-ng/src/app/services/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class Article {
read: boolean;
favorite: boolean;
thumbnail: string;
thumbnailLink: string;
time: string;
hits: Hits;
format: ArticleFormat;
Expand Down

0 comments on commit d6ffad6

Please sign in to comment.