jondashkyle / nanopage

super handy utilities for traversing flat content state
Apache License 2.0
42 stars 4 forks source link

Non-path based keys #4

Open jongacnik opened 6 years ago

jongacnik commented 6 years ago

Potentially allow lookups for keys not formatted like a path. This is mainly for allowing edge-case arbitrary content (I've been doing this), for example your content object could be shaped like:

{
  'GLOBAL': {},
  '/': {},
  '/projects': {},
  '/projects/a': {}
}

Where GLOBAL is content that is general to the whole site. In your views you could then use something like:

page('GLOBAL').value('title')
jondashkyle commented 6 years ago

that’s interesting. how does this work if we’re wanting to check global vs. local? for example page('child-page-example') vs. page('/root-page-example').

jongacnik commented 6 years ago

Not sure what you mean by global vs local? I guess another way to phrase what I mean here is maybe it's best not to do anything fancy when calling page(). Like, under the hood it could be as simple as:

function page (key) {
  key = key || (state.href || '/')
  this._value = state.content[key]
  return this
}

Doing it this way might reduce complexity, in that it doesn't impose any restrictions on how your state is structured—all you have to do is pass in a key. That could be 'page-slug' or '/page-slug' or 'GLOBAL' or whatever key you want.

jondashkyle commented 6 years ago

ah word, i meant root or relative, i guess. i think you’re right in that now we no longer have to compare against a pages object, so we can do something as simple as what you’re saying, which is sick.