From eb89664473ede303b4d6f9a22e3135c7634734c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Tue, 5 Jun 2018 21:28:54 +0200 Subject: [PATCH 1/4] Keep numbers in raw files, as they aren't sorted anyway. Fixes #26 --- libs/Tree/Builder.php | 2 +- tests/Tree/BuilderTest.php | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libs/Tree/Builder.php b/libs/Tree/Builder.php index 50b77c2..2defa09 100644 --- a/libs/Tree/Builder.php +++ b/libs/Tree/Builder.php @@ -99,7 +99,7 @@ class Builder $config = $parent->getConfig(); if (!in_array($file->getExtension(), $config['valid_content_extensions'])) { - $uri = static::removeSortingInformations($file->getFilename()); + $uri = $file->getFilename(); $entry = new Raw($parent, $uri, $file); $entry->setTitle(str_replace('_', ' ', static::removeSortingInformations($name))); diff --git a/tests/Tree/BuilderTest.php b/tests/Tree/BuilderTest.php index 0072f79..a034df5 100644 --- a/tests/Tree/BuilderTest.php +++ b/tests/Tree/BuilderTest.php @@ -1,6 +1,7 @@ setDocumentationDirectory(''); $root = new Root($config); - $dir = Builder::getOrCreateDir($root, 'directory'); $this->assertSame($root, $dir->getParent()); @@ -147,4 +147,28 @@ class BuilderTest extends TestCase $this->assertEquals('file.json', $entry->getUri()); $this->assertInstanceOf('Todaymade\Daux\Tree\ComputedRaw', $entry); } + + public function testScanner() + { + $structure = [ + 'Page.md' => 'another page', + 'Button.md' => 'another page', + '22.png' => '' + ]; + $root = vfsStream::setup('root', null, $structure); + + $config = new Config; + $config->setDocumentationDirectory($root->url()); + $config['valid_content_extensions'] = ['md']; + $config['mode'] = Daux::STATIC_MODE; + $config['index_key'] = 'index.html'; + + $tree = new Root($config); + Builder::build($tree, []); + + $this->assertEquals( + ['22.png', 'Button.html', 'Page.html'], + array_keys($tree->getEntries()) + ); + } } From 7b665558af15e77e0518caeade9aacd3ee16f0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Tue, 5 Jun 2018 22:29:31 +0200 Subject: [PATCH 2/4] Use front matter of the index page to define folder's name. Fixes #27 --- libs/Tree/Builder.php | 8 +++++++- libs/Tree/Directory.php | 14 ++++++++++++-- tests/Tree/BuilderTest.php | 24 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/libs/Tree/Builder.php b/libs/Tree/Builder.php index 2defa09..b3587d5 100644 --- a/libs/Tree/Builder.php +++ b/libs/Tree/Builder.php @@ -75,10 +75,16 @@ class Builder } if ($file->isDir()) { - $new = new Directory($node, static::removeSortingInformations($file->getFilename()), $file); + $title = static::removeSortingInformations($file->getFilename()); + $new = new Directory($node, $title, $file); $new->setName(static::getName($file->getPathName())); $new->setTitle(str_replace('_', ' ', static::removeSortingInformations($new->getName()))); static::build($new, $ignore); + + $index = $new->getLocalIndexPage(); + if ($index && $index->getTitle() != $title) { + $new->setTitle($index->getTitle()); + } } else { static::createContent($node, $file); } diff --git a/libs/Tree/Directory.php b/libs/Tree/Directory.php index d3c6a1f..958f1d6 100644 --- a/libs/Tree/Directory.php +++ b/libs/Tree/Directory.php @@ -125,6 +125,16 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate return $this->parent->getConfig(); } + public function getLocalIndexPage() { + $index_key = $this->getConfig()['index_key']; + + if (isset($this->children[$index_key])) { + return $this->children[$index_key]; + } + + return false; + } + /** * @return Content|null */ @@ -132,8 +142,8 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate { $index_key = $this->getConfig()['index_key']; - if (isset($this->children[$index_key])) { - return $this->children[$index_key]; + if ($this->getLocalIndexPage()) { + return $this->getLocalIndexPage(); } if ($this->getConfig()->shouldInheritIndex() && $first_page = $this->seekFirstPage()) { diff --git a/tests/Tree/BuilderTest.php b/tests/Tree/BuilderTest.php index a034df5..d675925 100644 --- a/tests/Tree/BuilderTest.php +++ b/tests/Tree/BuilderTest.php @@ -171,4 +171,28 @@ class BuilderTest extends TestCase array_keys($tree->getEntries()) ); } + + public function testIndexFrontMatter() + { + $structure = [ + 'folder' => [ + 'index.md' => "---\ntitle: new Title\n---\nThe content", + 'Page.md' => 'another page', + 'Button.md' => 'another page' + ] + ]; + $root = vfsStream::setup('root', null, $structure); + + $config = new Config; + $config->setDocumentationDirectory($root->url()); + $config['valid_content_extensions'] = ['md']; + $config['mode'] = Daux::STATIC_MODE; + $config['index_key'] = 'index.html'; + + $tree = new Root($config); + Builder::build($tree, []); + + $this->assertTrue(array_key_exists('folder', $tree->getEntries())); + $this->assertEquals('new Title', $tree->getEntries()['folder']->getTitle()); + } } From 049e5cd4985a04c45c97eb5f1241f476ec173da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Tue, 5 Jun 2018 22:40:38 +0200 Subject: [PATCH 3/4] Document how you can create a docker image with the documentation inside. Fixes #37 --- Dockerfile | 1 + docs/01_Features/Live_mode.md | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Dockerfile b/Dockerfile index 692f5f2..d6728a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,7 @@ COPY tipuesearch/ /daux/tipuesearch/ COPY global.json /daux/global.json COPY composer.json /daux/composer.json COPY composer.lock /daux/composer.lock +COPY index.php /daux/index.php # Composer install RUN cd /daux && php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ diff --git a/docs/01_Features/Live_mode.md b/docs/01_Features/Live_mode.md index d884928..343f044 100644 --- a/docs/01_Features/Live_mode.md +++ b/docs/01_Features/Live_mode.md @@ -97,3 +97,21 @@ The `web.config` needs an entry for `` under ``: ``` To use clean URLs on IIS 6, you will need to use a custom URL rewrite module, such as [URL Rewriter](http://urlrewriter.net/). + +## Docker + +This is not meant for production use, but you can bundle your documentation in Daux's docker container + +``` +FROM daux/daux.io + +WORKDIR /daux/ +COPY docs/ /daux/docs/ + +EXPOSE 80 +ENTRYPOINT [ "php", "-S", "0.0.0.0:80", "index.php" ] +``` + +When you add this to a `Dockerfile` and run `docker build --name my-daux-doc .` and then `docker --rm run -p 8000:80 my-daux-doc` + +You can access your documentation at `localhost:8000` \ No newline at end of file From 0570fb7971bfa2ff2fc5cb9dc7d33666ee855255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Tue, 5 Jun 2018 23:02:01 +0200 Subject: [PATCH 4/4] Fix breadcrumb support of multiple folders with the same name. Fixes #54 --- libs/Format/HTML/ContentPage.php | 4 ++-- libs/Format/HTML/Template.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/Format/HTML/ContentPage.php b/libs/Format/HTML/ContentPage.php index 6743f73..cb3bf3a 100644 --- a/libs/Format/HTML/ContentPage.php +++ b/libs/Format/HTML/ContentPage.php @@ -52,7 +52,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage if (!empty($parents)) { foreach ($parents as $node) { $page = $node->getIndexPage() ?: $node->getFirstPage(); - $breadcrumb_trail[$node->getTitle()] = $page ? $page->getUrl() : ''; + $breadcrumb_trail[] = ['title' => $node->getTitle(), 'url' => $page ? $page->getUrl() : '']; } } @@ -98,7 +98,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage $page['breadcrumb_separator'] = $params['html']['breadcrumb_separator']; if ($this->homepage) { - $page['breadcrumb_trail'] = [$this->file->getTitle() => '']; + $page['breadcrumb_trail'] = [['title' => $this->file->getTitle(), 'url' => '']]; } } diff --git a/libs/Format/HTML/Template.php b/libs/Format/HTML/Template.php index 691fbb8..fa0900b 100644 --- a/libs/Format/HTML/Template.php +++ b/libs/Format/HTML/Template.php @@ -99,8 +99,8 @@ class Template $title = ''; $breadcrumb_trail = $page['breadcrumb_trail']; $separator = $this->getSeparator($page['breadcrumb_separator']); - foreach ($breadcrumb_trail as $key => $value) { - $title .= '' . $key . '' . $separator; + foreach ($breadcrumb_trail as $value) { + $title .= '' . $value['title'] . '' . $separator; } if ($page['filename'] === 'index' || $page['filename'] === '_index') { if ($page['title'] != '') {