jgm / yst

create static websites from YAML data and string templates
GNU General Public License v2.0
379 stars 38 forks source link

Support custom `$nav$` rendering using templates #46

Open jmitchell opened 7 years ago

jmitchell commented 7 years ago

$nav$ currently generates hard-coded HTML (see https://github.com/jgm/yst/blob/e3838d318318012d9237c9a34e792d1a630805d5/Yst/Render.hs#L77). It would be great if users could specify a template for it instead.

If you're interested I can work on this and file a PR.

Possible solution

Custom nav templates could be specified by setting an optional setting in the config.

config.yaml

navigation: navmenu.st

If it isn't set $nav$ in a layout template could fallback to a default template which renders the same HTML yst does now. The default would be something like this:

navmenu.st

<ul class="nav tree" $if(!it.toplevel)$style="display: none;"$endif$>
  $if(it.page)$
    <li $if(it.current)$class="current"$endif$>
      <a href="$it.url$">$it.title$</a>
    </li>
  $else$   <!-- a submenu -->
    <a class="tree-toggle nav-header">$it.title$</a>
    $it.entries:navmenu()$
  $endif$
</ul>
jmitchell commented 7 years ago

By the way, this was prompted because the generated class="nav tree" part needs to be class="nav navbar-nav" to look right with Bootstrap. Bootstrap also seems to expect class="active" instead of class="current". I'm guessing their CSS API changed at some point.

At the very least I'd like Bootstrap support improved, but a more generic solution like the one proposed above would be even better.

EDIT: See PR #47 for Bootstrap navigation compatibility improvements.

jmitchell commented 7 years ago

This feature could resolve #27.

jgm commented 7 years ago

I'd consider a template if this isn't already solved by #47.

jmitchell commented 7 years ago

47 resolves my immediate concern, and I don't have any pressing need for this now.

Eventually I'd like the flexibility to migrate away from Bootstrap or further customize the navigation, but as I continue playing with yst I may come up with better strategies. There's something to be said for $nav$'s current simplicity.

Thanks for taking the time to consider the issues and PRs I've filed.