Skip to content

Commit

Permalink
import code
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkruss committed Jul 30, 2018
0 parents commit a82af5a
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
composer.lock
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.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Laravel Docs Workflow for Alfred

An ultra-fast Laravel docs search workflow for Alfred 3.

![Screenshot](screenshot.png)

## Installation

1. [Download the latest version](https://github.com/tillkruss/alfred-laravel-docs/releases/download/v0.1.0/Laravel.Docs.alfredworkflow)
2. Install the workflow by double-clicking the `.alfredworkflow` file
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.

## Usage

```
ld <query>
```

Just type `ld` followed by your search query.
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": {
"joetannenbaum/alfred-workflow": "^0.1.0",
"algolia/algoliasearch-client-php": "^1.27",
"erusev/parsedown": "^1.7"
}
}
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.
131 changes: 131 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>bundleid</key>
<string>com.tillkruss.laravel-docs</string>
<key>category</key>
<string>Development</string>
<key>connections</key>
<dict>
<key>7B86D057-DA8E-4302-AF17-83B889B48EE2</key>
<array>
<dict>
<key>destinationuid</key>
<string>D449CB87-B64C-41F5-8FF0-C93C75686459</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
</dict>
<key>createdby</key>
<string>Till Krüss</string>
<key>description</key>
<string>An ultra-fast Laravel docs search workflow</string>
<key>disabled</key>
<false/>
<key>name</key>
<string>Laravel Docs</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>browser</key>
<string></string>
<key>spaces</key>
<string></string>
<key>url</key>
<string>{query}</string>
<key>utf8</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>D449CB87-B64C-41F5-8FF0-C93C75686459</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>127</integer>
<key>keyword</key>
<string>ld</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>Searching docs for "{query}"...</string>
<key>script</key>
<string>php laravel.php "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Search the Laravel docs...</string>
<key>title</key>
<string>Laravel</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>7B86D057-DA8E-4302-AF17-83B889B48EE2</string>
<key>version</key>
<integer>2</integer>
</dict>
</array>
<key>readme</key>
<string></string>
<key>uidata</key>
<dict>
<key>7B86D057-DA8E-4302-AF17-83B889B48EE2</key>
<dict>
<key>xpos</key>
<integer>200</integer>
<key>ypos</key>
<integer>90</integer>
</dict>
<key>D449CB87-B64C-41F5-8FF0-C93C75686459</key>
<dict>
<key>xpos</key>
<integer>510</integer>
<key>ypos</key>
<integer>90</integer>
</dict>
</dict>
<key>variables</key>
<dict>
<key>branch</key>
<string>5.6</string>
</dict>
<key>version</key>
<string>0.1.0</string>
<key>webaddress</key>
<string>https://till.im</string>
</dict>
</plist>
63 changes: 63 additions & 0 deletions laravel.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];
$branch = $_ENV['branch'] ?? '5.6';

$workflow = new Workflow;
$parsedown = new Parsedown;
$algolia = new Algolia('8BB87I11DE', '8e1d446d61fce359f69cd7c8b86a50de');

AlgoliaUserAgent::addSuffixUserAgentSegment('Alfred Workflow', '0.1.0');

$index = $algolia->initIndex('docs');
$search = $index->search($query, ['tagFilters' => $branch]);
$results = $search['hits'];

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

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

foreach ($results as $hit) {
$hasText = isset($hit['_highlightResult']['content']['value']);
$hasSubtitle = isset($hit['h2']);

$title = $hit['h1'];
$subtitle = $hasSubtitle ? $hit['h2'] : null;

if ($hasSubtitle && $hasText) {
$title = $hit['h2'];
$subtitle = $hit['_highlightResult']['content']['value'];
}

$title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));

$subtitle = $parsedown->line($subtitle);
$subtitle = strip_tags(html_entity_decode($subtitle, ENT_QUOTES, 'UTF-8'));

$workflow->result()
->uid($hit['objectID'])
->title($title)
->autocomplete($title)
->subtitle($subtitle)
->arg("https://laravel.com/docs/{$branch}/{$hit['link']}")
->quicklookurl("https://laravel.com/docs/{$branch}/{$hit['link']}")
->valid(true);
}

echo $workflow->output();
Binary file added screenshot-sm.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 screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a82af5a

Please sign in to comment.