Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokgelal committed Feb 12, 2020
0 parents commit dfd1e28
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

vendor
Binary file added AlpasDocs.alfredworkflow
Binary file not shown.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Till Krüss

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# [Alpas Docs](https://alpas.dev/docs) Workflow for Alfred

Alpas docs search workflow for Alfred.

![Screenshot](screenshot.png)

## Installation

1. [Download the latest version](https://github.com/alpas/docs-alfred-workflow/releases/download/v1.0.0/AlpasDocs.alfredworkflow)
2. Double-click the `.alfredworkflow` file to install it.
3. Add the workflow to a category, then click `Import`.

## Usage

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.

```
al <query>
```

![Search by Algolia](algolia.png)
Binary file added algolia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions alpas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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;
$parsedown = new Parsedown;
$algolia = new Algolia('BH4D9OD16A', 'e017bb0b99fe3193f750d48a4e7d441e');

AlgoliaUserAgent::addSuffixUserAgentSegment('Alpas Docs Alfred Workflow', '1.0.0');

$index = $algolia->initIndex('alpas');
$search = $index->search($query);
$results = $search['hits'];

$subtextSupported = $subtext === '0' || $subtext === '2';

if (empty($results)) {
if (empty($results)) {
$workflow->result()
->title('No matches')
->icon('google.png')
->subtitle("No match found in the docs. Search Google for: \"Alpas+{$query}\"")
->arg("https://www.google.com/search?q=alpas+{$query}")
->quicklookurl("https://www.google.com/search?q=alpas+{$query}")
->valid(true);

echo $workflow->output();
exit;
}
exit;
}

$urls = [];


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();
17 changes: 17 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "alpas/docsalfred",
"description": "Alpas docs search workflow for Alfred.",
"version": "1.1.0",
"keywords": ["alfred", "alfred-workflow", "alpas", "algolia"],
"homepage": "https://github.com/alpas",
"support": {
"source": "https://github.com/alpas/docs-alfred-workflow",
"issues": "https://github.com/alpas/docs-alfred-workflow/issues"
},
"license": "MIT",
"require": {
"joetannenbaum/alfred-workflow": "^0.1.0",
"algolia/algoliasearch-client-php": "^1.27",
"erusev/parsedown": "^1.7"
}
}
159 changes: 159 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added google.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dfd1e28

Please sign in to comment.