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