-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvuejs.php
64 lines (52 loc) · 1.8 KB
/
vuejs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
use Alfred\Workflows\Workflow;
use AlgoliaSearch\Client as Algolia;
use AlgoliaSearch\Version as AlgoliaUserAgent;
require __DIR__ . '/vendor/autoload.php';
$query = $argv[1];
$workflow = new Workflow;
$algolia = new Algolia('BH4D9OD16A', '85cc3221c9f23bfbaa4e3913dd7625ea');
AlgoliaUserAgent::addSuffixUserAgentSegment('VueJS Alfred Workflow', '0.1.1');
$index = $algolia->initIndex('vuejs');
$search = $index->search($query, ['facetFilters' => 'version:v2']);
$results = $search['hits'];
if (empty($results)) {
$workflow->result()
->title('No matches')
->icon('google.png')
->subtitle("No match found in the docs. Search Google for: \"VueJS+{$query}\"")
->arg("https://www.google.com/search?q=vuejs+{$query}")
->quicklookurl("https://www.google.com/search?q=vuejs+{$query}")
->valid(true);
echo $workflow->output();
exit;
}
foreach ($results as $hit) {
$highestLvl = $hit['hierarchy']['lvl6'] ? 6 : (
$hit['hierarchy']['lvl5'] ? 5 : (
$hit['hierarchy']['lvl4'] ? 4 : (
$hit['hierarchy']['lvl3'] ? 3 : (
$hit['hierarchy']['lvl2'] ? 2 : (
$hit['hierarchy']['lvl1'] ? 1 : 0
)
)
)
)
);
$title = $hit['hierarchy']['lvl' . $highestLvl];
$currentLvl = 0;
$subtitle = $hit['hierarchy']['lvl0'];
while ($currentLvl < $highestLvl) {
$currentLvl = $currentLvl + 1;
$subtitle = $subtitle . ' » ' . $hit['hierarchy']['lvl' . $currentLvl];
}
$workflow->result()
->uid($hit['objectID'])
->title($title)
->autocomplete($title)
->subtitle($subtitle)
->arg($hit['url'])
->quicklookurl($hit['url'])
->valid(true);
}
echo $workflow->output();