nanopage icon indicating copy to clipboard operation
nanopage copied to clipboard

Non-path based keys

Open jongacnik opened this issue 7 years ago • 3 comments

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')

jongacnik avatar Apr 19 '18 04:04 jongacnik

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').

jondashkyle avatar Apr 19 '18 05:04 jondashkyle

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.

jongacnik avatar Apr 21 '18 00:04 jongacnik

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.

jondashkyle avatar Apr 21 '18 00:04 jondashkyle