Skip to content

Commit 957ba67

Browse files
authored
Merge pull request #10 from clnt/2.0.1-dev
PHP 8.0 Support + macOS Monterey Support
2 parents 22a0360 + 6af5f3a commit 957ba67

File tree

7 files changed

+139
-141
lines changed

7 files changed

+139
-141
lines changed

README.md

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

99
## Installation
1010

11-
1. [Download the latest version](https://github.com/clnt/alfred-tailwindcss-docs/releases/download/v2.0.0/TailwindCSSDocs.alfredworkflow)
11+
12+
> **macOS Monterey:** PHP is no longer shipped with macOS, before attempting to use this workflow ensure you have installed the php binary via Homebrew.
13+
14+
1. [Download the latest version](https://github.com/clnt/alfred-tailwindcss-docs/releases/download/v2.0.1/TailwindCSSDocs.alfredworkflow)
1215
2. Install the workflow by double-clicking the `.alfredworkflow` file
1316
3. You can add the workflow to a category, then click "Import" to finish importing. You'll now see the workflow listed in the left sidebar of your Workflows preferences pane.
1417

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "clnt/alfred-tailwindcss-docs",
3-
"description": "An ultra-fast TailwindCSS docs search workflow for Alfred 3.",
4-
"version": "1.1.0",
3+
"description": "An ultra-fast TailwindCSS docs search workflow for Alfred 4.",
4+
"version": "2.0.1",
55
"keywords": ["alfred", "alfred-workflow", "tailwindcss", "algolia"],
66
"homepage": "https://github.com/clnt",
77
"support": {
@@ -11,7 +11,6 @@
1111
"license": "MIT",
1212
"require": {
1313
"joetannenbaum/alfred-workflow": "^0.1.0",
14-
"algolia/algoliasearch-client-php": "^1.27",
15-
"erusev/parsedown": "^1.7"
14+
"algolia/algoliasearch-client-php": "^2.7"
1615
}
1716
}

functions.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
function getResults($algolia, $indexName, $query)
4+
{
5+
$index = $algolia->initIndex($indexName);
6+
7+
return $index->search($query)['hits'];
8+
}
9+
10+
function getTitle($hit)
11+
{
12+
if (isset($hit['hierarchy']['lvl6'])) {
13+
return [$hit['hierarchy']['lvl6'], 6];
14+
}
15+
16+
if (isset($hit['hierarchy']['lvl5'])) {
17+
return [$hit['hierarchy']['lvl5'], 5];
18+
}
19+
20+
if (isset($hit['hierarchy']['lvl4'])) {
21+
return [$hit['hierarchy']['lvl4'], 4];
22+
}
23+
24+
if (isset($hit['hierarchy']['lvl3'])) {
25+
return [$hit['hierarchy']['lvl3'], 3];
26+
}
27+
28+
if (isset($hit['hierarchy']['lvl2'])) {
29+
return [$hit['hierarchy']['lvl2'], 2];
30+
}
31+
32+
if (isset($hit['hierarchy']['lvl1'])) {
33+
return [$hit['hierarchy']['lvl1'], 1];
34+
}
35+
36+
return [null, null];
37+
}
38+
39+
function getSubtitle($hit, $titleLevel)
40+
{
41+
$currentLevel = 0;
42+
$subtitle = $hit['hierarchy']['lvl0'];
43+
44+
while ($currentLevel < $titleLevel) {
45+
$currentLevel++;
46+
$subtitle .= ' » ' . $hit['hierarchy']['lvl' . $currentLevel];
47+
}
48+
49+
return $subtitle;
50+
}

info.plist

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@
105105
<key>runningsubtext</key>
106106
<string>Searching docs for "{query}"...</string>
107107
<key>script</key>
108-
<string>php tailwindcss.php "{query}"</string>
108+
<string>if [ -f "/opt/homebrew/bin/php" ]; then
109+
/opt/homebrew/bin/php tailwindcss.php "{query}"
110+
elif [ -f "/usr/local/bin/php" ]; then
111+
/usr/local/bin/php tailwindcss.php "{query}"
112+
elif [ -f "/usr/bin/php" ]; then
113+
/usr/bin/php tailwindcss.php "{query}"
114+
fi</string>
109115
<key>scriptargtype</key>
110116
<integer>0</integer>
111117
<key>scriptfile</key>
@@ -173,7 +179,13 @@
173179
<key>runningsubtext</key>
174180
<string>Searching docs for "{query}"...</string>
175181
<key>script</key>
176-
<string>php v0_tailwindcss.php "{query}"</string>
182+
<string>if [ -f "/opt/homebrew/bin/php" ]; then
183+
/opt/homebrew/bin/php v0_tailwindcss.php "{query}"
184+
elif [ -f "/usr/local/bin/php" ]; then
185+
/usr/local/bin/php v0_tailwindcss.php "{query}"
186+
elif [ -f "/usr/bin/php" ]; then
187+
/usr/bin/php v0_tailwindcss.php "{query}"
188+
fi</string>
177189
<key>scriptargtype</key>
178190
<integer>0</integer>
179191
<key>scriptfile</key>
@@ -241,7 +253,13 @@
241253
<key>runningsubtext</key>
242254
<string>Searching docs for "{query}"...</string>
243255
<key>script</key>
244-
<string>php v1_tailwindcss.php "{query}"</string>
256+
<string>if [ -f "/opt/homebrew/bin/php" ]; then
257+
/opt/homebrew/bin/php v1_tailwindcss.php "{query}"
258+
elif [ -f "/usr/local/bin/php" ]; then
259+
/usr/local/bin/php v1_tailwindcss.php "{query}"
260+
elif [ -f "/usr/bin/php" ]; then
261+
/usr/bin/php v1_tailwindcss.php "{query}"
262+
fi</string>
245263
<key>scriptargtype</key>
246264
<integer>0</integer>
247265
<key>scriptfile</key>
@@ -335,7 +353,7 @@ Either press `⌘Y` to Quick Look the result, or press `&lt;enter&gt;` to open i
335353
<key>variablesdontexport</key>
336354
<array/>
337355
<key>version</key>
338-
<string>2.0.0</string>
356+
<string>2.0.1</string>
339357
<key>webaddress</key>
340358
<string>https://github.com/clnt/alfred-tailwindcss-docs</string>
341359
</dict>

tailwindcss.php

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,48 @@
22

33
use Alfred\Workflows\Workflow;
44

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;
77

88
require __DIR__ . '/vendor/autoload.php';
9+
require __DIR__ . '/functions.php';
910

1011
$query = $argv[1];
11-
//$branch = empty($_ENV['branch']) ? 'master' : $_ENV['branch'];
12-
//$subtext = empty($_ENV['alfred_theme_subtext']) ? '0' : $_ENV['alfred_theme_subtext'];
1312

1413
$workflow = new Workflow;
15-
$parsedown = new Parsedown;
16-
$algolia = new Algolia('R90K1756AM', 'a6e52654d6b591febdf42b07e0e7374a');
14+
$algolia = Algolia::create('R90K1756AM', 'a6e52654d6b591febdf42b07e0e7374a');
1715

18-
AlgoliaUserAgent::addSuffixUserAgentSegment('TailwindCSS Alfred Workflow', '2.0.0');
16+
AlgoliaUserAgent::addCustomUserAgent('TailwindCSS Alfred Workflow', '2.0.1');
1917

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);
2519

2620
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);
3528

36-
echo $workflow->output();
37-
exit;
38-
}
29+
echo $workflow->output();
3930
exit;
4031
}
4132

42-
$urls = [];
43-
44-
4533
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);
5735

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;
6438
}
6539

40+
$title = html_entity_decode($title);
41+
6642
$workflow->result()
6743
->uid($hit['objectID'])
6844
->title($title)
6945
->autocomplete($title)
70-
->subtitle($subtitle)
46+
->subtitle(html_entity_decode(getSubtitle($hit, $titleLevel)))
7147
->arg($hit['url'])
7248
->quicklookurl($hit['url'])
7349
->valid(true);

v0_tailwindcss.php

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,48 @@
22

33
use Alfred\Workflows\Workflow;
44

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;
77

88
require __DIR__ . '/vendor/autoload.php';
9+
require __DIR__ . '/functions.php';
910

1011
$query = $argv[1];
11-
//$branch = empty($_ENV['branch']) ? 'master' : $_ENV['branch'];
12-
//$subtext = empty($_ENV['alfred_theme_subtext']) ? '0' : $_ENV['alfred_theme_subtext'];
1312

1413
$workflow = new Workflow;
15-
$parsedown = new Parsedown;
16-
$algolia = new Algolia('R90K1756AM', 'a6e52654d6b591febdf42b07e0e7374a');
14+
$algolia = Algolia::create('R90K1756AM', 'a6e52654d6b591febdf42b07e0e7374a');
1715

18-
AlgoliaUserAgent::addSuffixUserAgentSegment('TailwindCSS Alfred Workflow', '2.0.0');
16+
AlgoliaUserAgent::addCustomUserAgent('TailwindCSS Alfred Workflow', '2.0.1');
1917

20-
$index = $algolia->initIndex('v0_tailwindcss');
21-
$search = $index->search($query);
22-
$results = $search['hits'];
23-
24-
$subtextSupported = $subtext === '0' || $subtext === '2';
18+
$results = getResults($algolia, 'v0_tailwindcss', $query);
2519

2620
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);
3528

36-
echo $workflow->output();
37-
exit;
38-
}
29+
echo $workflow->output();
3930
exit;
4031
}
4132

42-
$urls = [];
43-
44-
4533
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);
5735

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;
6438
}
6539

40+
$title = html_entity_decode($title);
41+
6642
$workflow->result()
6743
->uid($hit['objectID'])
6844
->title($title)
6945
->autocomplete($title)
70-
->subtitle($subtitle)
46+
->subtitle(html_entity_decode(getSubtitle($hit, $titleLevel)))
7147
->arg($hit['url'])
7248
->quicklookurl($hit['url'])
7349
->valid(true);

0 commit comments

Comments
 (0)