Skip to content

Commit dfd1e28

Browse files
committed
First release
0 parents  commit dfd1e28

12 files changed

+413
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
vendor

AlpasDocs.alfredworkflow

387 KB
Binary file not shown.

LICENSE

Lines changed: 21 additions & 0 deletions
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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# [Alpas Docs](https://alpas.dev/docs) Workflow for Alfred
2+
3+
Alpas docs search workflow for Alfred.
4+
5+
![Screenshot](screenshot.png)
6+
7+
## Installation
8+
9+
1. [Download the latest version](https://github.com/alpas/docs-alfred-workflow/releases/download/v1.0.0/AlpasDocs.alfredworkflow)
10+
2. Double-click the `.alfredworkflow` file to install it.
11+
3. Add the workflow to a category, then click `Import`.
12+
13+
## Usage
14+
15+
Type `al` followed by a search term to see the result. While selected, hit `⌘+y` for quickly viewing the documentation of the selected search result or hit enter to browse it online.
16+
17+
```
18+
al <query>
19+
```
20+
21+
![Search by Algolia](algolia.png)

algolia.png

3.43 KB
Loading

alpas.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
use Alfred\Workflows\Workflow;
4+
use AlgoliaSearch\Client as Algolia;
5+
use AlgoliaSearch\Version as AlgoliaUserAgent;
6+
7+
require __DIR__.'/vendor/autoload.php';
8+
9+
$query = $argv[1];
10+
11+
$workflow = new Workflow;
12+
$parsedown = new Parsedown;
13+
$algolia = new Algolia('BH4D9OD16A', 'e017bb0b99fe3193f750d48a4e7d441e');
14+
15+
AlgoliaUserAgent::addSuffixUserAgentSegment('Alpas Docs Alfred Workflow', '1.0.0');
16+
17+
$index = $algolia->initIndex('alpas');
18+
$search = $index->search($query);
19+
$results = $search['hits'];
20+
21+
$subtextSupported = $subtext === '0' || $subtext === '2';
22+
23+
if (empty($results)) {
24+
if (empty($results)) {
25+
$workflow->result()
26+
->title('No matches')
27+
->icon('google.png')
28+
->subtitle("No match found in the docs. Search Google for: \"Alpas+{$query}\"")
29+
->arg("https://www.google.com/search?q=alpas+{$query}")
30+
->quicklookurl("https://www.google.com/search?q=alpas+{$query}")
31+
->valid(true);
32+
33+
echo $workflow->output();
34+
exit;
35+
}
36+
exit;
37+
}
38+
39+
$urls = [];
40+
41+
42+
foreach ($results as $hit) {
43+
$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)))));
44+
45+
$title = $hit['hierarchy']['lvl'.$highestLvl];
46+
$currentLvl = 0;
47+
$subtitle = $hit['hierarchy']['lvl0'];
48+
while ($currentLvl < $highestLvl) {
49+
$currentLvl = $currentLvl + 1;
50+
$subtitle = $subtitle.' » '.$hit['hierarchy']['lvl'.$currentLvl];
51+
}
52+
53+
$workflow->result()
54+
->uid($hit['objectID'])
55+
->title($title)
56+
->autocomplete($title)
57+
->subtitle($subtitle)
58+
->arg($hit['url'])
59+
->quicklookurl($hit['url'])
60+
->valid(true);
61+
}
62+
63+
echo $workflow->output();

composer.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "alpas/docsalfred",
3+
"description": "Alpas docs search workflow for Alfred.",
4+
"version": "1.1.0",
5+
"keywords": ["alfred", "alfred-workflow", "alpas", "algolia"],
6+
"homepage": "https://github.com/alpas",
7+
"support": {
8+
"source": "https://github.com/alpas/docs-alfred-workflow",
9+
"issues": "https://github.com/alpas/docs-alfred-workflow/issues"
10+
},
11+
"license": "MIT",
12+
"require": {
13+
"joetannenbaum/alfred-workflow": "^0.1.0",
14+
"algolia/algoliasearch-client-php": "^1.27",
15+
"erusev/parsedown": "^1.7"
16+
}
17+
}

composer.lock

Lines changed: 159 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

google.png

5.74 KB
Loading

icon.png

15.1 KB
Loading

0 commit comments

Comments
 (0)