From 49d73b6bc6bb070be71a9f1c1c6a7e70a73de438 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 10 Apr 2024 11:07:08 +0300 Subject: [PATCH] implement local welcome page --- config.json | 2 +- src/Controller/Browser.php | 89 +++++++++++++++++++++++++++++++++++++- src/Model/Page.php | 31 +++++++++++++ src/Page/Oops.gmi | 5 +++ src/Page/Welcome.gmi | 3 ++ src/Template/welcome.gmi | 3 -- 6 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 src/Model/Page.php create mode 100644 src/Page/Oops.gmi create mode 100644 src/Page/Welcome.gmi delete mode 100644 src/Template/welcome.gmi diff --git a/config.json b/config.json index 0a99b090..6b73d7a0 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { - "homepage":"gemini://yggverse.cities.yesterweb.org", + "homepage":"yoda://welcome", "interface": { "theme":"default", diff --git a/src/Controller/Browser.php b/src/Controller/Browser.php index 992a2563..a6286c73 100644 --- a/src/Controller/Browser.php +++ b/src/Controller/Browser.php @@ -73,10 +73,14 @@ class Browser extends \Yggverse\Yoda\Abstract\Window ); $this->tab->navigation->home->button->set_sensitive( - !($url == $this->config->homepage) + !($this->tab->navigation->address->entry->get_text() == $this->config->homepage) ); } + $this->navigate( + $this->tab->navigation->address->entry->get_text() + ); + $this->window->add( $this->tab->box ); @@ -84,7 +88,88 @@ class Browser extends \Yggverse\Yoda\Abstract\Window $this->window->show_all(); } - public function navigate(string $url) + public function navigate(string $url): void + { + switch (true) + { + case str_starts_with($url, 'gemini://'): + + $this->navigateGemini( + $url + ); + + break; + + case str_starts_with($url, 'yoda://'): + + $this->navigateYoda( + $url + ); + + break; + + default: + + $this->navigateYoda( + 'yoda://oops' + ); + } + } + + + public function navigateYoda(string $url): void + { + if ($data = \Yggverse\Yoda\Model\Page::get(str_replace('yoda://', '', $url))) + { + $response = new \Yggverse\Gemini\Client\Response( + $data + ); + + $this->tab->content->label->set_markup( + $data + ); + + $body = new \Yggverse\Gemini\Gemtext\Body( + $data + ); + + if ($h1 = $body->getH1()) + { + $this->window->set_title( + $h1[0] + ); + } + } + + else + { + $data = \Yggverse\Yoda\Model\Page::get('Oops'); + + $this->tab->content->label->set_markup( + $data + ); + + $body = new \Yggverse\Gemini\Gemtext\Body( + $data + ); + + if ($h1 = $body->getH1()) + { + $this->window->set_title( + $h1[0] + ); + } + } + + if ($this->config->interface->window->navigation->button->home && $this->config->homepage) + { + $this->tab->navigation->home->button->set_sensitive( + !($url == $this->config->homepage) + ); + } + } + + public function navigateGemini(string $url): void { $this->tab->tray->label->set_text( sprintf( diff --git a/src/Model/Page.php b/src/Model/Page.php new file mode 100644 index 00000000..c5dcc638 --- /dev/null +++ b/src/Model/Page.php @@ -0,0 +1,31 @@ + https://github.com/YGGverse/Yoda/issues Report \ No newline at end of file diff --git a/src/Page/Welcome.gmi b/src/Page/Welcome.gmi new file mode 100644 index 00000000..92a688fa --- /dev/null +++ b/src/Page/Welcome.gmi @@ -0,0 +1,3 @@ +# Welcome to Yoda! + +=> https://github.com/YGGverse/Yoda \ No newline at end of file diff --git a/src/Template/welcome.gmi b/src/Template/welcome.gmi deleted file mode 100644 index 9ef7b925..00000000 --- a/src/Template/welcome.gmi +++ /dev/null @@ -1,3 +0,0 @@ -# Welcome to Yoda - -=> https://github.com/YGGverse/Yoda \ No newline at end of file