• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A menus (site navigation) plugin for your Jekyll website that also works with https://forestry.io (Jekyll CMS)

Jekyll Menus

A robust, simple-to-use menu plugin for Jekyll that allows for infinitely nested menus.

Installation

To install and use Jekyll Menus, you should have Ruby, and either RubyGems, or we recommend using Bundler. Bundler is what Jekyll will prefer you to use by default if you jekyll new.

Using Bundler

You can add our gem to the jekyll_plugins group in your Gemfile:

group :jekyll_plugins do
   gem "jekyll-menus"
end

And then install from shell.

bundle install
   # --path vendor/bundle

If you are using Jekyll Docker, you do not need to perform this step, Jekyll Docker will perform it on your behalf when you launch the image, you only need to perform this step if you are working directly on your system.

Using RubyGems

sudo gem install jekyll-menus
sudo gem update  jekyll-menus

Once installed, add the Gem to your _config.yml:

plugins:
- jekyll-menus

Note in earlier versions of Jekyll, plugins should instead be gems

Usage

Jekyll Menus allows you to create menus by attaching posts and pages to menus through their front matter, or by defining custom menu items via _data/menus.yml.

Jekyll Menus adds a new option to the site variable called site.menus, which can be looped over just like pages, posts, and other content:

<ul>
{% for item in site.menus.header %}
  <li class="menu-item-{{ loop.index }}">
    <a href="{{ item.url }}" title="Go to {{ item.title }}">{{ item.title }}</a>
  </li>
{% endfor %}
</ul>

Menus via Front Matter

The easiest way to use Jekyll Menus is to start building menus using your existing posts and pages. This can be done by adding a menus variable to your front matter:

---
title: Homepage
menus: header
---

This will create the header menu with a single item, the homepage. The url, title, and identifier for the homepage menu item will be automatically generated from the pages title, file path, and permalink.

You can optionally set any of the available menu item variables yourself to customize the appearance and functionality of your menus. For example, to set a custom title and weight:

---
title: Homepage
menus:
  header:
    title: Home
    weight: 1
---

Custom Menu Items via _data/menus.yml

The other option for configuring menus is creating menus using _data/menus.yml. In this scenario, you can add custom menu items to external content, or site content that isn’t handled by Jekyll.

In this file, you provide the menu key and an array of custom menu items. Custom menu items in the data file must have url, title, and identifier variable:

---
header:
  - url: /api
    title: API Documentation
    identifier: api
---

Sub-menus

Jekyll Menus supports infinitely nested menu items using the identifier variable. Any menu item can be used as a parent menu by using its identifier as the menu.

For example, in _data/menus.yml:

header:
  - url: /api
    title: API Documentation
    identifier: api

In a content file called /api-support.html:

---
title: Get API Support
menus: api
---

Which can then be used in your templates by looping over the menu item’s children variable:

<ul>
{% for item in site.menus.header %}
  <li class="menu-item-{{ loop.index }}">
    <a href="{{ item.url }}" title="Go to {{ item.title }}">{{ item.title }}</a>
    {% if item.children %}
      <ul class="sub-menu">
      {% for item in item.children %}
        <li class="menu-item-{{ loop.index }}">
          <a href="{{ item.url }}" title="Go to {{ item.title }}">{{ item.title }}</a>
        </li>
      {% endfor %}
      </ul>
    {% endif %}
  </li>
{% endfor %}
</ul>

You can also do this recursively using a re-usable include, allowing for easily managed infinitely nested menus.

Variables

Jekyll Menus has the following variables:

Menus

Variable Description
menu.menu Returns a JSON object with all of the menu’s items.
menu.identifier The unique identifier for the current menu, generated from the menu key. Allows for nested menu items.
menu.parent The parent menu. Resolves to the site.menus object for top-level menus.

Menu Items

Variable Description
item.title The display title of the menu item. Automatically set as the post or page title if no value is provided in front matter.
item.url The URL the menu item links to. Automatically set to the post or page URL if no value is provided in front matter.
item.weight Handles the order of menu items through a weighted system, starting with 1 being first.
item.identifier The unique identifier for the current menu item. Allows for nested menu items. Automatically resolved to the page’s file path and filename if not provided in front matter.
item.parent The parent menu.
item.children An array of any child menu items. Used to create sub-menus.

Custom Variables

Menu items also support custom variables, which you add to each menu item in the front matter or data file.

For example, adding a pre or post variable to add text or HTML to your menu items:

---
title: Homepage
menus:
  header:
    pre: <i class="icon-home"></i>
    post: " · "
---

Recursive Menus

If you’re looking to build an infinitely nested menu (or a menu that is nested more than once up to a limit) then you should set up a reusable menu include that will handle this for you.

In _includes/menu.html :

{% if menu %}
<ul>
{% for item in menu %}
  <li class="menu-item-{{ loop.index }}">
    <a href="{{ item.url }}" title="Go to {{ item.title }}">{{ item.title }}</a>
    {% if item.children %}
      {% assign menu = item.children %}
      {% include menu.html %}
    {% endif %}
  </li>
{% endfor %}
</ul>
{% endif %}

In _layouts/default.html (or any layout file):

<html>
  <body>
    <header>
      <nav>
        {% assign menu = site.menus.header %}
        {% include menus.html %}
      </nav>
    </header>
    {{ content }}
  </body>
</html>

More Repositories

1

hugo-theme-novela

Novela, the simplest way to start publishing with Hugo and Forestry.
SCSS
361
star
2

forestry.io

Forestry.io website
HTML
279
star
3

ubuild-jekyll

A Jekyll theme designed to work with Forestry Blocks
HTML
273
star
4

portfolio-vuepress

Vuepress portfolio
Vue
193
star
5

create-static-site

Create static websites with no build configuration.
JavaScript
135
star
6

novela-hugo-starter

Novela, the simplest way to start publishing with Hugo and Forestry.
63
star
7

sawmill

A Hugo theme built for Forestry.io blocks
HTML
38
star
8

gatsby-starter-forestry

A gatsby starter site pre-configured for Forestry
JavaScript
29
star
9

cloudformation-templates

JAMStack templates for AWS CloudFormation
26
star
10

forestry-vscode

A Visual Studio Code extension for developing projects managed with Forestry.io
TypeScript
18
star
11

ubuild-hugo

HTML
12
star
12

hydeout-jekyll-starter

A starter using @FongAndrew's updated Hyde Theme called Hydeout for Jekyll and Forestry as a Content Manager. Demo Site:
HTML
11
star
13

next-blog-forestry

NextJS Blog Starter for Forestry
JavaScript
11
star
14

hyde-hugo-starter

A starter using @SPF13's ported Hyde Theme for Hugo and Forestry as a Content Manager. Demo Site:
10
star
15

markdown-it-kramdown-attrs

Kramdown style attributes for Common.js (Markdown-it)
JavaScript
8
star
16

ubuild-hugo-starter

8
star
17

ubuild-blocks

uBuild is a CSS toolkit for creating modular page components.
CSS
7
star
18

kross-hugo-starter

A portfolio template editable in Forestry
7
star
19

gatsby-theme-novela

TypeScript
4
star
20

demo-portfolio

A Jekyll version of the "Phantom" theme by HTML5 UP with the help of Andrew Banchich https://andrewbanchich.gitlab.io/Phantom-Jekyll-Theme
CSS
4
star
21

eleventy-base-forestry

Eleventy base blog starter for Forestry
HTML
4
star
22

create-observable-thunk

Provides a H.O.F. that wraps any function returning an Rx.Observable in a Thunk
TypeScript
3
star
23

hugo-parsa-forestry

Hugo Parsa Forestry Starter
3
star
24

markdown-it-preserve-newline

Preserve newlines on certain inline elements (like images.)
JavaScript
2
star
25

hugo-ananke-forestry

Hugo Ananke starter for Forestry
2
star
26

demo-site

This is a modified version Brian Rinaldi's Hugo site from https://github.com/remotesynth/Static-Site-Samples. Using it for testing forestry.io.
CSS
2
star
27

markdown-it-codeblock-type

Add `data-md-type` to your codeblocks for `md<->html`
JavaScript
2
star
28

hugo-northendlab-forestry

Hugo starter for Forestry CMS with Northelab theme
1
star
29

onprem-cloudformation-sample

Sample AWS CloudFormation for Forestry on-premise resources
1
star
30

casper3-hugo-starter

Hugo Casper 3 starter pre-configured for Forestry CMS
1
star
31

react-patterns-article

Code samples behind the React Patterns article.
TypeScript
1
star