/** * Get the page sub title * * @param string $page * @return string */ public function getSubTitle($page) { $pageFile = $this->getDocumentationPath() . "/{$page}.md"; return $this->cache->rememberForever("doc_page_{$pageFile}_sub-title", function () use($pageFile) { $data = $this->parser->parse($this->finder->get($pageFile)); return $data->get('subtitle'); }); }
public function parseMarkdown(\Gen\Config $config, $file) { $source = file_get_contents($file); // Create a new document parser $parser = new DocumentParser(); // Parse the loaded source. $document = $parser->parse($source); $html = '{% extends "' . $document->get()['template'] . '" %}{% block content %}' . $document->getHtmlContent() . '{% endblock %}'; $filename = md5($html) . '.twig'; if (!file_exists($config->get('cache') . '/' . $filename)) { if (!is_dir($config->get('src'))) { mkdir($config->get('src')); } file_put_contents($config->get('cache') . '/' . $filename, $html); } $metadata = $document->get(); $metadata['template'] = $filename; return $metadata; }
/** * Loads all documents at the given base path. * * @return array */ protected function loadDocuments() { $filesystem = $this->filesystem; $files = $filesystem->files($this->basePath); $files = array_filter($files, function ($file) { return pathinfo($file, PATHINFO_EXTENSION) === 'md'; }); natcasesort($files); $parser = new DocumentParser(); return array_map(function ($file) use($filesystem, $parser) { return $parser->parse($filesystem->get($file)); }, $files); }
/** * Parse a markdown document * * @param string $filepath * @return \Kurenai\Document */ protected function parse($filepath) { $file = file_get_contents($filepath); return $this->parser->parse($file); }