Jekyll - Automatically highlight current tab in menu bar

后端 未结 12 1005
鱼传尺愫
鱼传尺愫 2020-12-22 15:34

I am using github to host a static site and Jekyll to generate it.

I have a menu bar (as

    ) and would like the
  • correspo
12条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-22 15:59

    I feel like for the simplest navigation requirement, the listed solutions are overly complex. Here's a solution that involves no front matter, javascript, loops, etc.

    Since we have access to the page URL, we can normalize and split the URL and test against the segments, like so:

    {% assign current = page.url | downcase | split: '/' %}
    
    
    

    Of course, this is only useful if static segments provide the means to delineate the navigation. Anything more complicated, and you'll have to use front matter like @RobertKenny demonstrated.

提交回复
热议问题