assemble/grunt-assemble

grunt-assemble withSort stops working

maekke97 opened this issue · 4 comments

Hi,
I'm not sure if this is the correct place to post this, please redirect me if I'm wrong.
We have a grunt setup to create our api documentation (http://api.meteomatics.com).
The main content pages have a handlebar header as follows:

---
title: Overview
sortOrder: 0
---

Our news blog entries like so:

---
title: "Model Output Statistics (MOS) is now available in our API" # 'to change' - Title for news blog always inside of ""
posted: "2018-04-06T12:00Z" # 'to change' - Posted Date (Format YYYY-MM-DDTHH:mmZ) UTC Time
linkforid: "2018-04-06Mos" # 'to change' - Link to scroll to this news blog, has to be unique
notInNav: true # 'keep this' - it hides the news blog in the side navigation, but it is still in the News tab
post: true # 'keep this if' - true shows this news blog, false hide it
---

Then we build our navbar using #withSort:

<ul class="nav navbar-nav">
  {{#isnt page.data.notInNav true}}
    {{#withSort  pages 'data.sortorder'}}
      {{#isnt data.notInNav true}}
        <li {{#is ../../page.dest this.dest}} class="active"{{/is}}><a href="{{filename}}" >{{data.title}}{{#is pagename "Search.html"}}<span style="float:right; margin-right: 30px;">&#128269;</span>{{/is}}</a>
        </li>
      {{/isnt}}
    {{/withSort}}
  {{else}}
    {{#withSort  pages 'data.sortorder'}}
      {{#isnt data.notInNav true}}
        <li  {{#is ../../page.title 'Available Parameters'}}
          {{#is this.dest "dest/Available-Parameters.html"}}
          class="active"
          {{/is}}
          {{/is}}><a href="{{filename}}" >{{data.title}}
        </li>
      {{/isnt}}
    {{/withSort}}
{{/isnt}}
</ul>

(I removed some content to make the example smaller)
This works all fine with up to 41 input pages. As soon as I add the 42nd (The 10th news blog entry), the sorting breaks and the navigation is in alphabetical order.

Does anyone have an Idea, what this could be?

@maekke97 Thanks for the issue! If you're reporting a bug, please be sure to include:

  • The version of assemble you are using.
  • Your assemblefile.js (This can be in a gist)
  • The commandline output. (Screenshot or gist is fine)
  • What you expected to happen instead.
doowb commented

One thing that I noticed is that in the yaml frontmatter the property is sortOrder (with a capital O) but the template uses data.sortorder (with a lowercase o). Since you say that this works up to 41 items, then I'm assuming that may have been a typo in the issue.

If it was a typo and that's not causing an issue, I'm not exactly sure what might be going on. It would help if you could share the repository or at least a list of all of the pages with their sortOrder properties (the sorting might be comparing strings instead of numbers). Also, if you could provide more of the information requested by the assemblebot, it would be helpful.

Hi, thanks for looking into this.
It actually is a typo that has no effect. (I just checked that it does not matter if you have )

I'm not able to share the repo, as it lies on our privat company server, sorry.
What I can share: (please let me know if you need more infos)

$ grunt -V
grunt-cli v1.2.0
grunt v0.4.5
$ npm -v
6.1.0
$ node -v
v8.11.4
$ npm list grunt-assemble
assemble-example@0.1.1
└── grunt-assemble@0.6.3 

The project structure:

|-templates/
|--includes/
|---allnewsblog.hbs -> sortorder: -1
|---head.hbs -> No sortorder field
|---navbar.hbs -> No sortorder field
|---newssideblog.hbs -> No sortorder field
|--AP-Agricultural-Parameters.hbs -> sortorder: 3.5
|--AP-Atmospheric-Pollution.hbs -> sortorder: 3.5
|--AP-XYZ (there are 16 more) all -> sortorder: 3.5
|--API-Request.hbs -> sortorder: 4
|--API-Response.hbs -> sortorder: 5
|--Appendix.hbs -> sortorder: 9
|--Avaliable-Parameters.hbs -> sortorder: 3.4
|--DataConnectors.hbs -> sortorder: 3
|--FAQ.hbs -> sortorder: 8.5
|--GettingStarted.hbs -> sortorder: 2
|--Imprint.hbs -> sortorder: 11
|--index.hbs -> sortorder: 0
|--News.hbs -> sortorder: -1
|--Overview.hbs -> sortorder: 0
|--Search.hbs -> sortorder: 1
|--WFS-Interface.hbs -> sortorder: 7
|--WMS-Interface.hbs -> sortorder: 6
|-content/
|--news/
|---2018-04-06-Mos.md -> posted: "2018-04-06T12:00Z"
|---2018-04-06-News.md -> posted: "2018-04-06T09:00Z"
|---2018-04-06-Zip.md -> posted: "2018-04-06T13:00Z"
|---2018-04-11-Satellite.md -> posted: "2018-04-11T09:00Z"
|---2018-04-23-WfsStations.md -> posted: "2018-04-23T16:00Z"
|---2018-06-06-Hail.md -> posted: "2018-06-06T20:00Z"
|---2018-07-30-GoogleSpreadSheet.md -> posted: "2018-07-30T11:00Z"
|---2018-07-31-Tableau.md -> posted: "2018-07-31T11:00Z"
|---2018-08-01-Qlik.md -> posted: "2018-08-01T11:00Z"
|---2018-09-11-Cesium.md -> posted: "2018-09-11T09:00Z"
|--AP-Agricultural-Parameters.md
|--... (One .md for each .hbs in templates)
|-Gruntfile.js (see below)

Gruntfile.js:

grunt.initConfig({
        assemble: {
            options: {
              collections: [{
                  name: 'post',
                  sortby: 'posted',
                  sortorder: 'descending'
                }],
                flatten: true,
                partials: ['templates/includes/*.hbs'],
                layoutdir: 'templates/layouts',
                layout: 'default.hbs'
            },
            site: {
                files: {
                    'dest/': ['templates/*.hbs','content/news/*.md']
                }
            }
        },
...

Grunt assembles all without error. The result with only 9 news blog files can be seen here: http://api.meteomatics.com/
(We removed the 2018-04-06-News.md file from the productive tree for now)
When I compile locally with the file, the Menu is the following:
bildschirmfoto 2018-09-12 um 16 05 05
Lower part:
bildschirmfoto 2018-09-12 um 16 13 26

doowb commented

Thanks for the additional information, I'll try to look at this soon.