From cd4522f9108e31ec37d1bbbd52166c6c060cb058 Mon Sep 17 00:00:00 2001 From: Rahman Ramsi Date: Sat, 21 Oct 2023 15:28:23 +0800 Subject: [PATCH] add meta tag --- app/Http/Middleware/SetupDefaultData.php | 7 +- .../Forms/Conferences/SearchEngineSetting.php | 68 +++++++++++++++++++ .../Pages/Settings/ConferenceSetting.php | 15 ++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 app/Panel/Livewire/Forms/Conferences/SearchEngineSetting.php diff --git a/app/Http/Middleware/SetupDefaultData.php b/app/Http/Middleware/SetupDefaultData.php index a9ab4a56b..3fb623874 100644 --- a/app/Http/Middleware/SetupDefaultData.php +++ b/app/Http/Middleware/SetupDefaultData.php @@ -41,7 +41,7 @@ protected function setupSite() View::share('contextName', $site->getMeta('name')); View::share('footer', $site->getMeta('footer')); - MetaTag::add('description', $site->getMeta('description') ?? 'dsadsa'); + MetaTag::add('description', $site->getMeta('description')); } protected function setupConference($currentConference) @@ -53,6 +53,11 @@ protected function setupConference($currentConference) View::share('footer', $currentConference->getMeta('footer')); View::share('favicon', $currentConference->getFirstMediaUrl('favicon')); View::share('styleSheet', $currentConference->getFirstMediaUrl('styleSheet')); + MetaTag::add('description', preg_replace("/\r|\n/", '', $currentConference->getMeta('description'))); + + foreach ($currentConference->getMeta('meta_tags') ?? [] as $name => $content) { + MetaTag::add($name, $content); + } } } diff --git a/app/Panel/Livewire/Forms/Conferences/SearchEngineSetting.php b/app/Panel/Livewire/Forms/Conferences/SearchEngineSetting.php new file mode 100644 index 000000000..e049a32ff --- /dev/null +++ b/app/Panel/Livewire/Forms/Conferences/SearchEngineSetting.php @@ -0,0 +1,68 @@ +form->fill([ + ...$conference->attributesToArray(), + 'meta' => $conference->getAllMeta(), + ]); + } + + public function render() + { + return view('panel.livewire.form'); + } + + public function form(Form $form): Form + { + return $form + ->model($this->conference) + ->schema([ + Section::make() + ->schema([ + KeyValue::make('meta.meta_tags') + ->keyLabel('Name') + ->valueLabel('Content') + + ->helperText('Add meta tags, to the head of every page on your conference. Before adding any tags, consult with a technical advisor to ensure that they are compatible with your website and will not cause any problems.'), + ]), + Actions::make([ + Action::make('save') + ->label('Save') + ->successNotificationTitle('Saved!') + ->failureNotificationTitle('Data could not be saved.') + ->action(function (Action $action) { + $formData = $this->form->getState(); + try { + ConferenceUpdateAction::run($this->conference, $formData); + $action->sendSuccessNotification(); + } catch (\Throwable $th) { + $action->sendFailureNotification(); + } + }), + ])->alignLeft(), + ]) + ->statePath('formData'); + } +} diff --git a/app/Panel/Pages/Settings/ConferenceSetting.php b/app/Panel/Pages/Settings/ConferenceSetting.php index 2b9b79a87..e9d801596 100644 --- a/app/Panel/Pages/Settings/ConferenceSetting.php +++ b/app/Panel/Pages/Settings/ConferenceSetting.php @@ -7,6 +7,7 @@ use App\Panel\Livewire\Forms\Conferences\ContactSetting; use App\Panel\Livewire\Forms\Conferences\InformationSetting; use App\Panel\Livewire\Forms\Conferences\PrivacySetting; +use App\Panel\Livewire\Forms\Conferences\SearchEngineSetting; use App\Panel\Livewire\Forms\Conferences\SetupSetting; use App\Panel\Livewire\Forms\Conferences\SidebarSetting; use Filament\Forms\Concerns\InteractsWithForms; @@ -92,6 +93,20 @@ public function infolist(Infolist $infolist): Infolist ]), ]), ]), + Tabs\Tab::make('Distribution') + ->schema([ + InfolistsVerticalTabs\Tabs::make() + ->schema([ + InfolistsVerticalTabs\Tab::make('Search Indexing') + ->icon('heroicon-o-magnifying-glass') + ->schema([ + LivewireEntry::make('sidebar-setting') + ->livewire(SearchEngineSetting::class, [ + 'conference' => App::getCurrentConference(), + ]), + ]), + ]), + ]), ]) ->contained(false), ]);