Skip to content

Commit

Permalink
Merge pull request #11 from 8fold/working
Browse files Browse the repository at this point in the history
Page controller and titles
  • Loading branch information
joshbruce authored Oct 29, 2021
2 parents da0efc2 + c25c75e commit 0d00bb3
Show file tree
Hide file tree
Showing 7 changed files with 489 additions and 86 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"8fold/php-html-builder": "^0.5.3",
"nyholm/psr7": "^1.4",
"laminas/laminas-httphandlerrunner": "^2.1",
"filp/whoops": "^2.14"
"filp/whoops": "^2.14",
"nesbot/carbon": "^2.53"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.6",
Expand Down
269 changes: 268 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 6 additions & 75 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
exit;
}

if ($server->isUsingUnsupportedMethod()) {
if ($server->isRequestingUnsupportedMethod()) {
JoshBruce\Site\Emitter::emitUnsupportedMethodResponse(
$markdownConverter,
$projectRoot,
Expand Down Expand Up @@ -83,79 +83,10 @@
exit;
}

/**
* Process HTML response: local response time 75ms (90ms with table content)
*/

$markdownConverter = $markdownConverter->withConfig(['html_input' => 'allow'])
->tables()->externalLinks();

$headers['Content-Type'] = $content->mimeType();

$headElements = JoshBruce\Site\PageComponents\Favicons::create();
$headElements[] = Eightfold\HTMLBuilder\Element::link()
->props('rel stylesheet', 'href /css/main.css');

$markdown = $content->markdown();

$frontMatter = $markdownConverter->getFrontMatter($content->markdown());

$updated = '';
if (array_key_exists('updated', $frontMatter)) {
$updated = Eightfold\HTMLBuilder\Element::p(
"Updated on: {$frontMatter['updated']}"
);
}

$dateBlock = Eightfold\HTMLBuilder\Element::div(
Eightfold\HTMLBuilder\Element::p("Created on: {$frontMatter['created']}"),
$updated
)->props('is dateblock');

$body = $markdownConverter->getBody($markdown);

$body = $dateBlock . $body;

if (array_key_exists('header', $frontMatter)) {
$body = "# {$frontMatter['header']}\n\n" . $body;

} else {
$body = "# {$frontMatter['title']}\n\n" . $body;

}

if (array_key_exists('type', $frontMatter) and $frontMatter['type'] === 'log') {
$contents = $content->contentInSubfolders();
krsort($contents);
$logLinks = [];
foreach ($contents as $key => $c) {
if (! str_starts_with(strval($key), '_') and $c->exists()) {
$logLinks[] = Eightfold\HTMLBuilder\Element::li(
Eightfold\HTMLBuilder\Element::a(
$c->frontMatter()['title']
)->props('href ' . $c->pathWithoutFile())
);
}
}
$list = Eightfold\HTMLBuilder\Element::ul(...$logLinks)->build();
$body = $body . $list;
}
$page = JoshBruce\Site\Pages\DefaultTemplate::create(
$markdownConverter,
$content
);

$body = Eightfold\HTMLBuilder\Document::create(
$frontMatter['title']
)->head(
...$headElements
)->body(
JoshBruce\Site\PageComponents\Navigation::create($content)
->build(),
$markdownConverter->convert($body),
Eightfold\HTMLBuilder\Element::footer(
Eightfold\HTMLBuilder\Element::p(
'Copyright © 2004–' . date('Y') . 'Joshua C. Bruce. ' .
'All rights reserved.'
)
)
)->build();

JoshBruce\Site\Emitter::emitWithResponse(200, $headers, $body);
JoshBruce\Site\Emitter::emitWithResponse(200, $page->headers(), $page->body());
exit;
Loading

0 comments on commit 0d00bb3

Please sign in to comment.