Skip to content

Commit 794f8a8

Browse files
committed
Merge pull request #1283 from haarg/404-search-terms
use args or captures to pick search terms on 404
2 parents 82c88e1 + 4eac484 commit 794f8a8

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/MetaCPAN/Web/Controller/Root.pm

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ sub default : Path {
5454

5555
sub not_found : Private {
5656
my ( $self, $c ) = @_;
57-
$c->stash( { template => 'not_found.html' } );
57+
$c->stash(
58+
{
59+
template => 'not_found.html',
60+
search => [ @{ $c->req->args }, @{ $c->req->captures } ],
61+
}
62+
);
5863
$c->response->status(404);
5964
}
6065

root/not_found.html

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ <h1>Not Found</h1>
1919
<% END %>
2020

2121
<%
22-
# FIXME: this drops the first two url components and suggests a search
23-
# for the rest (which makes fragile assumptions).
24-
q = req.path.split('/');
25-
IF q.size > 2;
26-
q = q.splice(2, 99).join(" ");
22+
IF search and search.size;
23+
q = search.join(" ");
2724
%>
2825
<p>
29-
Search the CPAN for <a href="/search?q=<% q %>"><% q %></a>
26+
Search the CPAN for <a href="/search?q=<% q | url %>"><% q %></a>
3027
</p>
3128
<% END %>
3229
</p>

0 commit comments

Comments
 (0)