|
7 | 7 | require __DIR__ . '/vendor/autoload.php';
|
8 | 8 |
|
9 | 9 | $query = $argv[1];
|
10 |
| -$branch = empty($_ENV['branch']) ? 'master' : $_ENV['branch']; |
11 | 10 |
|
12 | 11 | $workflow = new Workflow;
|
13 | 12 | $algolia = new Algolia('BH4D9OD16A', '85cc3221c9f23bfbaa4e3913dd7625ea');
|
14 | 13 |
|
15 |
| -AlgoliaUserAgent::addSuffixUserAgentSegment('Alfred Workflow', '0.2.1'); |
| 14 | +AlgoliaUserAgent::addSuffixUserAgentSegment('VueJS Alfred Workflow', '0.1.1'); |
16 | 15 |
|
17 | 16 | $index = $algolia->initIndex('vuejs');
|
18 | 17 | $search = $index->search($query, ['facetFilters' => 'version:v2']);
|
|
22 | 21 | $workflow->result()
|
23 | 22 | ->title('No matches')
|
24 | 23 | ->icon('google.png')
|
25 |
| - ->subtitle("No match found in the docs. Search Google for: \"{$query}\"") |
| 24 | + ->subtitle("No match found in the docs. Search Google for: \"VueJS+{$query}\"") |
26 | 25 | ->arg("https://www.google.com/search?q=vuejs+{$query}")
|
27 | 26 | ->quicklookurl("https://www.google.com/search?q=vuejs+{$query}")
|
28 | 27 | ->valid(true);
|
|
32 | 31 | }
|
33 | 32 |
|
34 | 33 | foreach ($results as $hit) {
|
35 |
| - $hasText = isset($hit['_highlightResult']['content']['value']); |
36 |
| - $hasSubtitle = isset($hit['h2']); |
37 |
| - |
38 |
| - $title = $hit['h1']; |
39 |
| - $subtitle = $hasSubtitle ? $hit['h2'] : null; |
40 |
| - |
41 |
| - if ($hasText) { |
42 |
| - $subtitle = $hit['_highlightResult']['content']['value']; |
43 |
| - |
44 |
| - if ($hasSubtitle) { |
45 |
| - $title = "{$title} » {$hit['h2']}"; |
46 |
| - } |
| 34 | + $highestLvl = $hit['hierarchy']['lvl6'] ? 6 : ( |
| 35 | + $hit['hierarchy']['lvl5'] ? 5 : ( |
| 36 | + $hit['hierarchy']['lvl4'] ? 4 : ( |
| 37 | + $hit['hierarchy']['lvl3'] ? 3 : ( |
| 38 | + $hit['hierarchy']['lvl2'] ? 2 : ( |
| 39 | + $hit['hierarchy']['lvl1'] ? 1 : 0 |
| 40 | + ) |
| 41 | + ) |
| 42 | + ) |
| 43 | + ) |
| 44 | + ); |
| 45 | + |
| 46 | + $title = $hit['hierarchy']['lvl' . $highestLvl]; |
| 47 | + $currentLvl = 0; |
| 48 | + $subtitle = $hit['hierarchy']['lvl0']; |
| 49 | + while ($currentLvl < $highestLvl) { |
| 50 | + $currentLvl = $currentLvl + 1; |
| 51 | + $subtitle = $subtitle . ' » ' . $hit['hierarchy']['lvl' . $currentLvl]; |
47 | 52 | }
|
48 | 53 |
|
49 |
| - $title = $hit['hierarchy']['lvl6'] ?: $hit['hierarchy']['lvl5'] ?: $hit['hierarchy']['lvl4'] ?: $hit['hierarchy']['lvl2'] ?: $hit['hierarchy']['lvl1'] ?: $hit['hierarchy']['lvl0']; |
50 |
| - |
51 |
| - $subtitle = $hit['hierarchy']['lvl0'] . ($hit['hierarchy']['lvl1'] ? ' => ' . $hit['hierarchy']['lvl1'] : ''); |
52 |
| - |
53 | 54 | $workflow->result()
|
54 | 55 | ->uid($hit['objectID'])
|
55 | 56 | ->title($title)
|
|
0 commit comments