diff --git a/daux.phar b/daux.phar index 6df9c6f..dbe17e1 100755 Binary files a/daux.phar and b/daux.phar differ diff --git a/docs/01_Features/Search.md b/docs/01_Features/Search.md new file mode 100644 index 0000000..5fb99e3 --- /dev/null +++ b/docs/01_Features/Search.md @@ -0,0 +1,13 @@ +Searching in a Daux.io documentation is possible, but only in static mode. + +We don't provide this feature in live rendering as it would be too slow. + +To enable the generated search, you can set `search` to true in the `html` section of your configuration + +```json +{ + "html": { + "search": true + } +} +``` diff --git a/global.json b/global.json index 617e56f..22fd103 100644 --- a/global.json +++ b/global.json @@ -30,6 +30,7 @@ "date_modified": false, "float": false, "auto_landing": true, + "search": true, "repo": "", "twitter": [], diff --git a/gulpfile.js b/gulpfile.js index d952b7d..bb72309 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -19,6 +19,7 @@ var unusedRules = [ //We only use one glyphicon ... ".glyphicon-", "!.glyphicon-chevron-right", + "!.glyphicon-search", //we dont need all buttons ".btn-", diff --git a/libs/Console/Generate.php b/libs/Console/Generate.php index 9ec08e9..7ca1c1c 100755 --- a/libs/Console/Generate.php +++ b/libs/Console/Generate.php @@ -21,7 +21,7 @@ class Generate extends SymfonyCommand ->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from') ->addOption('delete', null, InputOption::VALUE_NONE, 'Delete pages not linked to a documentation page (confluence)') ->addOption('destination', 'd', InputOption::VALUE_REQUIRED, $description, 'static') - ->addOption('text_search', '-t', InputOption::VALUE_NONE, 'Generate full text search'); + ->addOption('search', null, InputOption::VALUE_NONE, 'Generate full text search'); } protected function execute(InputInterface $input, OutputInterface $output) diff --git a/libs/Format/HTML/Generator.php b/libs/Format/HTML/Generator.php index fd675b5..292ed89 100755 --- a/libs/Format/HTML/Generator.php +++ b/libs/Format/HTML/Generator.php @@ -10,7 +10,6 @@ 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; use Todaymade\Daux\Tree\Raw; @@ -22,6 +21,8 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator /** @var Daux */ protected $daux; + protected $indexed_pages = []; + /** * @param Daux $daux */ @@ -60,17 +61,18 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator $output->writeLn("Generating ..."); - $text_search = ($input->getOption('text_search')); - $params['text_search'] = $text_search; - if ($text_search) { - $index_pages = []; - } - $this->generateRecursive($this->daux->tree, $destination, $params, $output, $width, $index_pages); + $params['html']['search'] = $input->getOption('search'); + $this->generateRecursive($this->daux->tree, $destination, $params, $output, $width, $params['html']['search']); - if ($text_search) { - $tipuesearch_directory = $this->daux->local_base . DIRECTORY_SEPARATOR . 'tipuesearch' . DIRECTORY_SEPARATOR; - file_put_contents($tipuesearch_directory . 'tipuesearch_content.json', json_encode(['pages' => $index_pages])); - GeneratorHelper::copyRecursive ($tipuesearch_directory, $destination . DIRECTORY_SEPARATOR . 'tipuesearch'); + if ($params['html']['search']) { + GeneratorHelper::copyRecursive( + $this->daux->local_base . DIRECTORY_SEPARATOR . 'tipuesearch' . DIRECTORY_SEPARATOR, + $destination . DIRECTORY_SEPARATOR . 'tipuesearch' + ); + file_put_contents( + $destination . DIRECTORY_SEPARATOR . 'tipuesearch' . DIRECTORY_SEPARATOR . 'tipuesearch_content.json', + json_encode(['pages' => $this->indexed_pages]) + ); } } @@ -110,8 +112,9 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", ), - $text ); - return trim (preg_replace('/\s+/', ' ', strip_tags($text))); + $text + ); + return trim(preg_replace('/\s+/', ' ', strip_tags($text))); } /** @@ -122,10 +125,11 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator * @param \Todaymade\Daux\Config $params * @param OutputInterface $output * @param integer $width + * @param boolean $index_pages * @param string $base_url * @throws \Exception */ - private function generateRecursive(Directory $tree, $output_dir, $params, $output, $width, &$index_pages, $base_url = '') + private function generateRecursive(Directory $tree, $output_dir, $params, $output, $width, $index_pages, $base_url = '') { DauxHelper::rebaseConfiguration($params, $base_url); @@ -146,7 +150,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator "- " . $node->getUrl(), $output, $width, - function() use ($node, $output_dir, $key, $params, &$index_pages) { + function() use ($node, $output_dir, $key, $params, $index_pages) { if ($node instanceof Raw) { copy($node->getPath(), $output_dir . DIRECTORY_SEPARATOR . $key); return; @@ -154,13 +158,13 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator $generated = $this->generateOne($node, $params); file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $generated->getContent()); - if (isset($index_pages)) { - array_push($index_pages, [ + if ($index_pages) { + $this->indexed_pages[] =[ 'title' => $node->getTitle(), - 'text' => utf8_encode($this->strip_html_tags($generated->getContent())), + 'text' => utf8_encode($this->strip_html_tags($generated->getPureContent())), 'tags' => "", 'url' => $node->getUrl() - ]); + ]; } } ); diff --git a/libs/Server/Server.php b/libs/Server/Server.php index a08fe43..1d305b8 100755 --- a/libs/Server/Server.php +++ b/libs/Server/Server.php @@ -99,6 +99,9 @@ class Server $params['base_page'] .= 'index.php/'; } + // Text search would be too slow on live server + $params['html']['search'] = false; + return $params; } @@ -144,9 +147,7 @@ class Server ); } - $params = $this->params; - $params['text_search'] = false; - return $this->daux->getGenerator()->generateOne($file, $params); + return $this->daux->getGenerator()->generateOne($file, $this->params); } public function getRequest() diff --git a/templates/home.php b/templates/home.php index d66ae19..b4dda1d 100755 --- a/templates/home.php +++ b/templates/home.php @@ -45,16 +45,13 @@
- + - - -
- -
+ +
+ +
diff --git a/templates/layout/00_layout.php b/templates/layout/00_layout.php index c1a1f1d..3af9c7e 100755 --- a/templates/layout/00_layout.php +++ b/templates/layout/00_layout.php @@ -23,10 +23,9 @@ echo ""; } ?> - + - - +