Exemplo n.º 1
0
 public function parse($filename)
 {
     foreach ($this->files as $file) {
         if ($file['name'] == $filename) {
             $doc = Parser::parse(file_get_contents($file['path']))->setConfig('url', ConfigManager::getUrl($this->entity) . '/' . $file['name']);
             if ($file['parser']) {
                 $html = self::parseMarkdown($doc->getContent());
             } else {
                 $html = $doc->getContent();
             }
             $doc->setConfig('content', $html);
             return $doc;
         }
     }
 }
Exemplo n.º 2
0
 public function init(Page $page)
 {
     $data = file_get_contents($this->blazon->getSrc() . '/' . $page->getSrc());
     $doc = FrontMatterParser::parse($data);
     $config = $doc->getConfig();
     foreach ($config as $key => $value) {
         $page->setProperty($key, $value);
     }
     /*
     if (isset($config['layout'])) {
         $page->setLayout($config['layout']);
     }
     */
     $this->content = $doc->getContent();
 }
Exemplo n.º 3
0
 /**
  * Get a value from the YAML file (content give the content part)
  * @param $key
  * @return null|string
  */
 public function get($key)
 {
     if (!$this->parsed_data) {
         $this->parsed_data = Parser::parse(file_get_contents($this->path));
     }
     if ($key === "content") {
         $pathinfo = explode('.', pathinfo($this->path, PATHINFO_FILENAME));
         $type = end($pathinfo);
         $method = "parse_{$type}";
         return $this->{$method}($this->parsed_data->getContent());
     }
     if (!isset($this->parsed_data->getConfig()[$key])) {
         return null;
     }
     if (is_array($this->parsed_data->getConfig()[$key])) {
         return $this->parsed_data->getConfig()[$key];
     }
     return nl2br($this->parsed_data->getConfig()[$key]);
 }
Exemplo n.º 4
0
 public function getKeys()
 {
     $doc = Parser::parse(file_get_contents($this->url));
     return $doc->getConfig();
 }
Exemplo n.º 5
0
 public function readContent($path)
 {
     return Parser::parse(file_get_contents($path))->getContent();
 }
Exemplo n.º 6
0
$base_url = get_base_url();
$file_ext = '.html';
//$parser = new Devster\Frontmatter\Parser( 'yaml', 'markdown' );
$scanner = new \TheSeer\DirectoryScanner\DirectoryScanner();
//$scanner->addExclude('./*');
$scanner->addExclude('./_drafts/*');
$scanner->addInclude('*.md');
$scanner->addInclude('*.markdown');
$scanner->addInclude('./_posts/*');
$idx = 0;
foreach ($scanner('.') as $path => $item) {
    $content = file_get_contents($path);
    // Try to prevent YAML exception - 'Multiple documents are not supported.'
    $content = preg_replace(YAML_MULTI_DOC_EXCEPT_RE, '$1\\-\\-\\-', $content);
    try {
        $doc = Parser::parse($content);
    } catch (Exception $ex) {
        fprintf(STDERR, "Exception: %s - %s\n", $ex->getMessage(), $path);
        exit(1);
    }
    $frontmatter = $doc->getConfig();
    if (!isset($frontmatter['x-source'])) {
        echo "#{$idx}. Skipping {$path} - no frontmatter / x-source" . PHP_EOL;
        continue;
        //WAS: break;
    }
    if (isset($frontmatter['permalink'])) {
        $dest_path = $base_url . $frontmatter['permalink'];
    } elseif (preg_match(JEKYLL_POST_FILE_RE, $item->getFilename(), $matches)) {
        $m = (object) $matches;
        $dest_path = $base_url . "/{$m->yr}/{$m->mo}/{$m->dy}/{$m->slug}" . $file_ext;