Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata in Locals, incl.pagination #18

Open
lunelson opened this issue Aug 6, 2019 · 0 comments
Open

Metadata in Locals, incl.pagination #18

lunelson opened this issue Aug 6, 2019 · 0 comments
Projects

Comments

@lunelson
Copy link
Owner

lunelson commented Aug 6, 2019

locals

$page keys

$pkg
$env
$data
$page
  url -> pass to link()
  slug ->
  matter -> from gray-matter
  params -> from dynamic segment matchers
  srcFile
  outFile
  ? date -> parsed from creation date; can be overriden from 'matter'
  ? title -> parsed from slug; can be overriden from 'matter'
  ? paginated -> added if matter contains valid `paginate` instructions
      index: __p || 0
      group: chunk(data, size)[__p]
      groups: chunk(data, size)[__p]
      baseUrl: same as $page.url
      prevUrl: prev page's url
      nextUrl: next page's url
      lastUrl: last page's url
$pages

NOTE: the $page local is actually a getter, since on first call it might need to evaluate the paginate.data key from matter. The following is a rough sketch of how this works:

const vm = require('vm')

const locals = {
  get $page() {
    const { matter: { paginate } } = this.__$p;
    if (!paginate) return this.__$p
    if ('__$e' in this) return this.__$e;
    this.__$e = this.__$p;
    this.__$e.matter.paginate.data = vm.runInNewContext(paginate.data, this);
    return this.__$e;
  },
  __$p: {
    matter: {
      paginate: {
        data: '$data.posts',
        size: 5
      }
    }
  },
  $data: {
    posts: [
      1, 2, 3, 4
    ]
  }
}
@lunelson lunelson created this issue from a note in Penny 2 (WIP) Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant