update readme

This commit is contained in:
lubiana 2022-04-05 00:02:52 +02:00 committed by Andre Lubian
parent b12cf019e7
commit ab3227b75f
88 changed files with 7546 additions and 176 deletions

View file

@ -2,6 +2,8 @@
namespace Lubian\NoFramework\Action;
use Lubian\NoFramework\Model\MarkdownPage;
use Lubian\NoFramework\Repository\MarkdownPageFilesystem;
use Lubian\NoFramework\Repository\MarkdownPageRepo;
use Lubian\NoFramework\Template\Renderer;
use Parsedown;
@ -12,19 +14,33 @@ use function str_replace;
class Page
{
public function __invoke(
public function __construct(
private ResponseInterface $response,
private MarkdownPageRepo $repo,
private Parsedown $parsedown,
private Renderer $renderer,
){}
public function show(
string $page,
ResponseInterface $response,
MarkdownPageRepo $repo,
Parsedown $parsedown,
Renderer $renderer,
): ResponseInterface {
$page = $repo->byTitle($page);
$page = $this->repo->byTitle($page);
$content = $this->linkFilter($page->content);
$content = $parsedown->parse($content);
$html = $renderer->render('page', ['content' => $content]);
$response->getBody()->write($html);
return $response;
$content = $this->parsedown->parse($content);
$html = $this->renderer->render('page', ['content' => $content, 'title' => $page->title]);
$this->response->getBody()->write($html);
return $this->response;
}
public function list(): ResponseInterface
{
$pages = array_map(
fn (MarkdownPage $p) => ['title' => $p->title, 'id' => $p->id],
$this->repo->all()
);
$html = $this->renderer->render('pagelist', ['pages' => $pages]);
$this->response->getBody()->write($html);
return $this->response;
}
private function linkFilter(string $content): string