forestryio / jekyll-menus

A menus (site navigation) plugin for your Jekyll website that also works with https://forestry.io (Jekyll CMS)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using the menu url in a permalink?

barnomics opened this issue · comments

commented

In my posts / pages, is it possible to access the url property of a menu to create dynamic permalinks instead of hardcoding them in?

---
title: Test Post 1
layout: default
menus: learn
permalink: /:menus (?) /test-post-title
---

This is the test post

Doesn't work. Hard-coding the permalink does but that's not very cool...

permalink: /learn/test-post-title

Well... I don't know that my intention is to ever necessarily be cool 😉. That said, it depends on what you are trying to do, and why. In your menu you can indeed set a slug that we will use in the menus that we will use when we build a permalink... but if you are trying to access our data in a Jekyll permalink (as your example shows) that is something you will need to consult with Jekyll on because they don't allow the consumption of external data past a static list AFAIW.

commented

Thanks for the quick response! Does that basically mean I should create another variable, like category, to match the menu for the permalink?

Maybe I'm expecting too much from this gem, and really should treat it like a way to create menus and nothing more?

---
title: Test Post 1
layout: default
menus: learn
categories: learn
permalink: /:categories/test-post-title
---

You can create a hook to achieve your goal (https://jekyllrb.com/docs/plugins/hooks -- you probably want to insert yourself into :documents :post_render so that you can alter it before write -- as the permalink is used for where it gets written to) but indeed I do think at the end of the day it might be out of scope (but I would like to know more about your actual goal... with examples if possible.)

We act as an aggregator, with this kind of change we would act as an aggregator, and broker of data back into the source we aggregate... things get particularly complicated when you calculate in that page could be in any number of menu's, so we have to think about what to do in those situations, do we throw the build, or do we ignore the data, or any number of things.

commented

Ok i think I'm starting to understand. I don't know much Ruby so this has not been coming easy to me. Setting up hooks would probably be more effort than its worth for me.

I just want to group content together (collections of pages ... not blog posts). So it seems like the default :categories is the way to get the url to sync up with the menu. It just seemed redundant

/topic-1
 /topic-1/apples
 /topic-1/oranges
/topic-2
 /topic-2/lettuce
 /topic-2/potatoes
 /topic-2/kale

Happy Thanksgiving!

You actually don't need to do anything special in Jekyll, or Jekyll Menu's to do that. Organize your files as so (and then create a collection https://jekyllrb.com/docs/collections), then in each collection page create a menu for your collection, and we'll infer the permalink for the collection on your behalf when you write the menu out.

Happy Thanksgiving to you, as well!