mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 08:35:28 +00:00
implement local welcome page
This commit is contained in:
parent
46a6a240cc
commit
49d73b6bc6
5 changed files with 125 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"homepage":"gemini://yggverse.cities.yesterweb.org",
|
||||
"homepage":"yoda://welcome",
|
||||
"interface":
|
||||
{
|
||||
"theme":"default",
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
31
src/Model/Page.php
Normal file
31
src/Model/Page.php
Normal file
|
|
@ -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
Normal file
5
src/Page/Oops.gmi
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Oops!
|
||||
|
||||
Something went wrong..
|
||||
|
||||
=> https://github.com/YGGverse/Yoda/issues Report
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
# Welcome to Yoda
|
||||
# Welcome to Yoda!
|
||||
|
||||
=> https://github.com/YGGverse/Yoda
|
||||
Loading…
Add table
Add a link
Reference in a new issue