From cf0a25efd1c479e07119c22d3f7d6e23fda828c6 Mon Sep 17 00:00:00 2001 From: jakebathman Date: Tue, 31 Jul 2018 10:06:27 -0500 Subject: [PATCH 1/3] Add optional Laravel version in query --- laravel.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/laravel.php b/laravel.php index 2d3dc4e..f5368f7 100644 --- a/laravel.php +++ b/laravel.php @@ -8,7 +8,13 @@ require __DIR__ . '/vendor/autoload.php'; $query = $argv[1]; -$branch = empty($_ENV['branch']) ? 'master' : $_ENV['branch']; +preg_match('/^\s*?v?(master|(?:[\d]+)(?:\.[\d]+)?(?:\.[\d]+)?)?\s*?(.*?)$/', $query, $matches); +if (trim($matches[1]) != "") { + $branch = $matches[1]; + $query = $matches[2]; +} else { + $branch = empty($_ENV['branch']) ? 'master' : $_ENV['branch']; +} $workflow = new Workflow; $parsedown = new Parsedown; From b42a979cd459c8af7a152f9460729a820e026b79 Mon Sep 17 00:00:00 2001 From: jakebathman Date: Tue, 31 Jul 2018 10:06:45 -0500 Subject: [PATCH 2/3] Filter identical URL results from list --- laravel.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/laravel.php b/laravel.php index f5368f7..9a33aa3 100644 --- a/laravel.php +++ b/laravel.php @@ -39,7 +39,15 @@ exit; } +$hits = []; foreach ($results as $hit) { + $url = "https://laravel.com/docs/{$branch}/{$hit['link']}"; + if (in_array($url, $hits)) { + // Already included this URL + continue; + } + $hits[] = $url; + $hasText = isset($hit['_highlightResult']['content']['value']); $hasSubtitle = isset($hit['h2']); @@ -64,8 +72,8 @@ ->title($title) ->autocomplete($title) ->subtitle($subtitle) - ->arg("https://laravel.com/docs/{$branch}/{$hit['link']}") - ->quicklookurl("https://laravel.com/docs/{$branch}/{$hit['link']}") + ->arg($url) + ->quicklookurl($url) ->valid(true); } From c9481094049595e008f5738615570ee294c44ac5 Mon Sep 17 00:00:00 2001 From: jakebathman Date: Tue, 31 Jul 2018 10:07:17 -0500 Subject: [PATCH 3/3] Add all subheads to subtitle, if applicable --- laravel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/laravel.php b/laravel.php index 9a33aa3..966c46a 100644 --- a/laravel.php +++ b/laravel.php @@ -52,7 +52,7 @@ $hasSubtitle = isset($hit['h2']); $title = $hit['h1']; - $subtitle = $hasSubtitle ? $hit['h2'] : null; + $subtitle = $hit['h2'] . (! is_null($hit['h3']) ? " | " . $hit['h3'] : null) . (! is_null($hit['h4']) ? " ยป " . $hit['h4'] : null); if ($hasText) { $subtitle = $hit['_highlightResult']['content']['value'];