bookdown / Bookdown.Bookdown

Core libraries for Bookdown generation.
http://bookdown.io
MIT License
81 stars 11 forks source link

[WIP] add navigation menu process #26

Closed sandrokeil closed 8 years ago

sandrokeil commented 8 years ago

@pmjones This is a WIP for a navigation menu. Idea is simple. Save all pages to every page and build the menu in a template depending on page type. IndexPage and RootPage is a menu entry, Page is a sub entry of them.

I've to add support for multiple depths.

I'm not sure if we should provide a default menu template or give only an example in the docs like this one?

$page = $this->page;
$isSubMenu = false;
echo '<ul>';
foreach ($page->getMenuEntries() as $entry) {
    if ($entry instanceof \Bookdown\Bookdown\Content\RootPage) {
        echo '<li>';
        echo $this->anchorRaw($entry->getHref(), $entry->getTitle());
        echo '</li>';
        continue;
    }
    if ($entry instanceof \Bookdown\Bookdown\Content\IndexPage) {
        if ($isSubMenu) {
            echo '</ul>';
        }
        $isSubMenu = true;
        echo '<li>';
        echo $this->anchorRaw($entry->getHref(), $entry->getTitle());
        echo '<ul>';
        continue;
    }
    echo '<li>';
    echo $this->anchorRaw($entry->getHref(), $entry->getTitle());
    echo '</li>';
}
if ($isSubMenu) {
    echo '</ul></li>';
}
echo '</ul>';

You will get something like this.

<ul>
    <li><a href="/">proophessor - Exploring prooph components</a></li>
    <li><a href="/proophessor/">Exploring prooph components</a>
        <ul>
            <li><a href="/proophessor/prooph-in-a-nutshell.html">prooph in a nutshell</a></li>
            <li><a href="/proophessor/components.html">prooph components</a></li>
            <li><a href="/proophessor/wishlist.html">Component Wishlist</a></li>
        </ul>
    <li><a href="/snapshotter/">Snapshot tool for the prooph event-store</a>
        <ul>
            <li><a href="/snapshotter/intro.html">snapshotter</a></li>
            <li><a href="/snapshotter/configuration.html">Configuration</a></li>
        </ul>
    </li>
</ul>
sandrokeil commented 8 years ago

This is not needed, because we can use the prev/next functions of the pages.