Skip to content

Commit

Permalink
improves hierarchy display text
Browse files Browse the repository at this point in the history
  • Loading branch information
vmitchell85 committed Jul 31, 2018
1 parent c01ab05 commit 47549f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

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

Adapted from [Alfred Laravel Docs](https://github.com/tillkruss/alfred-laravel-docs), Thanks [Till Krüss](https://github.com/tillkruss)!
Adapted from [Alfred Laravel Docs](https://github.com/tillkruss/alfred-laravel-docs), Thanks [Till Krüss](https://twitter.com/tillkruss)!

![Screenshot](screenshot.png)

## Installation

1. [Download the latest version](https://github.com/vmitchell85/alfred-vuejs-docs/releases/download/0.1/VueJS.Docs.alfredworkflow)
1. [Download the latest version](https://github.com/vmitchell85/alfred-vuejs-docs/releases/download/0.1.1/VueJS.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.

Expand Down
39 changes: 20 additions & 19 deletions vuejs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
require __DIR__ . '/vendor/autoload.php';

$query = $argv[1];
$branch = empty($_ENV['branch']) ? 'master' : $_ENV['branch'];

$workflow = new Workflow;
$algolia = new Algolia('BH4D9OD16A', '85cc3221c9f23bfbaa4e3913dd7625ea');

AlgoliaUserAgent::addSuffixUserAgentSegment('Alfred Workflow', '0.2.1');
AlgoliaUserAgent::addSuffixUserAgentSegment('VueJS Alfred Workflow', '0.1.1');

$index = $algolia->initIndex('vuejs');
$search = $index->search($query, ['facetFilters' => 'version:v2']);
Expand All @@ -22,7 +21,7 @@
$workflow->result()
->title('No matches')
->icon('google.png')
->subtitle("No match found in the docs. Search Google for: \"{$query}\"")
->subtitle("No match found in the docs. Search Google for: \"VueJS+{$query}\"")
->arg("https://www.google.com/search?q=vuejs+{$query}")
->quicklookurl("https://www.google.com/search?q=vuejs+{$query}")
->valid(true);
Expand All @@ -32,24 +31,26 @@
}

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

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

if ($hasText) {
$subtitle = $hit['_highlightResult']['content']['value'];

if ($hasSubtitle) {
$title = "{$title} » {$hit['h2']}";
}
$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];
}

$title = $hit['hierarchy']['lvl6'] ?: $hit['hierarchy']['lvl5'] ?: $hit['hierarchy']['lvl4'] ?: $hit['hierarchy']['lvl2'] ?: $hit['hierarchy']['lvl1'] ?: $hit['hierarchy']['lvl0'];

$subtitle = $hit['hierarchy']['lvl0'] . ($hit['hierarchy']['lvl1'] ? ' => ' . $hit['hierarchy']['lvl1'] : '');

$workflow->result()
->uid($hit['objectID'])
->title($title)
Expand Down

0 comments on commit 47549f6

Please sign in to comment.