{{Pager}} Sort Order not working || YMAL vs JSON
Opened this issue · 0 comments
This {{pager pagination}} helper seems very promising... now only if I could get it to work right.
I'm having a 2 main issues right now.
1) Got trouble setting the next and previous sort order. By default it seems to be in alphabetical order.
2) I'd like to use a JSON file, so I can manage the sort order from a single file, while still loading YMAL variables and content from pages as usual.
My Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
posts: grunt.file.readJSON('src/pages/_directory.json'),
options: {livereload:true},
assemble: {
options: {
flatten: false,
assets: 'dist/assets/',
data: ['src/data/*.json'],
layoutdir: 'src/layouts/',
partials: 'src/partials/**/*.hbr',
helpers: ['src/helpers/**/*.js','handlebars-helper-eachitems'],
collections: [{
name: 'pages',
sortby: 'chapter',
sortorder: 'descending'
}],
},
homepage: {
options: {
layout: 'homepage.hbr'
},
expand: true,
cwd: 'src/pages/',
src: ['index.hbr'],
dest: 'dist/'
},
single: {
options: {
layout: 'single.hbr',
//pages: '<%= posts.listing %>', // breaks pages and assemble creates 6 copies each page.
//data: 'src/pages/*.json',
},
expand: true,
cwd: 'src/pages/',
src: ['**/*.hbr','!index.hbr'],
dest: 'dist/'
}
}
//...
_directory.json contains pages in desired order:
{
"listing": {
"services": {
"data": {
"chapter": "services"
}
},
"we-help-the-economy": {
"data": {
"chapter": "we-help-the-economy"
}
},
"evolution": {
"data": {
"chapter": "evolution"
}
},
"the-model": {
"data": {
"chapter": "the-model"
}
},
"close": {
"data": {
"chapter": "close"
}
}
}
}
When pages: '<%= posts.listing %>', the assemble:single task creates each page 6 times. The pages become blank and the pager starts working funky. When I comment out that line, it goes back to normal, but still the pages are in alphabetical order.
src/pages/close.hbr:
---
order: 4
section: SECTION_PLACEHOLDER
chapter: Close
listed: true
---
<h2>All Sections</h2>
{{#each pages }}
<li><a href="{{replaceStr this.dest 'dist' ''}}">{{data.chapter}}</a></li>
{{/each}}
<h2>All Sections w/ Sorting</h2>
{{#withSort pages "data.order"}}
{{#each this.pages}}
<li><a href="{{replaceStr this.dest 'dist' ''}}">{{data.chapter}}</a></li>
{{/each}}
{{/withSort}}
<h2>Pager</h2>
{{pager pagination}}
Which compiles to:
All Sections
- Close
- Evolution
- Services
- The model
- We help the economy
All Sections w/ Sorting
(nothing here)
Pager
POPULAR
Next (Evolution) -->
Thanks for reading through this long post. Any help would be appreciated!