getpelican / pelican

Static site generator that supports Markdown and reST syntax. Powered by Python.
https://getpelican.com
GNU Affero General Public License v3.0
12.62k stars 1.81k forks source link

does pelican have support for data files like in Jekyll? #3031

Closed shirooo39 closed 2 years ago

shirooo39 commented 2 years ago

Issue

Hi! I'm currently writing a Material Design theme for Pelican, but I'm stuck.

in my theme, I want to have the flexibility to add or remove multiple navigation links, which each of them could have an icon right next to them and this have to be easy for non-tech people.

I tried to write it as a Python list, but I just can't get my head to work as it might involves multi-dimensional list, or a dictionary containing multiple values, or a bunch of for loops. I don't know, I have no idea for now...

in the config.py: example using multiple lists

NAV_ITEM_NAMES = ['Home', 'Categories', 'About']
NAV_ITEM_URLS = ['/', '/categories.html', '/about.html']
NAV_ITEM_ICONS = ['icon 1', 'icon 2', 'icon 3']

I want to be able to assign each URL and ICON that corresponds to the NAME.

my real question, does Pelican support something like Jekyll's data files?

if there is support for this, writing themes will be much more easier (hopefully).

I can forget about the lists or dictionaries and have the items written like:

data file: navigation.yaml

- name: home
  url: /
  icon: material_home

- name: external
  url: https//www.google.com
  icon: (no icon)

these items can be accessed globally. would be even better if the items can be iterated

for items in site.data.navigation
   # do something

Note: Please don't automatically close this issue, I'll close it once I could figure out how to do what I needed in the above. I do need the help from anyone seeing this open issue.

justinmayer commented 2 years ago

To my knowledge Pelican core does not have such a thing. I don't think it's ever been needed before, but maybe there are plugins that offer such functionality.

I think a dict is probably the way to go, instead of three lists.

virtadpt commented 2 years ago

@shirooo39 I did something similar with my site. I wound up forking and editing the sidebar template file for my site's theme to build the list.

However, now that I think about it, I think it is possible to do what you want. The original version of the theme that I use has code for it in the templates/base.html file. Check this out and see if it makes sense:

https://github.com/mc-buckets/brutalist/blob/master/templates/base.html#L84

justinmayer commented 2 years ago

Many thanks for the suggestion, @virtadpt!

@shirooo39: If we can be of further assistance, please let us know.