Skip to content

Instantly share code, notes, and snippets.

@ryangjchandler
Last active Nov 4, 2022
Embed
What would you like to do?
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"
}
}
@christophrumpel
Copy link

Hey, just found this and I get the error "Optional(Error Domain=NSPOSIXErrorDomain Code=8 "Exec format error")".

I have no idea what the error is about, can you help me here Ryan?

@ryangjchandler
Copy link
Author

Hey @christophrumpel. Never seen this error before unfortunately - have you copied everything exactly as above?

@christophrumpel
Copy link

kk, still thanks. I will give it another try.

@christophrumpel
Copy link

Of course, now it worked =) Thanks.

Do you plan on making an official extension from it? Or list multiple results before visiting one of the results?

@ryangjchandler
Copy link
Author

@christophrumpel I will likely do a stream this week and build it on stream. I've not played around with the extension API that much but it'll be a fun one!

@christophrumpel
Copy link

Cool, will be interesting to watch. Please add the scheduled stream to https://larastreamers.com/ :-)

@johanmolen
Copy link

This is awesome! Thanks @ryangjchandler. I will keep an eye on Twitter once you do a stream.

@weavdale
Copy link

Any update for 9.x docs? I tried changing the facetFilters but gave an error.

@ryangjchandler
Copy link
Author

@weavdale Yeah, I'll update tomorrow.

@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