| | 104 | } |
|---|
| | 105 | |
|---|
| | 106 | sub _sort_prioritize { |
|---|
| | 107 | my($permalink, @entries) = @_; |
|---|
| | 108 | |
|---|
| | 109 | # use domain match, date and full-content-ness to prioritize source entry |
|---|
| | 110 | # TODO: Date vs Full-content check should be user configurable |
|---|
| | 111 | |
|---|
| | 112 | my $now = time; |
|---|
| | 113 | return |
|---|
| | 114 | map { $_->[0] } |
|---|
| | 115 | sort { $b->[1] <=> $a->[1] || $b->[2] <=> $a->[2] || $b->[3] <=> $a->[3] || $b->[4] <=> $a->[4] } |
|---|
| | 116 | map { [ |
|---|
| | 117 | $_, # Plagger::Entry for Schwartzian |
|---|
| | 118 | _is_same_domain($permalink, $_->source->url), # permalink and $feed->url is the same domain |
|---|
| | 119 | _is_same_domain($permalink, $_->source->link), # permalink and $feed->link is the same domain |
|---|
| | 120 | ($_->date ? ($now - $_->date->epoch) : 0), # Older entry date is prioritized |
|---|
| | 121 | length($_->body || ''), # Prioritize full content feed |
|---|
| | 122 | ] } @entries; |
|---|
| | 123 | } |
|---|
| | 124 | |
|---|
| | 125 | sub _is_same_domain { |
|---|
| | 126 | my $u1 = URI->new($_[0]); |
|---|
| | 127 | my $u2 = URI->new($_[1]); |
|---|
| | 128 | |
|---|
| | 129 | return 0 unless $u1->can('host') && $u2->can('host'); |
|---|
| | 130 | return lc($u1->host) eq lc($u2->host); |
|---|