Jac Make Title Plugin
If file does not have a meta section and title set title to filename .
Use Raw Markdown Files
If your markdown source does not have a meta section, then no title will be set. Phile will not throw an error, but you won't see any links to the page in navigation or other features that use title meta.
If you got a lot of existing markdown files, this plugin will allow you to quickly use them without adding a meta header section. The title will be set to the file name.
<?php
/**
* Plugin class :: jacMakeTitle
* IF NO TITLE, the set filename as title
* future maybe: if no title search content for first h1 or h2 and use that
* note if no title is set then the meta parser probably went crazy as well
* should try to also delete all the meta; for now just set a title!
*/
namespace Phile\Plugin\Jaccms\JacMaketitle;
class Plugin extends \Phile\Plugin\AbstractPlugin implements \Phile\Gateway\EventObserverInterface {
public function __construct() {
\Phile\Event::registerEvent('before_load_content', $this);
\Phile\Event::registerEvent('after_read_file_meta', $this);
}
public function on($eventKey, $data = null) {
if ($eventKey == 'before_load_content') {
//Event::triggerEvent('before_load_content', array('filePath' => &$this->filePath, 'rawData' => $this->rawData, 'page' => &$this));
$this->thispageURL = basename($data['filePath'], '.md');
}
if ($eventKey == 'after_read_file_meta') {
//Event::triggerEvent('after_read_file_meta', array('rawData' => &$rawData, 'meta' => &$this));
$title = $data['meta']->get('title');
if(!$title) {
//if no title meta is set, then all parsed meta is probably bogus
$title = ucfirst(basename($this->thispageURL));
//save to the object
$data['meta']->set('title', trim($title));
}
}
}
}