Skip to content

Commit

Permalink
Allow searching the latest stable version. (#11)
Browse files Browse the repository at this point in the history
`/docs/{query}` automatically redirects to `/docs/{semver}/{query}`, allow the workflow to be configured by unsetting the `branch`  env var, or setting it to `latest`.
  • Loading branch information
CupOfTea696 authored and tillkruss committed May 23, 2019
1 parent e38709e commit 124cd3a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
$branch = $matches[1];
$query = $matches[2];
} else {
$branch = empty($_ENV['branch']) ? 'master' : $_ENV['branch'];
$branch = $_ENV['branch'];
}

if ($branch === 'latest') {
$branch = null;
}

$subtext = empty($_ENV['alfred_theme_subtext']) ? '0' : $_ENV['alfred_theme_subtext'];
Expand All @@ -27,7 +31,7 @@
AlgoliaUserAgent::addSuffixUserAgentSegment('Alfred Workflow', '0.2.2');

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

$subtextSupported = $subtext === '0' || $subtext === '2';
Expand Down Expand Up @@ -55,10 +59,11 @@
exit;
}

$docs = sprintf('https://laravel.com/docs/%s', $branch ? $branch . '/' : '');
$urls = [];

foreach ($results as $hit) {
$url = sprintf("https://laravel.com/docs/%s/%s", $branch, $hit['link']);
$url = $docs . $hit['link'];

if (in_array($url, $urls)) {
continue;
Expand Down

0 comments on commit 124cd3a

Please sign in to comment.