Skip to content

Commit 6fc860e

Browse files
committed
Merge gh-1230 to add more feed data
1 parent ae71cf1 commit 6fc860e

File tree

15 files changed

+174
-19
lines changed

15 files changed

+174
-19
lines changed

lib/MetaCPAN/Web/Controller/Feed.pm

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,21 @@ sub author : Chained('index') PathPart Args(1) {
7272

7373
my $author_cv = $c->model('API::Author')->get($author);
7474
my $releases_cv = $c->model('API::Release')->latest_by_author($author);
75-
my $data = {
76-
author => $author_cv->recv,
77-
releases =>
78-
[ map { $_->{fields} } @{ $releases_cv->recv->{hits}{hits} } ],
79-
};
75+
my $release_data
76+
= [ map { $_->{fields} } @{ $releases_cv->recv->{hits}{hits} } ];
77+
my $author_info = $author_cv->recv;
78+
my $faves_cv
79+
= $c->model('API::Favorite')->by_user( $author_info->{user} );
80+
my $faves_data
81+
= [ map { $_->{fields} } @{ $faves_cv->recv->{hits}{hits} } ];
8082

8183
$c->stash->{feed} = $self->build_feed(
82-
title => "Recent CPAN uploads by $data->{author}->{name} - MetaCPAN",
83-
entries => $data->{releases}
84+
title => "Recent CPAN activity of $author - MetaCPAN",
85+
entries => [
86+
sort { $b->{date} cmp $a->{date} }
87+
@{ $self->_format_release_entries($release_data) },
88+
@{ $self->_format_favorite_entries( $author, $faves_data ) }
89+
],
8490
);
8591
}
8692

@@ -98,7 +104,7 @@ sub build_entry {
98104
my $e = XML::Feed::Entry->new('RSS');
99105
$e->title( $entry->{name} );
100106
$e->link(
101-
$entry->{link} // join( '/',
107+
$entry->{link} ||= join( '/',
102108
'http://metacpan.org', 'release',
103109
$entry->{author}, $entry->{name} )
104110
);
@@ -120,6 +126,34 @@ sub build_feed {
120126
return $feed->as_xml;
121127
}
122128

129+
sub _format_release_entries {
130+
my ( $self, $releases ) = @_;
131+
my @release_data;
132+
foreach my $item ( @{$releases} ) {
133+
$item->{link} = join( '/',
134+
'https://metacpan.org', 'release',
135+
$item->{author}, $item->{name} );
136+
$item->{name} = "$item->{author} has released $item->{name}";
137+
push( @release_data, $item );
138+
}
139+
return \@release_data;
140+
}
141+
142+
sub _format_favorite_entries {
143+
my ( $self, $author, $data ) = @_;
144+
my @fav_data;
145+
foreach my $fav ( @{$data} ) {
146+
$fav->{abstract}
147+
= "$author ++ed $fav->{distribution} from $fav->{author}";
148+
$fav->{author} = $author;
149+
$fav->{link} = join( '/',
150+
'https://metacpan.org', 'release', $fav->{distribution} );
151+
$fav->{name} = "$author ++ed $fav->{distribution}";
152+
push( @fav_data, $fav );
153+
}
154+
return \@fav_data;
155+
}
156+
123157
sub end : Private {
124158
my ( $self, $c ) = @_;
125159
$c->res->content_type('application/rss+xml; charset=UTF-8');

root/author.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@
146146
<!-- End left content -->
147147

148148
<div class="content">
149+
<div id="feed_subscription" class="page-header">
150+
<p>Activity for <% author.name %> (<% author.pauseid %>)</p>
151+
<i class="fa fa-rss fa-2x">
152+
<a href="/feed/author/<% author.pauseid %>"></a>
153+
</i>
154+
</div>
149155
<div class="visible-xs inline-author-pic"><% INCLUDE inc/author-pic.html author = author %></div>
150156
<% IF releases.0 %>
151157
<% INCLUDE inc/release-table.html releases = aggregated, header = 1, tablesorter = 1, table_id = "author_releases" %>

root/inc/release-tools.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<span class="glyphicon glyphicon-star black"></span>Rate this distribution
2020
</a>
2121
</li>
22+
<li>
23+
<a href="/feed/distribution/<% release.distribution %>">
24+
<i class="fa fa-rss-square fa-fw black" id="rss-subscription"></i>Subscribe this distribution
25+
</a>
26+
</li>
2227
<li>
2328
<form action="/search">
2429
<input type="hidden" name="q" value="dist:<% release.distribution %>">

root/pod.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<% INCLUDE inc/breadcrumbs.html plussers_div = plusser_authors%>
77

8-
<ul class="nav nav-list slidepanel" id="pod-navlist" itemscope itemtype="http://schema.org/SoftwareApplication">
8+
<ul class="nav nav-list slidepanel" itemscope itemtype="http://schema.org/SoftwareApplication">
99
<li class="visible-xs">
1010
<% INCLUDE mobile/toolbar-search-form.html %>
1111
</li>

root/recent.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
%>
66

77
<div class="content">
8+
<div id="feed_subscription" class="page-header">
9+
<p>Recent Uploads</p>
10+
<i class="fa fa-rss fa-2x">
11+
<a href="/feed/recent"></a>
12+
</i>
13+
</div>
814
<%-
915
MoY = [undef, 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
1016
DoW = [undef, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

root/static/css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,8 @@ div.qtip-github table th {
338338

339339
.news_feed {
340340
float: right;
341+
}
342+
343+
#icon-rss {
344+
background: url('/static/icons/icon-rss.png');
341345
}

root/static/icons/icon-rss.png

1.38 KB
Loading

root/static/icons/rss_feed.png

3.88 KB
Loading

root/static/less/account.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
padding-left: 0px !important;
1010
}
1111

12-
1312
#account-profile {
1413
.form-group:after {
1514
clear: both !important;

root/static/less/author.less

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,29 @@
6464
}
6565
}
6666
}
67+
68+
#feed_subscription {
69+
&.page-header {
70+
margin: 0 0 5px;
71+
font-weight: bold;
72+
margin-left: 5px;
73+
}
74+
75+
p {
76+
font-size: 16px;
77+
display: inline;
78+
}
79+
80+
a {
81+
display: inline;
82+
width: 20px;
83+
height: 20px;
84+
padding-right: 20px;
85+
float: right;
86+
}
87+
88+
.fa {
89+
float: right;
90+
margin-right: -15px;
91+
}
92+
}

0 commit comments

Comments
 (0)