From 9df3472ceb98a371a824ac4884b1948821ac1114 Mon Sep 17 00:00:00 2001 From: Tom Wiesing <tkw01536@gmail.com> Date: Thu, 18 May 2017 15:32:56 +0200 Subject: [PATCH] Allow external and static items in menu --- README.md | 26 +++++++++++++- _config.yml | 15 +++++++- _includes/header.html | 80 ++++++++++++++++++++++++------------------- 3 files changed, 84 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 8449d50..3a21f06 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ See the above links for details. This is a [*static website*](http://en.wikipedia.org/wiki/Static_web_page) automatically generated with [Jekyll](http://jekyllrb.com/) by [GitHub Pages](http://pages.github.com/). -### Editing pages online with GitHub +### Editing pages online with GitHub / GitLab You can edit any page by following the `Edit this page` link in the Quick links nav bar. Alternatively, you can directly navigate to the corresponding `.md` (Markdown) file in GitHub. @@ -50,6 +50,30 @@ Other reasons why GitHub's preview may not correspond to the final results are: - Use of [Liquid templates](https://github.com/Shopify/liquid/wiki/Liquid-for-Designers) in the source. - Use of special purpose markup, HTML, and scripts, such as mathematical excerpts written in [MathJax](http://mathjax.org/). +### Editing the menu + +The menu of the page is defined in the ``_config.yml`` file. +It contains three kinds of items: +1. **Folder menu**. An expandable sub-menu that contains all pages in a specific folder. +2. **Internal links**. A single link to a specific page. +3. **External links**. A link to an external page that automatically opens in a new tab. + +The items can be defined by inserting them into the appropriate place in the list of menu items. +They look like +```yaml +# A folder menu for the /people/ folder +- title: 'People' + folder: 'people' +# A single link to the /news/ page. +- title: 'News' + url: '/news/' +# An external link to the bibliography page +- title: 'Bibliography' + external: true + url: 'https://kwarc.github.io/bibs/' +``` + + ### 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 f7c6a6a..87d2a8f 100644 --- a/_config.yml +++ b/_config.yml @@ -17,7 +17,11 @@ gems: - jekyll-github-metadata - jekyll-redirect-from -exclude: ['public/*.md', 'public/*.html', '*/README.md', '*.synctex.gz', '*.aux', '*.nav', '*.out', '*.snm', '*.tex', '*.log', '*.toc'] +exclude: + - 'public/materialize/materialize-src/*' + - 'public/*.md' + - 'public/*.html' + - '*/README.md' # About/contact @@ -46,6 +50,9 @@ fontawesome: font-awesome-4.7.0 menu: - title: 'People' folder: 'people' + - title: 'Bibliography' + external: true + url: 'https://kwarc.github.io/bibs/' - title: 'Research' folder: 'research' - title: 'Systems' @@ -56,6 +63,12 @@ menu: folder: 'students' - title: 'Teaching' folder: 'teaching' + - title: 'News' + url: '/news/' + - title: 'Contact' + url: '/contact/' + + defaults: - diff --git a/_includes/header.html b/_includes/header.html index a6747fe..441344c 100644 --- a/_includes/header.html +++ b/_includes/header.html @@ -28,40 +28,50 @@ {% assign base_folder = url_parts[1] %} {% assign sorted_pages = site.pages | sort:"menu_order" %} - <li class="no-padding"> - <ul class="collapsible collapsible-accordion"> - {% for node in site.menu %} - <li class="bold"> - <a class="collapsible-header {% if base_folder == node.folder %}active{% endif %}">{{ node.title }}</a> - <div class="collapsible-body"> - <ul> - {% for sub in sorted_pages %} - - {% assign sub_parts = sub.url | split: '/' %} - {% assign sub_url = sub_parts | last %} - {% assign sub_folder = sub_parts[1] %} - - {% if sub_folder == node.folder %} - {% if sub.hidden == false %} - <li {% if sub_url == base_url %}class="active"{% endif %}> - <a href="{{ sub.url }}"> - {% if sub.menu_title %} - {{ sub.menu_title }} - {% else %} - {{ sub.title }} - {% endif %} - </a> - </li> - {% endif%} - {% endif %} - {% endfor %} - </ul> - </div> - </li> - {% endfor %} - </ul> - </li> - <li {% if page.url == "/news/" %} class="active" {% endif %}><a href="{{ site.baseurl }}/news/">News</a></li> - <li {% if page.url == "/contact/" %} class="active" {% endif %}><a href="{{ site.baseurl }}/contact/">Contact</a></li> + {% for node in site.menu %} + + {% if node.folder %} + <li class="no-padding"> + <ul class="collapsible collapsible-accordion"> + <li class="bold"> + <a class="collapsible-header {% if base_folder == node.folder %}active{% endif %}">{{ node.title }}</a> + <div class="collapsible-body"> + <ul> + {% for sub in sorted_pages %} + + {% assign sub_parts = sub.url | split: '/' %} + {% assign sub_url = sub_parts | last %} + {% assign sub_folder = sub_parts[1] %} + + {% if sub_folder == node.folder %} + {% if sub.hidden == false %} + <li {% if sub_url == base_url %}class="active"{% endif %}> + <a href="{{ sub.url }}"> + {% if sub.menu_title %} + {{ sub.menu_title }} + {% else %} + {{ sub.title }} + {% endif %} + </a> + </li> + {% endif%} + {% endif %} + {% endfor %} + </ul> + </div> + </li> + </ul> + </li> + {% else if node.url %} + <li + {% if page.url == node.url %} + class="active" + {% endif %} + > + <a href="{% unless node.external %}{{ site.baseurl }}{% endunless %}{{ node.url }}" {% if node.external %}target="_blank"{% endif %}>{{node.title}}</a> + </li> + {% endif %} + {% endfor %} +</li> </ul> \ No newline at end of file -- GitLab