Skip to content

Instantly share code, notes, and snippets.

@ryangjchandler
Last active June 23, 2023 08:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryangjchandler/c63adfdedfdf014722fbda80fa9e1aa6 to your computer and use it in GitHub Desktop.
Save ryangjchandler/c63adfdedfdf014722fbda80fa9e1aa6 to your computer and use it in GitHub Desktop.
Raycast - Laravel Documentation

Raycast - Laravel Documentation

This script command provides a quick way of searching the Laravel documentation.

It accepts a query and will open the first result in your default browser.

Installation

  1. Begin by creating a ~/.config/raycast/scripts folder if you don't already have one.

  2. Add the laravel.js and package.json file to this folder.

If you already have a package.json in this folder, run npm install open algoliasearch -D instead.

  1. Add the ~/.config/raycast/scripts folder to Raycast

Open Raycast and search for Extensions. Hit Cmd + N and choose "Add Script Directory". Navigate to and choose the ~/.config/raycast/scripts folder.

  1. Open Raycast and type laravel. It should appear as a Script Command.

  2. Hit Enter and you'll be prompted to enter your search query. Type your search and hit enter. The Raycast output window will tell you how many results were found and it'll open the most relevant in your default browser.

#!/usr/bin/env node
import Algolia from 'algoliasearch'
import open from 'open'
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title Laravel
// @raycast.mode fullOutput
// Optional parameters:
// @raycast.icon 🤖
// @raycast.argument1 { "type": "text", "placeholder": "Search..." }
// Documentation:
// @raycast.description Search the Laravel documentation.
// @raycast.author Ryan Chandler
// @raycast.authorURL https://github.com/ryangjchandler
const client = Algolia('BH4D9OD16A', '7dc4fe97e150304d1bf34f5043f178c4')
const index = client.initIndex('laravel')
const results = await index.search(process.argv.slice(2)[0], {
facetFilters: ['version:8.x'],
hitsPerPage: 5
})
console.log(`Found ${results.nbHits} results.`)
console.log(`Opening ${results.hits[0].url}...`)
open(results.hits[0].url)
{
"private": true,
"type": "module",
"devDependencies": {
"algoliasearch": "^4.10.5",
"open": "^8.2.1"
}
}
@mwikala
Copy link

mwikala commented Feb 28, 2022

For @weavdale and anyone else that might stumble across this.

To make sure you always have the latest search results from the Laravel docs, I've used the Algolia keys from the documentation site. This way you'll have access to everything from 4.2 to current the current master branch (as long as you've set that version inside the facetFilters key of the laravel.js file and provided Laravel don't ever change the keys).

Make a simple change to laravel.js on line 20

- const client = Algolia('BH4D9OD16A', '7dc4fe97e150304d1bf34f5043f178c4')
+ const client = Algolia('E3MIRNPJH5', '1fa3a8fec06eb1858d6ca137211225c0')

and on line 24

- facetFilters: ['version:8.x'],
+ facetFilters: ['version:9.x'],

@keizah7
Copy link

keizah7 commented Nov 4, 2022

env: node: No such file or directory

Done in 0.02s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment