Skip to content

Commit

Permalink
Use a more reliable way to load the theme in singlepage mode
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz committed Jan 31, 2022
1 parent 11d76ee commit 4e49953
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
25 changes: 15 additions & 10 deletions libs/Format/HTMLFile/Book.php
@@ -1,24 +1,29 @@
<?php namespace Todaymade\Daux\Format\HTMLFile;

use Todaymade\Daux\Config;
use Todaymade\Daux\Tree\Content;
use Todaymade\Daux\Tree\Directory;

class Book
{
protected $cover;
protected $tree;
protected $pages = [];

public function __construct(Directory $tree, $cover)
public function __construct(Directory $tree, Config $config)
{
$this->tree = $tree;
$this->cover = $cover;
$this->config = $config;
}

protected function getStyles()
{
// TODO :: un-hardcode that
return '<style>' . file_get_contents('themes/daux_singlepage/css/main.min.css') . '</style>';
$styles = '';
foreach ($this->config->getTheme()->getCSS() as $css) {
$file = $this->config->getThemesPath() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $css;
$styles .= '<style>' . file_get_contents($file) . '</style>';
}

return $styles;
}

protected function getPageUrl($page)
Expand Down Expand Up @@ -89,8 +94,8 @@ protected function generateTOC()
protected function generateCover()
{
return '<div>' .
"<h1 style='font-size:40pt; margin-bottom:0;'>{$this->cover['title']}</h1>" .
"<p><strong>{$this->cover['subject']}</strong> by {$this->cover['author']}</p>" .
"<h1 style='font-size:40pt; margin-bottom:0;'>{$this->config->getTitle()}</h1>" .
"<p><strong>{$this->config->getTagline()}</strong> by {$this->config->getAuthor()}</p>" .
'</div><div class="PageBreak">&nbsp;</div>';
}

Expand All @@ -115,9 +120,9 @@ public function addPage($page, $content)
public function generateHead()
{
$head = [
"<title>{$this->cover['title']}</title>",
"<meta name='description' content='{$this->cover['subject']}' />",
"<meta name='author' content='{$this->cover['author']}'>",
"<title>{$this->config->getTitle()}</title>",
"<meta name='description' content='{$this->config->getTagline()}' />",
"<meta name='author' content='{$this->config->getAuthor()}'>",
"<meta charset='UTF-8'>",
$this->getStyles(),
];
Expand Down
12 changes: 5 additions & 7 deletions libs/Format/HTMLFile/Generator.php
Expand Up @@ -57,15 +57,13 @@ function () use ($destination) {
}
);

DauxHelper::rebaseConfiguration($config, '');
// TODO :: make it possible to customize the single page theme
$config['html']['theme'] = 'daux_singlepage';
$config['html']['theme-variant'] = null;

$data = [
'author' => $config->getAuthor(),
'title' => $config->getTitle(),
'subject' => $config->getTagline(),
];
DauxHelper::rebaseConfiguration($config, '');

$book = new Book($this->daux->tree, $data);
$book = new Book($this->daux->tree, $config);

$current = $this->daux->tree->getIndexPage();
while ($current) {
Expand Down
1 change: 1 addition & 0 deletions libs/Tree/Content.php
Expand Up @@ -150,6 +150,7 @@ public function dump()

$dump['prev'] = $this->getPrevious() ? $this->getPrevious()->getUrl() : '';
$dump['next'] = $this->getNext() ? $this->getNext()->getUrl() : '';
$dump['attributes'] = $this->getAttribute();

return $dump;
}
Expand Down

0 comments on commit 4e49953

Please sign in to comment.