These are chat archives for jescalan/roots

13th
Oct 2016
Carl Morlock
@gin93r
Oct 13 2016 14:34

how do i get metadata into my templates though? i tried adding front matter to a page that would be read by a partial (to check which menu item is inactive) and it didn't seem to work

I'd be interested in seeing what you came up with. I ended up using javascript to set which menu item was active. It would be cool to not have to rely on it.

Tom Kraak
@tkraak
Oct 13 2016 15:17

@dualmoon and @gin93r here is what I hacked together for setting the active menu item:

https://github.com/earlylightmedia/elm/blob/master/views/mixins/_nav.jade

Carl Morlock
@gin93r
Oct 13 2016 15:21
@tkraak That's a nice solution. I wrote a small jquery thinga-ma-jig that read the window.location.pathname and compared it to the href of the nav items. Your solution might be more elegant. I'll have to experiment with it. Though I don't know how the mixins work yet.
Jeff Escalante
@jescalan
Oct 13 2016 15:22
you can use the _page variable to get the page name as well
Carl Morlock
@gin93r
Oct 13 2016 15:22
@jescalan So much more to learn...
Carl Morlock
@gin93r
Oct 13 2016 15:30

you can use the _page variable to get the page name as well

You don't happen to know where the documentation on this is do you? It's not working in my code but at the same time, I'm 99% sure I'm not doing it correctly.

Jeff Escalante
@jescalan
Oct 13 2016 15:47
ah sorry it's _path
i don't think it's documented right now, shame on me
its just a little helper injected into the locals automatically
Carl Morlock
@gin93r
Oct 13 2016 15:48
@jescalan Works wonderfully. Thanks for that :)
Tom Kraak
@tkraak
Oct 13 2016 15:53

I wrote a tiny helper for _path … came in handy:

https://github.com/earlylightmedia/elm/blob/master/helpers/get-page-name.js

and then in a view:
- var page = helpers.getPageName(_path)body(id= page)
or
body(id = helpers.getPageName(_path))
Carl Morlock
@gin93r
Oct 13 2016 16:01

The only issue I see with using _path is for the root page. Because there isn't a path.

Something like this will work for the about page, but not the Home page.

mixin item(uri, label)
    a(class={active: _path == uri} href=uri) #{label}

header
    nav(id="main-nav" v-tester)
        +item("/","Home")
        +item("/about.html", "About")
Carl Morlock
@gin93r
Oct 13 2016 16:28

@tkraak I was able to modify your helper to do what I wanted for the nav - Thanks!

// get-active-page.js
module.exports = function(path)
{
    if(!path)
        return 'Missing path parameter';
    else
        page = path.match(/(\w+)\.html$/);
        return page[1] == "index" ? "/" : page[0];

}

then in view:

- var page = helpers.getActivePage(_path)

mixin item(uri, label)
    a(class={active: page == uri} href=uri) #{label}

header(id=page)
    nav(id="main-nav" v-tester)
        +item("/","Home")
        +item("about.html", "About")
Tom Kraak
@tkraak
Oct 13 2016 16:40
@gin93r … awesome!
CS-LP
@CS-LP
Oct 13 2016 23:19
Hi, Thanks to all involved for making a great project!
CS-LP
@CS-LP
Oct 13 2016 23:59
Just wanted to share tip, I used roots-records to create categories/product pages and it got slow with +100s of pages. Using client-templates from roots I made a separate nodejs script to read in the template and create all of the categories/product pages. Takes 10 sec to make 500 product pages on my machine. Im sure something like this approach or better is already in wide use but I wanted to see if anyone wanted to know more. Im happy to share, thanks again!