Skip to content

Commit

Permalink
Merge fb49846 into e855717
Browse files Browse the repository at this point in the history
  • Loading branch information
zakame committed Apr 22, 2018
2 parents e855717 + fb49846 commit 1712166
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
60 changes: 60 additions & 0 deletions lib/MetaCPAN/Web/Controller/ContributingDoc.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package MetaCPAN::Web::Controller::ContributingDoc;

use Moose;
use namespace::autoclean;

BEGIN { extends 'MetaCPAN::Web::Controller' }

use List::Util ();

sub index : Chained('/') : PathPart('contributing-to') : CaptureArgs(0) {
}

sub release : Chained('index') : PathPart('') : Args(2) {
my ( $self, $c, $author, $release ) = @_;

# force consistent casing in URLs
if ( $author ne uc($author) ) {
$c->res->redirect(
$c->uri_for( $c->action, [ uc($author), $release ] ), 301 );
$c->detach();
}

$c->forward( 'get', [ $author, $release ] );
}

sub get : Private {
my ( $self, $c, @args ) = @_;

my $contributing_re = qr/(CONTRIBUTING|HACKING)/i;
my $files
= $c->model('API::Release')->interesting_files(@args)->get->{files};

my $file = List::Util::first { $_->{name} =~ /$contributing_re/ } @$files;

if ( !exists $file->{path} ) {
my $release = join q{/}, @args;
$c->stash( {
message => 'Ask the author on how to contribute to this release.',
suggest => {
description => 'Try the release info page',
url => $c->uri_for( '/release/' . $release ),
link_text => $release,
}
} );
$c->detach('/not_found');
}
else {
my $path = join '/' => @$file{qw(author release path)};
if ( $path =~ /\.pod$/ ) {
$c->res->redirect( "/pod/release/$path", 301 );
}
else {
$c->res->redirect( "/source/$path", 301 );
}
}
}

__PACKAGE__->meta->make_immutable;

1;
3 changes: 3 additions & 0 deletions root/inc/release-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<a class="nopopup" href="<% release.resources.homepage %>"><i class="fa fa-fw fa-external-link black"></i>Homepage</a>
</li>
<% END %>
<li>
<a class="nopopup" href="/contributing-to/<% [release.author, release.name].join('/') %>"><i class="fa fa-fw fa-plus-circle black"></i>How to Contribute</a>
</li>
<% IF release.resources.repository %>
<li>
<% IF is_url(release.resources.repository.web) %>
Expand Down

0 comments on commit 1712166

Please sign in to comment.