Christian Gill
Christian Gill

Reputation: 524

Harp.js: generate a navigation for my site

Hi I's starting to develop a site using harp.js and was wondering if there is a way to build a automatic navigation for a site using the variables that are exposed to the templates. Something like this:

for url in public._contents
    li= url

I know _contents does not work that way.

Upvotes: 1

Views: 281

Answers (2)

Alice Tribuleva
Alice Tribuleva

Reputation: 33

I think you'll still have to pull the variables from JSON global object or an array. But I'd love to hear about any other solutions, not using metadata, too.

using Pug (Jade), from this thread:

- var items = { home : 'Home', about: 'About', account: 'Account' }
  ul
    - for item, path in items
      li
        a(href="/" + path) #{item}

using EJS, using two arrays with the same length:

<nav>
<% for (item in urls, titles) { %>
  <a href="<%= urls[item] %>">
    <span class="menu-item"><%= titles[item] %></span>
  </a>
<% } %>
</nav>

global harp.json:

{
  "globals": {
    "titles": [
      "post title 1",
      "post title 2",
      "post title 3"
    ],
    "urls": [
      "post-title-1",
      "post-title-2",
      "post-title-custom-url"
    ]
  }
}

Please, also take a look at the current object: http://harpjs.com/docs/development/current

Upvotes: 0

Sascha
Sascha

Reputation: 1156

As far as I know the jade processor does not provide verbose log information, neither in harp nor in the npm. So I'd like to suggest to traverse the files bevore like

grep -r '\- var' .

what will give you something like

./sub/sub.jade:- var variableInSub = true
./sub/sub2.jade:- var variableInSub2 = true
./main.jade:- var variableInMain = true

that you can split and use to build an own datastructure of used variables in the files.

Upvotes: 1

Related Questions