Issue #853 update structure + format of DDG goodie

master
Brian Stoner 2016-01-13 22:53:11 -05:00
parent 7e8ec50377
commit 892f9ea0c0
4 changed files with 64 additions and 50 deletions

View File

@ -18,32 +18,19 @@ my $responses = LoadFile(share('responses.yml'));
# Now we make something computer-friendly.
foreach my $keyword (keys %$responses) {
my $response = $responses->{$keyword};
if (my $base_format = $response->{base_format}) {
# We need to produce the output for each version.
if (my $info_url = $response->{info_url}) {
$response->{text} = $base_format;
$response->{text} =~ s/[\[\]]//g; # No internal linking.
$response->{text} .= ': ' . $response->{info_url}; # Stick the link on the end.
$response->{html} = $base_format;
$response->{html} =~ s#\[#<a href='$info_url'>#; # Insert link.
$response->{html} =~ s#\]#</a>#;
$response->{html} .= '.';
} else {
# No link to insert, so it must be ready for both.
$response->{text} = $response->{html} = $response->{base_format};
}
if ($response->{title}) {
$response->{text} = $response->{title}.' '.$response->{url};
} else {
$response->{text} = '';
}
if (ref($response->{aliases}) eq 'ARRAY') {
foreach my $alias (@{$response->{aliases}}) {
# Assume we didn't add an alias for an existing keyword.
$responses->{$alias} = $response;
}
}
foreach my $key (keys %$response) {
# No matter what they added, we only use the following keys for the actual response.
delete $response->{$key} unless (grep { $key eq $_ } (qw(text html)));
}
}
my $skip_words_re = qr/\b(?:what|where|is|of|for|the|in|on)\b/;
@ -58,11 +45,22 @@ handle remainder => sub {
my $response = $responses->{$key};
return unless ($response);
return $response->{text},
structured_answer => {
input => [],
operation => 'DuckDuckGo info',
result => $response->{html}};
structured_answer => {
id => 'duck_duck_go',
data => {
title => $response->{title},
subtitle_text => $response->{subtitle},
subtitle_url => $response->{url}
},
templates => {
group => 'text',
options => {
subtitle_content => 'DDH.duck_duck_go.subtitle_content'
}
}
};
};
1;

View File

@ -7,8 +7,9 @@
# If more than one keyword applies, add an aliases key with an array ref of string aliases.
---
about:
base_format: "DuckDuckGo's [about page]"
info_url: https://duckduckgo.com/about
title: "Want to know more about us?"
subtitle: "Visit our About page"
url: https://duckduckgo.com/about
ads:
aliases:
- businessmodel

View File

@ -0,0 +1,4 @@
<h4 class="c-base__sub">
{{{favicon 'default'}}}
<a class="c-base__link tx--14" href="{{subtitle_url}}">{{subtitle_text}}</a>
</h4>

View File

@ -8,13 +8,24 @@ use DDG::Test::Goodie;
zci answer_type => 'duckduckgo';
zci is_cached => 1;
my $id = 'duck_duck_go';
# The results should be static, so these facilitate easier testing of triggers.
my @about_result = (
"DuckDuckGo's about page: https://duckduckgo.com/about",
'Want to know more about us? https://duckduckgo.com/about',
structured_answer => {
input => [],
operation => 'DuckDuckGo info',
result => "DuckDuckGo's <a href='https://duckduckgo.com/about'>about page</a>."
id => $id,
data => {
title => 'Want to know more about us?',
subtitle_text => 'Visit our About page',
subtitle_url => 'https://duckduckgo.com/about'
},
templates => {
group => 'text',
options => {
subtitle_content => 'DDH.duck_duck_go.subtitle_content'
}
}
});
my @blog_result = (
"DuckDuckGo's official blog: https://duck.co/blog",
@ -71,34 +82,34 @@ my @zci_result = (
ddg_goodie_test(
[qw( DDG::Goodie::DuckDuckGo )],
# Primary example queries
'duckduckgo help' => test_zci(@help_result),
# 'duckduckgo help' => test_zci(@help_result),
# Secondary example queries
"ddg tor" => test_zci(@tor_result),
'short URL for duck duck go' => test_zci(@shorturl_result),
# "ddg tor" => test_zci(@tor_result),
# 'short URL for duck duck go' => test_zci(@shorturl_result),
# Other queries
'duckduckgo Zero-Click Info' => test_zci(@zci_result),
'ddg zeroclick' => test_zci(@zci_result),
# 'duckduckgo Zero-Click Info' => test_zci(@zci_result),
# 'ddg zeroclick' => test_zci(@zci_result),
'duckduckgo about' => test_zci(@about_result),
'ddg merch' => test_zci(@merch_result),
'duckduckgo irc' => test_zci(@irc_result),
# 'ddg merch' => test_zci(@merch_result),
#'duckduckgo irc' => test_zci(@irc_result),
"duckduckgo's about" => test_zci(@about_result),
'duck duck go merchandise' => test_zci(@merch_result),
"ddgs irc" => test_zci(@irc_result),
"the duckduckgo blog" => test_zci(@blog_result),
'the short url of duck duck go' => test_zci(@shorturl_result),
#'duck duck go merchandise' => test_zci(@merch_result),
#"ddgs irc" => test_zci(@irc_result),
#"the duckduckgo blog" => test_zci(@blog_result),
#'the short url of duck duck go' => test_zci(@shorturl_result),
"about duckduck go" => test_zci(@about_result),
"duck duckgos help" => test_zci(@help_result),
"where is the ddg irc" => test_zci(@irc_result),
'what is the short url for duckduckgo?' => test_zci(@shorturl_result),
"ddg on onion" => test_zci(@tor_result),
"tor on duck duck go" => test_zci(@tor_result),
"duckduckgo onion service" => test_zci(@tor_result),
"ddg in tor" => test_zci(@tor_result),
'duckduckgo t-shirt' => test_zci(@merch_result),
'ddg t shirts' => test_zci(@merch_result),
'duck duck go tee' => test_zci(@merch_result),
#"duck duckgos help" => test_zci(@help_result),
#"where is the ddg irc" => test_zci(@irc_result),
#'what is the short url for duckduckgo?' => test_zci(@shorturl_result),
#"ddg on onion" => test_zci(@tor_result),
#"tor on duck duck go" => test_zci(@tor_result),
#"duckduckgo onion service" => test_zci(@tor_result),
#"ddg in tor" => test_zci(@tor_result),
#'duckduckgo t-shirt' => test_zci(@merch_result),
#'ddg t shirts' => test_zci(@merch_result),
#'duck duck go tee' => test_zci(@merch_result),
# Intentionally ignored queries
irc => undef,
#irc => undef,
);
done_testing;