Skip to content

Commit 312c500

Browse files
committed
Add beta docs search, use twb
1 parent ba0f5e7 commit 312c500

File tree

5 files changed

+196
-8
lines changed

5 files changed

+196
-8
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ Adapted from [Alfred VueJS Docs](https://github.com/vmitchell85/alfred-vuejs-doc
1414

1515
## Usage
1616

17+
Just type `tw` followed by your search query.
18+
1719
```
1820
tw <query>
1921
```
2022

21-
Just type `tw` followed by your search query.
23+
To search the [beta docs](https://next.tailwindcss.com/docs), just type `twb` followed by your search query.
24+
25+
```
26+
twb <query>
27+
```
2228

2329
![Search by Algolia](algolia.png)

beta_tailwindcss.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
use Alfred\Workflows\Workflow;
4+
5+
use AlgoliaSearch\Client as Algolia;
6+
use AlgoliaSearch\Version as AlgoliaUserAgent;
7+
8+
require __DIR__ . '/vendor/autoload.php';
9+
10+
$query = $argv[1];
11+
//$branch = empty($_ENV['branch']) ? 'master' : $_ENV['branch'];
12+
//$subtext = empty($_ENV['alfred_theme_subtext']) ? '0' : $_ENV['alfred_theme_subtext'];
13+
14+
$workflow = new Workflow;
15+
$parsedown = new Parsedown;
16+
$algolia = new Algolia('R90K1756AM', 'a6e52654d6b591febdf42b07e0e7374a');
17+
18+
AlgoliaUserAgent::addSuffixUserAgentSegment('TailwindCSS Alfred Workflow', '1.0.0');
19+
20+
$index = $algolia->initIndex('beta_tailwindcss');
21+
$search = $index->search($query);
22+
$results = $search['hits'];
23+
24+
$subtextSupported = $subtext === '0' || $subtext === '2';
25+
26+
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);
35+
36+
echo $workflow->output();
37+
exit;
38+
}
39+
exit;
40+
}
41+
42+
$urls = [];
43+
44+
45+
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+
);
57+
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];
64+
}
65+
66+
$workflow->result()
67+
->uid($hit['objectID'])
68+
->title($title)
69+
->autocomplete($title)
70+
->subtitle($subtitle)
71+
->arg($hit['url'])
72+
->quicklookurl($hit['url'])
73+
->valid(true);
74+
}
75+
76+
echo $workflow->output();

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "clnt/alfred-tailwindcss-docs",
33
"description": "An ultra-fast TailwindCSS docs search workflow for Alfred 3.",
4-
"version": "0.1.0",
4+
"version": "1.0.0",
55
"keywords": ["alfred", "alfred-workflow", "tailwindcss", "algolia"],
66
"homepage": "https://github.com/clnt",
77
"support": {

info.plist

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
<string>Productivity</string>
99
<key>connections</key>
1010
<dict>
11+
<key>89F02255-0DA5-4773-896A-BF05292D2CE8</key>
12+
<array>
13+
<dict>
14+
<key>destinationuid</key>
15+
<string>1BC09BF1-F684-4789-897B-F70B225A4D72</string>
16+
<key>modifiers</key>
17+
<integer>0</integer>
18+
<key>modifiersubtext</key>
19+
<string></string>
20+
<key>vitoclose</key>
21+
<false/>
22+
</dict>
23+
</array>
1124
<key>BA0F1293-0A15-462E-966E-7C84BCFBC501</key>
1225
<array>
1326
<dict>
@@ -98,6 +111,72 @@
98111
<key>version</key>
99112
<integer>2</integer>
100113
</dict>
114+
<dict>
115+
<key>config</key>
116+
<dict>
117+
<key>browser</key>
118+
<string></string>
119+
<key>spaces</key>
120+
<string></string>
121+
<key>url</key>
122+
<string>{query}</string>
123+
<key>utf8</key>
124+
<true/>
125+
</dict>
126+
<key>type</key>
127+
<string>alfred.workflow.action.openurl</string>
128+
<key>uid</key>
129+
<string>1BC09BF1-F684-4789-897B-F70B225A4D72</string>
130+
<key>version</key>
131+
<integer>1</integer>
132+
</dict>
133+
<dict>
134+
<key>config</key>
135+
<dict>
136+
<key>alfredfiltersresults</key>
137+
<false/>
138+
<key>alfredfiltersresultsmatchmode</key>
139+
<integer>0</integer>
140+
<key>argumenttrimmode</key>
141+
<integer>0</integer>
142+
<key>argumenttype</key>
143+
<integer>0</integer>
144+
<key>escaping</key>
145+
<integer>127</integer>
146+
<key>keyword</key>
147+
<string>twb</string>
148+
<key>queuedelaycustom</key>
149+
<integer>3</integer>
150+
<key>queuedelayimmediatelyinitially</key>
151+
<true/>
152+
<key>queuedelaymode</key>
153+
<integer>0</integer>
154+
<key>queuemode</key>
155+
<integer>1</integer>
156+
<key>runningsubtext</key>
157+
<string>Searching docs for "{query}"...</string>
158+
<key>script</key>
159+
<string>php beta_tailwindcss.php "{query}"</string>
160+
<key>scriptargtype</key>
161+
<integer>0</integer>
162+
<key>scriptfile</key>
163+
<string></string>
164+
<key>subtext</key>
165+
<string>Search the TailwindCSS Beta docs...</string>
166+
<key>title</key>
167+
<string>TailwindCSS Beta</string>
168+
<key>type</key>
169+
<integer>0</integer>
170+
<key>withspace</key>
171+
<true/>
172+
</dict>
173+
<key>type</key>
174+
<string>alfred.workflow.input.scriptfilter</string>
175+
<key>uid</key>
176+
<string>89F02255-0DA5-4773-896A-BF05292D2CE8</string>
177+
<key>version</key>
178+
<integer>2</integer>
179+
</dict>
101180
</array>
102181
<key>readme</key>
103182
<string>An ultra-fast TailwindCSS docs search workflow for Alfred 3.
@@ -108,29 +187,49 @@ Just type `tw` followed by your search query.
108187
109188
```
110189
tw &lt;query&gt;
111-
tw preview mailables
190+
tw font-family
191+
```
192+
193+
To search the beta docs at `https://next.tailwindcss.com/docs`, just type `twb` followed by your search query.
194+
195+
```
196+
twb &lt;query&gt;
112197
```
113198
114199
Either press `⌘Y` to Quick Look the result, or press `&lt;enter&gt;` to open it in your web browser.</string>
115200
<key>uidata</key>
116201
<dict>
202+
<key>1BC09BF1-F684-4789-897B-F70B225A4D72</key>
203+
<dict>
204+
<key>xpos</key>
205+
<integer>650</integer>
206+
<key>ypos</key>
207+
<integer>250</integer>
208+
</dict>
209+
<key>89F02255-0DA5-4773-896A-BF05292D2CE8</key>
210+
<dict>
211+
<key>xpos</key>
212+
<integer>340</integer>
213+
<key>ypos</key>
214+
<integer>250</integer>
215+
</dict>
117216
<key>A0BE7549-BF89-4E85-86DC-E30C0D797564</key>
118217
<dict>
119218
<key>xpos</key>
120-
<integer>510</integer>
219+
<integer>650</integer>
121220
<key>ypos</key>
122221
<integer>90</integer>
123222
</dict>
124223
<key>BA0F1293-0A15-462E-966E-7C84BCFBC501</key>
125224
<dict>
126225
<key>xpos</key>
127-
<integer>200</integer>
226+
<integer>340</integer>
128227
<key>ypos</key>
129228
<integer>90</integer>
130229
</dict>
131230
</dict>
132231
<key>version</key>
133-
<string>0.1.0</string>
232+
<string>1.0.0</string>
134233
<key>webaddress</key>
135234
<string>https://github.com/clnt</string>
136235
</dict>

tailwindcss.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88
require __DIR__ . '/vendor/autoload.php';
99

1010
$query = $argv[1];
11+
//$branch = empty($_ENV['branch']) ? 'master' : $_ENV['branch'];
12+
//$subtext = empty($_ENV['alfred_theme_subtext']) ? '0' : $_ENV['alfred_theme_subtext'];
1113

1214
$workflow = new Workflow;
1315
$parsedown = new Parsedown;
14-
$algolia = new Algolia('R90K1756AM', 'cd63556797a9e2dc23249752a4e33b67');
16+
$algolia = new Algolia('R90K1756AM', 'a6e52654d6b591febdf42b07e0e7374a');
1517

16-
AlgoliaUserAgent::addSuffixUserAgentSegment('TailwindCSS Alfred Workflow', '0.1.0');
18+
AlgoliaUserAgent::addSuffixUserAgentSegment('TailwindCSS Alfred Workflow', '1.0.0');
1719

1820
$index = $algolia->initIndex('tailwindcss');
1921
$search = $index->search($query);
2022
$results = $search['hits'];
2123

24+
$subtextSupported = $subtext === '0' || $subtext === '2';
25+
2226
if (empty($results)) {
2327
if (empty($results)) {
2428
$workflow->result()
@@ -35,6 +39,9 @@
3539
exit;
3640
}
3741

42+
$urls = [];
43+
44+
3845
foreach ($results as $hit) {
3946
$highestLvl = $hit['hierarchy']['lvl6'] ? 6 : (
4047
$hit['hierarchy']['lvl5'] ? 5 : (

0 commit comments

Comments
 (0)