|
2 | 2 |
|
3 | 3 | use Alfred\Workflows\Workflow; |
4 | 4 |
|
5 | | -use AlgoliaSearch\Client as Algolia; |
6 | | -use AlgoliaSearch\Version as AlgoliaUserAgent; |
| 5 | +use Algolia\AlgoliaSearch\SearchClient as Algolia; |
| 6 | +use Algolia\AlgoliaSearch\Support\UserAgent as AlgoliaUserAgent; |
7 | 7 |
|
8 | 8 | require __DIR__ . '/vendor/autoload.php'; |
| 9 | +require __DIR__ . '/functions.php'; |
9 | 10 |
|
10 | 11 | $query = $argv[1]; |
11 | | -//$branch = empty($_ENV['branch']) ? 'master' : $_ENV['branch']; |
12 | | -//$subtext = empty($_ENV['alfred_theme_subtext']) ? '0' : $_ENV['alfred_theme_subtext']; |
13 | 12 |
|
14 | 13 | $workflow = new Workflow; |
15 | | -$parsedown = new Parsedown; |
16 | | -$algolia = new Algolia('R90K1756AM', 'a6e52654d6b591febdf42b07e0e7374a'); |
| 14 | +$algolia = Algolia::create('R90K1756AM', 'a6e52654d6b591febdf42b07e0e7374a'); |
17 | 15 |
|
18 | | -AlgoliaUserAgent::addSuffixUserAgentSegment('TailwindCSS Alfred Workflow', '2.0.0'); |
| 16 | +AlgoliaUserAgent::addCustomUserAgent('TailwindCSS Alfred Workflow', '2.0.1'); |
19 | 17 |
|
20 | | -$index = $algolia->initIndex('v2_tailwindcss'); |
21 | | -$search = $index->search($query); |
22 | | -$results = $search['hits']; |
23 | | - |
24 | | -$subtextSupported = $subtext === '0' || $subtext === '2'; |
| 18 | +$results = getResults($algolia, 'v2_tailwindcss', $query); |
25 | 19 |
|
26 | 20 | if (empty($results)) { |
27 | | - if (empty($results)) { |
28 | | - $workflow->result() |
29 | | - ->title('No matches') |
30 | | - ->icon('google.png') |
31 | | - ->subtitle("No match found in the docs. Search Google for: \"TailwindCSS+{$query}\"") |
32 | | - ->arg("https://www.google.com/search?q=tailwindcss+{$query}") |
33 | | - ->quicklookurl("https://www.google.com/search?q=tailwindcss+{$query}") |
34 | | - ->valid(true); |
| 21 | + $workflow->result() |
| 22 | + ->title('No matches') |
| 23 | + ->icon('google.png') |
| 24 | + ->subtitle("No match found in the docs. Search Google for: \"TailwindCSS+{$query}\"") |
| 25 | + ->arg("https://www.google.com/search?q=tailwindcss+{$query}") |
| 26 | + ->quicklookurl("https://www.google.com/search?q=tailwindcss+{$query}") |
| 27 | + ->valid(true); |
35 | 28 |
|
36 | | - echo $workflow->output(); |
37 | | - exit; |
38 | | - } |
| 29 | + echo $workflow->output(); |
39 | 30 | exit; |
40 | 31 | } |
41 | 32 |
|
42 | | -$urls = []; |
43 | | - |
44 | | - |
45 | 33 | foreach ($results as $hit) { |
46 | | - $highestLvl = $hit['hierarchy']['lvl6'] ? 6 : ( |
47 | | - $hit['hierarchy']['lvl5'] ? 5 : ( |
48 | | - $hit['hierarchy']['lvl4'] ? 4 : ( |
49 | | - $hit['hierarchy']['lvl3'] ? 3 : ( |
50 | | - $hit['hierarchy']['lvl2'] ? 2 : ( |
51 | | - $hit['hierarchy']['lvl1'] ? 1 : 0 |
52 | | - ) |
53 | | - ) |
54 | | - ) |
55 | | - ) |
56 | | - ); |
| 34 | + list($title, $titleLevel) = getTitle($hit); |
57 | 35 |
|
58 | | - $title = $hit['hierarchy']['lvl' . $highestLvl]; |
59 | | - $currentLvl = 0; |
60 | | - $subtitle = $hit['hierarchy']['lvl0']; |
61 | | - while ($currentLvl < $highestLvl) { |
62 | | - $currentLvl = $currentLvl + 1; |
63 | | - $subtitle = $subtitle . ' » ' . $hit['hierarchy']['lvl' . $currentLvl]; |
| 36 | + if ($title === null) { |
| 37 | + continue; |
64 | 38 | } |
65 | 39 |
|
| 40 | + $title = html_entity_decode($title); |
| 41 | + |
66 | 42 | $workflow->result() |
67 | 43 | ->uid($hit['objectID']) |
68 | 44 | ->title($title) |
69 | 45 | ->autocomplete($title) |
70 | | - ->subtitle($subtitle) |
| 46 | + ->subtitle(html_entity_decode(getSubtitle($hit, $titleLevel))) |
71 | 47 | ->arg($hit['url']) |
72 | 48 | ->quicklookurl($hit['url']) |
73 | 49 | ->valid(true); |
|
0 commit comments