Skip to content

Commit a82af5a

Browse files
committed
import code
0 parents  commit a82af5a

10 files changed

+242
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
composer.lock

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Till Krüss
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Laravel Docs Workflow for Alfred
2+
3+
An ultra-fast Laravel docs search workflow for Alfred 3.
4+
5+
![Screenshot](screenshot.png)
6+
7+
## Installation
8+
9+
1. [Download the latest version](https://github.com/tillkruss/alfred-laravel-docs/releases/download/v0.1.0/Laravel.Docs.alfredworkflow)
10+
2. Install the workflow by double-clicking the `.alfredworkflow` file
11+
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.
12+
13+
## Usage
14+
15+
```
16+
ld <query>
17+
```
18+
19+
Just type `ld` followed by your search query.

composer.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"require": {
3+
"joetannenbaum/alfred-workflow": "^0.1.0",
4+
"algolia/algoliasearch-client-php": "^1.27",
5+
"erusev/parsedown": "^1.7"
6+
}
7+
}

google.png

6.02 KB
Loading

icon.png

20.4 KB
Loading

info.plist

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>bundleid</key>
6+
<string>com.tillkruss.laravel-docs</string>
7+
<key>category</key>
8+
<string>Development</string>
9+
<key>connections</key>
10+
<dict>
11+
<key>7B86D057-DA8E-4302-AF17-83B889B48EE2</key>
12+
<array>
13+
<dict>
14+
<key>destinationuid</key>
15+
<string>D449CB87-B64C-41F5-8FF0-C93C75686459</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>
24+
</dict>
25+
<key>createdby</key>
26+
<string>Till Krüss</string>
27+
<key>description</key>
28+
<string>An ultra-fast Laravel docs search workflow</string>
29+
<key>disabled</key>
30+
<false/>
31+
<key>name</key>
32+
<string>Laravel Docs</string>
33+
<key>objects</key>
34+
<array>
35+
<dict>
36+
<key>config</key>
37+
<dict>
38+
<key>browser</key>
39+
<string></string>
40+
<key>spaces</key>
41+
<string></string>
42+
<key>url</key>
43+
<string>{query}</string>
44+
<key>utf8</key>
45+
<true/>
46+
</dict>
47+
<key>type</key>
48+
<string>alfred.workflow.action.openurl</string>
49+
<key>uid</key>
50+
<string>D449CB87-B64C-41F5-8FF0-C93C75686459</string>
51+
<key>version</key>
52+
<integer>1</integer>
53+
</dict>
54+
<dict>
55+
<key>config</key>
56+
<dict>
57+
<key>alfredfiltersresults</key>
58+
<false/>
59+
<key>alfredfiltersresultsmatchmode</key>
60+
<integer>0</integer>
61+
<key>argumenttrimmode</key>
62+
<integer>0</integer>
63+
<key>argumenttype</key>
64+
<integer>0</integer>
65+
<key>escaping</key>
66+
<integer>127</integer>
67+
<key>keyword</key>
68+
<string>ld</string>
69+
<key>queuedelaycustom</key>
70+
<integer>3</integer>
71+
<key>queuedelayimmediatelyinitially</key>
72+
<true/>
73+
<key>queuedelaymode</key>
74+
<integer>0</integer>
75+
<key>queuemode</key>
76+
<integer>1</integer>
77+
<key>runningsubtext</key>
78+
<string>Searching docs for "{query}"...</string>
79+
<key>script</key>
80+
<string>php laravel.php "{query}"</string>
81+
<key>scriptargtype</key>
82+
<integer>0</integer>
83+
<key>scriptfile</key>
84+
<string></string>
85+
<key>subtext</key>
86+
<string>Search the Laravel docs...</string>
87+
<key>title</key>
88+
<string>Laravel</string>
89+
<key>type</key>
90+
<integer>0</integer>
91+
<key>withspace</key>
92+
<true/>
93+
</dict>
94+
<key>type</key>
95+
<string>alfred.workflow.input.scriptfilter</string>
96+
<key>uid</key>
97+
<string>7B86D057-DA8E-4302-AF17-83B889B48EE2</string>
98+
<key>version</key>
99+
<integer>2</integer>
100+
</dict>
101+
</array>
102+
<key>readme</key>
103+
<string></string>
104+
<key>uidata</key>
105+
<dict>
106+
<key>7B86D057-DA8E-4302-AF17-83B889B48EE2</key>
107+
<dict>
108+
<key>xpos</key>
109+
<integer>200</integer>
110+
<key>ypos</key>
111+
<integer>90</integer>
112+
</dict>
113+
<key>D449CB87-B64C-41F5-8FF0-C93C75686459</key>
114+
<dict>
115+
<key>xpos</key>
116+
<integer>510</integer>
117+
<key>ypos</key>
118+
<integer>90</integer>
119+
</dict>
120+
</dict>
121+
<key>variables</key>
122+
<dict>
123+
<key>branch</key>
124+
<string>5.6</string>
125+
</dict>
126+
<key>version</key>
127+
<string>0.1.0</string>
128+
<key>webaddress</key>
129+
<string>https://till.im</string>
130+
</dict>
131+
</plist>

laravel.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 = $_ENV['branch'] ?? '5.6';
12+
13+
$workflow = new Workflow;
14+
$parsedown = new Parsedown;
15+
$algolia = new Algolia('8BB87I11DE', '8e1d446d61fce359f69cd7c8b86a50de');
16+
17+
AlgoliaUserAgent::addSuffixUserAgentSegment('Alfred Workflow', '0.1.0');
18+
19+
$index = $algolia->initIndex('docs');
20+
$search = $index->search($query, ['tagFilters' => $branch]);
21+
$results = $search['hits'];
22+
23+
if (empty($results)) {
24+
$workflow->result()
25+
->title('No matches')
26+
->icon('google.png')
27+
->subtitle("No match found in the {$branch} docs. Search Google for: \"{$query}\"")
28+
->arg("https://www.google.com/search?q={$query}")
29+
->quicklookurl("https://www.google.com/search?q={$query}")
30+
->valid(true);
31+
32+
echo $workflow->output();
33+
exit;
34+
}
35+
36+
foreach ($results as $hit) {
37+
$hasText = isset($hit['_highlightResult']['content']['value']);
38+
$hasSubtitle = isset($hit['h2']);
39+
40+
$title = $hit['h1'];
41+
$subtitle = $hasSubtitle ? $hit['h2'] : null;
42+
43+
if ($hasSubtitle && $hasText) {
44+
$title = $hit['h2'];
45+
$subtitle = $hit['_highlightResult']['content']['value'];
46+
}
47+
48+
$title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
49+
50+
$subtitle = $parsedown->line($subtitle);
51+
$subtitle = strip_tags(html_entity_decode($subtitle, ENT_QUOTES, 'UTF-8'));
52+
53+
$workflow->result()
54+
->uid($hit['objectID'])
55+
->title($title)
56+
->autocomplete($title)
57+
->subtitle($subtitle)
58+
->arg("https://laravel.com/docs/{$branch}/{$hit['link']}")
59+
->quicklookurl("https://laravel.com/docs/{$branch}/{$hit['link']}")
60+
->valid(true);
61+
}
62+
63+
echo $workflow->output();

screenshot-sm.png

126 KB
Loading

screenshot.png

161 KB
Loading

0 commit comments

Comments
 (0)