Skip to content

Commit

Permalink
update to fix alternativeto and add nginx override for randword
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlang committed Apr 21, 2012
1 parent 70dca45 commit 5e195be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/DDG/Spice/AlternativeTo.pm
Expand Up @@ -14,22 +14,22 @@ handle query_lc => sub {
# license and platform specified - queries like:
# -> free alternative to firefox for mac
# -> opensource matlab for linux
return $2, "platform=".$3, "license=".$1;
return $2, "platform=".$3, "license=".$1.'/';
} elsif ($1 and $2) {
# lincense secified only:
# -> free nod32
# -> opensource alternative to omnigraffle
return $2, "license=".$1;
return $2, "license=".$1.'/';
} elsif ($3) {
# platform specified:
# -> TextMate for windows
# -> alternative to vim for linux
return $2, "platform=".$3;
return $2, "platform=".$3.'/';
} elsif($2) {
# license and platform not specified
# in this case we need to match 'alternative(s) to':
# -> alternative to firefox
return $2;
return $2.'/';
}
}
return;
Expand Down
17 changes: 15 additions & 2 deletions lib/DDG/Spice/RandWord.pm
@@ -1,16 +1,29 @@
package DDG::Spice::RandWord;
use DDG::Spice;

sub nginx_conf {
my $api_key = $ENV{WORDNIK_API_KEY};
$nginx_conf = <<"__END_OF_CONF__";
location ^~ /js/spice/rand_word/ {
rewrite ^$/js/spice/rand_word/(?:([0-9]+)\-([0-9]+)|) /v4/words.json/randomWord?minLength=$1&maxLength=$2&api_key=$api_key&callback=ddg_spice_rand_word break;
proxy_pass http://api.wordnik.com/;
}
__END_OF_CONF__
}

triggers any => "random", "word";
#spice is_memcached => 0;
handle query_lc => sub {
if ($_ =~ /^random word(?: ([0-9]+\-[0-9]+)|)$/) {
if ($1) {
return qq(/iwrd/$1);
return $1;
} else {
return qq(/iwrd/);
return;
}
# $is_kill_pre_results = 1;
}
return;
};
1;

0 comments on commit 5e195be

Please sign in to comment.