Skip to content

Commit

Permalink
Use eleventy-navigation plugin for navigation menu
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Nov 11, 2019
1 parent 0da708e commit c9018fa
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ const { DateTime } = require("luxon");
const fs = require("fs");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginNavigation = require("@11ty/eleventy-navigation");

module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.setDataDeepMerge(true);

eleventyConfig.addLayoutAlias("post", "layouts/post.njk");
Expand Down
12 changes: 7 additions & 5 deletions _includes/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
<body>
<header>
<h1 class="home"><a href="{{ '/' | url }}">{{ metadata.title }}</a></h1>
<ul class="nav">
{%- for nav in collections.nav | reverse -%}
<li class="nav-item{% if nav.url == page.url %} nav-item-active{% endif %}"><a href="{{ nav.url | url }}">{{ nav.data.navtitle }}</a></li>
{%- endfor -%}
</ul>
<!-- Read more about `eleventy-navigation` at https://github.com/11ty/eleventy-navigation -->
{{ collections.all | eleventyNavigation | eleventyNavigationToHtml({
listClass: "nav",
listItemClass: "nav-item",
activeListItemClass: "nav-item-active",
activeKey: eleventyNavigation.key
}) | safe }}
</header>

<main{% if templateClass %} class="{{ templateClass }}"{% endif %}>
Expand Down
6 changes: 3 additions & 3 deletions about/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
layout: layouts/post.njk
title: About Me
tags:
- nav
navtitle: About
eleventyNavigation:
key: About Me
order: 2
templateClass: tmpl-post
---

Expand Down
6 changes: 3 additions & 3 deletions archive.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
layout: layouts/home.njk
tags:
- nav
navtitle: Archive
eleventyNavigation:
key: Archive
order: 3
permalink: /posts/
---

Expand Down
6 changes: 3 additions & 3 deletions index.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
layout: layouts/home.njk
tags:
- nav
navtitle: Home
eleventyNavigation:
key: Home
order: 1
---

<h1>Latest 3 Posts</h1>
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"build": "npx eleventy",
"watch": "npx eleventy --watch",
"serve": "npx eleventy --serve",
"debug": "DEBUG=* npx eleventy"
},
"repository": {
Expand All @@ -23,6 +24,7 @@
"homepage": "https://github.com/11ty/eleventy-base-blog#readme",
"devDependencies": {
"@11ty/eleventy": "^0.9.0",
"@11ty/eleventy-navigation": "^0.1.0",
"@11ty/eleventy-plugin-rss": "^1.0.7",
"@11ty/eleventy-plugin-syntaxhighlight": "^2.0.3",
"luxon": "^1.12.0",
Expand Down

0 comments on commit c9018fa

Please sign in to comment.