From 2cf5c92ad784ff97a5cdb7bdf41f8adfd4ff1113 Mon Sep 17 00:00:00 2001 From: Tom Wiesing <tkw01536@gmail.com> Date: Fri, 23 Jun 2017 17:32:51 -0400 Subject: [PATCH] Update the menu --- README.md | 6 +++++- _config.yml | 6 ++++-- _includes/menu_single.html | 19 +++++++++++++++++ _includes/menu_sub.html | 42 ++++++++++++++++++++++++++------------ 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 892edf1..b2c00a3 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ The menu of the page is defined in the ``_config.yml`` file. It consists of a set of items, that are defined by the following keys: * `url` - The (internal or external) url to the page. If internal, must be relative to the root directory. +* `active` - URL to a folder under which the item should automatically be expanded (if applicable). * `folder` - Instead of using `url`, the `folder` can be used to create a submenu pointing to a specific folder. * `items` - A list of items for submenus. * `external` - If set to `true`, assumes that `url` is external to the page. @@ -97,7 +98,7 @@ It consists of a set of items, that are defined by the following keys: 2. An item specifies the `items` key. Here the items are used accordingly. 3. An item specifies both the `folder` and `items` keys. The items for both cases are automatically merged. -Because submenus are not clickable, the `url` for submenus is ignored. +Because submenus are not clickable, the `url` for submenus is ignored when building the menu. Furthermore, if these are mixed between folders and static items, the folders will always show first. ```yaml @@ -115,6 +116,9 @@ Furthermore, if these are mixed between folders and static items, the folders wi url: 'https://cs.fau.de/' ``` +A submenu is automatically expanded if any of the submenu items inside it are clicked. +Alternatively, if the menu item contains an `active` key, it is checked as well. + ### Working locally If you want to do more than the occasional editing, you'll soon realise GitHub's editor and preview are too limited. diff --git a/_config.yml b/_config.yml index 72e8c95..9d64609 100644 --- a/_config.yml +++ b/_config.yml @@ -1,4 +1,4 @@ -permalink: pretty +permalink: /news/:year/:month/:day/:title/ # Setup title: KWARC @@ -11,7 +11,6 @@ paginate_path: "/news/page:num/" blog_path: "/news/" future: True gems: - - jemoji - jekyll-paginate - jekyll-github-metadata - jekyll-redirect-from @@ -44,7 +43,10 @@ fontawesome: font-awesome-4.7.0 menu: - title: 'News' url: '/news/' + active: '/news/' + - title: 'People' + active: '/people/' items: - title: 'Current Members' url: '/people/' diff --git a/_includes/menu_single.html b/_includes/menu_single.html index 6dec52f..4e8b3c7 100644 --- a/_includes/menu_single.html +++ b/_includes/menu_single.html @@ -2,8 +2,27 @@ This page creates a single (non-submenu) item. It expects `item` as a variable. {% endcomment %} +{% assign menu_active = false %} + +{% assign base_folder = page.url | split: '/' %} +{% assign base_folder = base_folder[1] %} + +{% assign represents = item.active | split: '/' %} +{% assign represents = represents[1] %} + +{% if represents %} + {% if base_folder == represents %} + {% assign menu_active = true %} + {% endif %} +{% endif %} + +{% if page.url == item.url %} + {% assign menu_active = true %} +{% endif %} + {% unless item.menu_hidden %} <li + {% if menu_active %}class="active"{% endif %} {% if page.url == item.url %}class="active"{% endif %} > {% if item.external %} diff --git a/_includes/menu_sub.html b/_includes/menu_sub.html index de57fe2..d803532 100644 --- a/_includes/menu_sub.html +++ b/_includes/menu_sub.html @@ -5,21 +5,37 @@ {% unless item.menu_hidden %} {% assign base_folder = page.url | split: '/' %} - - <!-- if we are in the right folder, we are active --> - {% if base_folder[1] == item.folder %} - {% assign menu_active = true %} - {% else %} - {% assign menu_active = false %} - {% for item in (item.items | where: "url", page.url) %} - {% unless item.external %} + {% assign base_folder = base_folder[1] %} + + {% assign represents = item.active | split: '/' %} + {% assign represents = represents[1] %} + + {% assign menu_active = false %} + + {% if base_folder %} + {% if item.folder %} + {% if base_folder == item.folder %} {% assign menu_active = true %} - <!-- active because {{item}} --> - {% endunless %} - {% endfor %} + {% endif %} + {% endif %} {% endif %} - - + + {% if represents %} + {% if base_folder == represents %} + {% assign menu_active = true %} + {% endif %} + {% endif %} + + {% unless menu_active %} + {% for it in item.items %} + {% if page.url == it.url %} + {% unless it.external %} + {% assign menu_active = true %} + {% endunless %} + {% endif %} + {% endfor %} + {% endunless %} + <!-- Find the current folder --> {% assign item_folder = item.folder %} -- GitLab