Browse Source

implement local welcome page

PHP-GTK3
yggverse 7 months ago
parent
commit
49d73b6bc6
  1. 2
      config.json
  2. 89
      src/Controller/Browser.php
  3. 31
      src/Model/Page.php
  4. 5
      src/Page/Oops.gmi
  5. 3
      src/Page/Welcome.gmi
  6. 3
      src/Template/welcome.gmi

2
config.json

@ -1,5 +1,5 @@
{ {
"homepage":"gemini://yggverse.cities.yesterweb.org", "homepage":"yoda://welcome",
"interface": "interface":
{ {
"theme":"default", "theme":"default",

89
src/Controller/Browser.php

@ -73,10 +73,14 @@ class Browser extends \Yggverse\Yoda\Abstract\Window
); );
$this->tab->navigation->home->button->set_sensitive( $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->window->add(
$this->tab->box $this->tab->box
); );
@ -84,7 +88,88 @@ class Browser extends \Yggverse\Yoda\Abstract\Window
$this->window->show_all(); $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( $this->tab->tray->label->set_text(
sprintf( sprintf(

31
src/Model/Page.php

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Model;
class Page
{
public static function get(string $name): ?string
{
$name = ucfirst(
mb_strtolower(
$name
)
);
$filename = __DIR__ .
DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . 'Page' .
DIRECTORY_SEPARATOR . $name . '.gmi';
if (file_exists($filename) && is_readable($filename))
{
return file_get_contents(
$filename
);
}
return null;
}
}

5
src/Page/Oops.gmi

@ -0,0 +1,5 @@
# Oops!
Something went wrong..
=> https://github.com/YGGverse/Yoda/issues Report

3
src/Page/Welcome.gmi

@ -0,0 +1,3 @@
# Welcome to Yoda!
=> https://github.com/YGGverse/Yoda

3
src/Template/welcome.gmi

@ -1,3 +0,0 @@
# Welcome to Yoda
=> https://github.com/YGGverse/Yoda
Loading…
Cancel
Save