Add computed raw pages, to create special content at any time
This commit is contained in:
18
libs/Format/Base/ComputedRawPage.php
Normal file
18
libs/Format/Base/ComputedRawPage.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php namespace Todaymade\Daux\Format\Base;
|
||||
|
||||
use Todaymade\Daux\Tree\ComputedRaw;
|
||||
|
||||
abstract class ComputedRawPage implements Page
|
||||
{
|
||||
protected $raw;
|
||||
|
||||
public function __construct(ComputedRaw $content)
|
||||
{
|
||||
$this->raw = $content;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->raw->getContent();
|
||||
}
|
||||
}
|
6
libs/Format/HTML/ComputedRawPage.php
Normal file
6
libs/Format/HTML/ComputedRawPage.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTML;
|
||||
|
||||
class ComputedRawPage extends \Todaymade\Daux\Format\Base\ComputedRawPage
|
||||
{
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Format\Base\LiveGenerator;
|
||||
use Todaymade\Daux\GeneratorHelper;
|
||||
use Todaymade\Daux\Tree\ComputedRaw;
|
||||
use Todaymade\Daux\Tree\Content;
|
||||
use Todaymade\Daux\Tree\Directory;
|
||||
use Todaymade\Daux\Tree\Entry;
|
||||
@ -94,7 +95,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
$output,
|
||||
$width,
|
||||
function() use ($node, $output_dir, $key, $params) {
|
||||
if (!$node instanceof Content) {
|
||||
if ($node instanceof Raw) {
|
||||
copy($node->getPath(), $output_dir . DIRECTORY_SEPARATOR . $key);
|
||||
return;
|
||||
}
|
||||
@ -118,6 +119,10 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
|
||||
return new RawPage($node->getPath());
|
||||
}
|
||||
|
||||
if ($node instanceof ComputedRaw) {
|
||||
return new ComputedRawPage($node);
|
||||
}
|
||||
|
||||
$params['request'] = $node->getUrl();
|
||||
return ContentPage::fromFile($node, $params, $this->daux->getContentTypeHandler()->getType($node));
|
||||
}
|
||||
|
@ -169,32 +169,35 @@ class Builder
|
||||
*/
|
||||
public static function getOrCreatePage(Directory $parent, $path)
|
||||
{
|
||||
$title = static::getName($path);
|
||||
|
||||
$extension = pathinfo($path, PATHINFO_EXTENSION);
|
||||
// If the file doesn't have an extension, set .md as a default
|
||||
if (pathinfo($path, PATHINFO_EXTENSION) == '') {
|
||||
if ($extension == '') {
|
||||
$extension = 'md';
|
||||
$path .= '.md';
|
||||
}
|
||||
|
||||
$uri = $slug = DauxHelper::slug($title);
|
||||
if ($parent->getConfig()['mode'] === Daux::STATIC_MODE) {
|
||||
$uri = $slug . ".html";
|
||||
$raw = !in_array($extension, $parent->getConfig()['valid_content_extensions']);
|
||||
|
||||
$title = $uri = $path;
|
||||
if (!$raw) {
|
||||
$title = static::getName($path);
|
||||
$uri = DauxHelper::slug($title);
|
||||
if ($parent->getConfig()['mode'] === Daux::STATIC_MODE) {
|
||||
$uri .= ".html";
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists($uri, $parent->getEntries())) {
|
||||
return $parent->getEntries()[$uri];
|
||||
}
|
||||
|
||||
$page = new Content($parent, $uri);
|
||||
$page = $raw? new ComputedRaw($parent, $uri) : new Content($parent, $uri);
|
||||
$page->setContent("-"); //set an almost empty content to avoid problems
|
||||
$page->setName($path);
|
||||
$page->setTitle($title);
|
||||
|
||||
if ($title == 'index') {
|
||||
// TODO :: clarify the difference between 'index' and '_index'
|
||||
$page->setName('_index.' . pathinfo($path, PATHINFO_EXTENSION));
|
||||
if ($title == 'index' || $title == '_index') {
|
||||
$page->setTitle($parent->getTitle());
|
||||
} else {
|
||||
$page->setName($path);
|
||||
$page->setTitle($title);
|
||||
}
|
||||
|
||||
return $page;
|
||||
|
23
libs/Tree/ComputedRaw.php
Normal file
23
libs/Tree/ComputedRaw.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php namespace Todaymade\Daux\Tree;
|
||||
|
||||
class ComputedRaw extends Entry
|
||||
{
|
||||
/** @var string */
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user