getParams(); $this->daux = $daux; $this->templateRenderer = new Template($params); $params->templateRenderer = $this->templateRenderer; } /** * @return array */ public function getContentTypes() { return [ 'markdown' => new ContentType($this->daux->getParams()), ]; } public function generateAll(InputInterface $input, OutputInterface $output, $width) { $destination = $input->getOption('destination'); $params = $this->daux->getParams(); if (is_null($destination)) { $destination = $this->daux->local_base . DIRECTORY_SEPARATOR . 'static'; } $this->runAction( 'Copying Static assets ...', $width, function() use ($destination, $params) { $this->ensureEmptyDestination($destination); $this->copyThemes($destination, $params->getThemesPath()); } ); $output->writeLn('Generating ...'); if (!array_key_exists('search', $params['html']) || !$params['html']['search']) { $params['html']['search'] = $input->getOption('search'); } $this->generateRecursive($this->daux->tree, $destination, $params, $output, $width, $params['html']['search']); GeneratorHelper::copyRecursive( $this->daux->local_base . DIRECTORY_SEPARATOR . '_libraries' . DIRECTORY_SEPARATOR, $destination . DIRECTORY_SEPARATOR . '_libraries' ); if ($params['html']['search']) { GeneratorHelper::copyRecursive( $this->daux->local_base . DIRECTORY_SEPARATOR . 'search' . DIRECTORY_SEPARATOR, $destination . DIRECTORY_SEPARATOR . 'search' ); file_put_contents( $destination . DIRECTORY_SEPARATOR . 'search' . DIRECTORY_SEPARATOR . 'search_index.json', json_encode(['pages' => $this->indexed_pages]) ); if (json_last_error()) { echo "Could not write search index: \n" . json_last_error_msg() . "\n"; } } } /** * Remove HTML tags, including invisible text such as style and * script code, and embedded objects. Add line breaks around * block-level tags to prevent word joining after tag removal. * Also collapse whitespace to single space and trim result. * modified from: http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page * * @param string $text * @return string */ private function sanitize($text) { $text = preg_replace( [ // Remove invisible content '@]*?>.*?@siu', '@]*?>.*?@siu', '@]*?.*?@siu', '@]*?.*?@siu', '@]*?.*?@siu', '@]*?.*?@siu', '@]*?.*?@siu', '@]*?.*?@siu', '@]*?.*?@siu', // Add line breaks before and after blocks '@getFirstPage(); } foreach ($tree->getEntries() as $key => $node) { if ($node instanceof Directory) { $new_output_dir = $output_dir . DIRECTORY_SEPARATOR . $key; mkdir($new_output_dir); $this->generateRecursive($node, $new_output_dir, $params, $output, $width, $index_pages, '../' . $base_url); // Rebase configuration again as $params is a shared object DauxHelper::rebaseConfiguration($params, $base_url); } else { $this->runAction( '- ' . $node->getUrl(), $width, function() use ($node, $output_dir, $key, $params, $index_pages) { if ($node instanceof Raw) { copy($node->getPath(), $output_dir . DIRECTORY_SEPARATOR . $key); return; } $this->daux->tree->setActiveNode($node); $generated = $this->generateOne($node, $params); file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $generated->getContent()); if ($index_pages) { $this->indexed_pages[] = [ 'title' => $node->getTitle(), 'text' => $this->sanitize($generated->getPureContent()), 'tags' => '', 'url' => $node->getUrl(), ]; } } ); } } } /** * @param Entry $node * @param Config $params * @return \Todaymade\Daux\Format\Base\Page */ public function generateOne(Entry $node, Config $params) { if ($node instanceof Raw) { return new RawPage($node->getPath()); } if ($node instanceof ComputedRaw) { return new ComputedRawPage($node); } $params['request'] = $node->getUrl(); $contentPage = ContentPage::fromFile($node, $params, $this->daux->getContentTypeHandler()->getType($node)); $contentPage->templateRenderer = $this->templateRenderer; return $contentPage; } }