Pelican: Add metadata for custom page ordering

Created on 15 Jul 2012  路  12Comments  路  Source: getpelican/pelican

raignarok in IRC gave me this idea for this feature so I am documenting it.

  • A :page-order: # metadata for pages
  • Any page-order metadata that doesn't cast properly to a number throws a warning and discards the metadata
  • Pages with the page-order metadata go first in the list, sorted in ascending numerically.
  • If there is multiple pages with the same order # then they will be sorted by alpha slug
  • Any pages missing an order # goes at the end of the list alpha-slug just like before to keep compatibility.

This will probably go nicely with #400 and #220 since pages and the location of articles will be way more flexible.

enhancement

Most helpful comment

It may sounds exaggerated, but this is a HUGE improvement to non-blog site projects in Pelican. This feature deserves a better explanation in the docs, maybe a full paragraph. Thank you very much!

All 12 comments

+1 :)

Ok! Its on my todo list

Included for 3.1

+1 - would be lovely to have this feature as well as already mentioned #400 ad #200. Very helpful for project sites or sites of ogrganisations.

@tbunnyman: Do you think you can find some time to work on this issue? Just trying to plan the next release. :smile:

I've just added a pull request with a fix.

This change makes the default sorting order for pages their filenames (new). The default sorting order for articles is still by slug (same as before). But you can tweak how either is sorted in your pelicanconf.py. For example:

PAGE_ORDER_BY = 'page-order'

In this case, just make sure that all pages have the metadata attribute 'page-order'.

Advanced: You could also use a sorting function. See the code for an example, as a sorting function is used to get filenames based on the source_path attribute of content.

This new pull request seems to do it. Hopefully it's accepted.

This interest me and when I will have a little time I may rework this. Still, I would like to propose a slightly different implementation:

  • meta attribute to be called "order" so it is identical for articles too.
  • if is positive pages will be sorted on top based on the same logic, bug if is negative it will sort them after those with no order specific. This would enable you to put a page to the bottom.

I've merged @davidmarble work and @malept tests against current master in #1348

Works like a charm for me.

Feature merged and will be included in Pelican 3.5. Thanks to everyone for their input, contributions, and patience.

It may sounds exaggerated, but this is a HUGE improvement to non-blog site projects in Pelican. This feature deserves a better explanation in the docs, maybe a full paragraph. Thank you very much!

I gave this a try and it didn't work! Then I realized that is because the template which I am using also sort the pages!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Lucas-C picture Lucas-C  路  4Comments

rpmzandwijk picture rpmzandwijk  路  3Comments

begueradj picture begueradj  路  7Comments

jkarimi91 picture jkarimi91  路  6Comments

mwcz picture mwcz  路  5Comments