-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add wp-scaffold:elasticsearch #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Elasticsearch | ||
|
|
||
| Use the WP Acorn scaffold command to get started: | ||
|
|
||
| ```shell | ||
| wp acorn scaffold:elasticsearch | ||
| ``` | ||
|
|
||
| After scaffolding, follow these steps: | ||
|
|
||
| ## 1. Install dependencies | ||
|
|
||
| Install the Yard Elasticsearch plugin and the Reactive Search npm package: | ||
|
|
||
| ```shell | ||
| composer require plugin/yard-elasticsearch && pnpm install @yardinternet/reactive-search | ||
| ``` | ||
|
|
||
| ## 2. Add the Elasticsearch `.env` variables | ||
|
|
||
| Add the following variables to your `.env` and `.env.example` file: | ||
|
|
||
| ```env | ||
| # Elasticsearch | ||
| EP_HOST= | ||
| ES_PUBLIC_URL= | ||
| ``` | ||
|
|
||
| ## 3. Add Reactive Search entrypoint to Vite | ||
|
|
||
| Update your `vite.config.js`: | ||
|
|
||
| ```js | ||
| export default braveConfig( { | ||
| entryPoints: [ | ||
| 'resources/scripts/reactive-search/reactive-search.jsx', | ||
| ], | ||
| } ); | ||
| ``` | ||
|
|
||
| ## 4. Register the Elasticsearch Hook | ||
|
|
||
| Add the `Elasticsearch.php` hook to your `hooks.php`: | ||
|
|
||
| ```php | ||
| return [ | ||
| 'elasticsearch' => \App\Hooks\Elasticsearch::class, | ||
| ]; | ||
| ``` | ||
|
|
||
| ## 5. Add the reactive search bar to the header | ||
|
|
||
| Replace the current `@include('partials.header.search-bar')` of the search-bar with the following in the `header.blade.php`: | ||
|
|
||
| ```diff | ||
| - @include('partials.header.search-bar') | ||
|
|
||
| + @if (is_plugin_active('yard-elasticsearch/yard-elasticsearch.php')) | ||
| + @include('partials.header.reactive-search-bar') | ||
| + @else | ||
| + @include('partials.header.search-bar') | ||
| + @endif | ||
| ``` | ||
|
|
||
| ## 6. Activate the Plugin & Configure Settings | ||
|
|
||
| 1. Activate the Yard Elasticsearch plugin in WordPress. | ||
| 2. Go to the settings page `/wp/wp-admin/admin.php?page=acf-options-yard-elastic` | ||
| 3. Configure the following settings: | ||
| - **Bronnen** (required) | ||
| - **Filters** (optional) | ||
| - **Veld weging** (required) | ||
|
|
||
| Everything should now be set up and ready to use! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yard\Brave\Scaffold\Console; | ||
|
|
||
| use Illuminate\Console\Command; | ||
|
|
||
| class ElasticsearchScaffoldCommand extends Command | ||
| { | ||
| /** | ||
| * The name and signature of the console command. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $signature = 'scaffold:elasticsearch'; | ||
|
|
||
| /** | ||
| * The console command description. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $description = 'Scaffold Elasticsearch & Reactive Search'; | ||
|
|
||
| /** | ||
| * Execute the console command. | ||
| */ | ||
| public function handle(): void | ||
| { | ||
| $this->call('vendor:publish', [ | ||
| '--provider' => 'Yard\\Brave\\Scaffold\\ScaffoldServiceProvider', | ||
| '--tag' => 'elasticsearch', | ||
| ]); | ||
| $this->info('You need to do some additional steps after running this scaffold. Please read the docs here:'); | ||
| $this->line('https://github.com/yardinternet/brave-scaffold/blob/feat/elasticsearch/docs/elasticsearch.md'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Hooks; | ||
|
|
||
| use Illuminate\Support\Facades\Vite; | ||
| use Yard\Brave\Hooks\Plugin; | ||
| use Yard\Hook\Action; | ||
| use Yard\Hook\Filter; | ||
|
|
||
| #[Plugin('yard-elasticsearch/yard-elasticsearch.php')] | ||
| class Elasticsearch | ||
| { | ||
| #[Action('wp_head')] | ||
| public function enqueueAssets(): void | ||
| { | ||
| wp_enqueue_script('wp-element'); | ||
|
|
||
| Vite::useHotFile(get_parent_theme_file_path('public/hot')); | ||
|
|
||
| try { | ||
| echo Vite::withEntryPoints([ | ||
| 'web/app/themes/' . get_stylesheet() . '/resources/scripts/reactive-search/reactive-search.jsx', | ||
| ])->toHtml(); | ||
| } catch (\Exception $e) { | ||
| // Fail silently if entrypoint is not found. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Misschien hier nog een visuele error tonen? Want vind @yardinternet/wordpress-backend ? |
||
| } | ||
| } | ||
|
|
||
| #[Filter('template_include')] | ||
| public function overrideSearchTemplate(string $template): string | ||
| { | ||
| if (! is_search() || is_admin()) { | ||
| return $template; | ||
| } | ||
|
|
||
| $override = get_theme_file_path('resources/views/reactive-search-page.blade.php'); | ||
|
|
||
| if (file_exists($override)) { | ||
| return $override; | ||
| } | ||
|
|
||
| return $template; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export const theme = { | ||
| typography: { | ||
| fontFamily: 'inherit', | ||
| fontSize: 'inherit', | ||
| }, | ||
| colors: { | ||
| primaryColor: '#3a0056', // @todo | ||
| borderColor: '#3a0056', // @todo | ||
| textColor: '#000', | ||
| }, | ||
| }; |
34 changes: 34 additions & 0 deletions
34
stubs/resources/scripts/reactive-search/reactive-search.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import SearchPage from './views/search-page/SearchPage.jsx'; | ||
| import SearchBar from './views/search-bar/SearchBar.jsx'; | ||
| import SearchInput from './views/search-input/SearchInput.jsx'; | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { createRoot } from '@wordpress/element'; | ||
|
|
||
| /** | ||
| * Styles | ||
| */ | ||
| import './styles/autosuggest.css'; | ||
|
|
||
| if ( document.getElementById( 'js-reactive-search-page' ) ) { | ||
| createRoot( document.getElementById( 'js-reactive-search-page' ) ).render( | ||
| <SearchPage /> | ||
| ); | ||
| } | ||
|
|
||
| if ( document.getElementById( 'js-reactive-search-bar' ) ) { | ||
| createRoot( document.getElementById( 'js-reactive-search-bar' ) ).render( | ||
| <SearchBar /> | ||
| ); | ||
| } | ||
|
|
||
| if ( document.getElementById( 'js-reactive-search-input' ) ) { | ||
| createRoot( document.getElementById( 'js-reactive-search-input' ) ).render( | ||
| <SearchInput /> | ||
| ); | ||
| } |
56 changes: 56 additions & 0 deletions
56
stubs/resources/scripts/reactive-search/styles/autosuggest.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| @reference '@sage/styles/base/config.css'; | ||
| @reference '@sage/styles/base/utilities.css'; | ||
|
|
||
| .yrs-wrapper { | ||
| .yrs-autosuggest { | ||
| @apply z-100 shadow; | ||
| } | ||
|
|
||
| .yrs-autosuggest-item { | ||
| @apply border-gray-100; | ||
|
|
||
| &:last-child { | ||
| @apply font-bold; | ||
|
|
||
| .yrs-autosuggest-link { | ||
| @apply gap-x-4; | ||
| } | ||
| } | ||
|
|
||
| &.is-selected { | ||
| .yrs-autosuggest-link { | ||
| @apply text-primary bg-white; | ||
| animation: focus 0.1s linear both; | ||
| outline-color: -webkit-focus-ring-color; | ||
| outline-style: auto; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .yrs-autosuggest-link { | ||
| @apply py-2 no-underline; | ||
|
|
||
| &:hover, | ||
| &:focus { | ||
| @apply text-black; | ||
| } | ||
|
|
||
| @variant hocus { | ||
| @apply text-primary; | ||
| } | ||
|
|
||
| &:focus { | ||
| .trim { | ||
| @apply underline; | ||
| } | ||
| } | ||
|
|
||
| i { | ||
| @apply text-inherit!; | ||
| } | ||
| } | ||
|
|
||
| .yrs-autosuggest-link-label { | ||
| @apply text-xs whitespace-nowrap sm:pl-4; | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
stubs/resources/scripts/reactive-search/views/search-bar/SearchBar.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { | ||
| Base, | ||
| SearchBar as ReactiveSearchBar, | ||
| } from '@yardinternet/reactive-search'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { theme } from '../../config/theme'; | ||
| import './search-bar.css'; | ||
|
|
||
| const SearchBar = () => { | ||
| if ( ! window.YS || ! window.YS.indices ) { | ||
| console.error( 'Error: Yard Elasticsearch indices has not been set.' ); // eslint-disable-line no-console | ||
| return <></>; | ||
| } | ||
|
|
||
| return ( | ||
| <Base | ||
| app={ window.YS.indices.join() } | ||
| url={ window.YS.url } | ||
| theme={ theme } | ||
| > | ||
| <ReactiveSearchBar | ||
| boosts={ window.YS.boosts } | ||
| dataFields={ window.YS.dataFields } | ||
| fuzziness={ | ||
| window.YS.fuzziness === 'AUTO' | ||
| ? window.YS.fuzziness | ||
| : parseInt( window.YS.fuzziness ) | ||
| } | ||
| mustMatch={ window.YS.mustMatch } | ||
| openButtonText="Zoeken" | ||
| placeholder="Waar bent u naar op zoek?" | ||
| /> | ||
| </Base> | ||
| ); | ||
| }; | ||
|
|
||
| export default SearchBar; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Volgens mij staan heel veel van deze hooks in brave hooks, bij Involv ziet het bestand er zo uit: https://github.com/yardinternet/involv/blob/main/web/app/themes/sage/app/Hooks/Elasticsearch.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Dit stond TOTAAL niet op mijn radar. Heb de functies verwijderd!