-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support ordering pages and articles when iterating in templates. #836
Conversation
Order can be set to a metadata attribute or a sorting function. Default to order by slug for articles and order by filename for pages.
|
||
if order_by: | ||
if hasattr(order_by, '__call__'): | ||
index.sort(key=order_by) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a try/except
with a more friendly logging message would be nicer, in case the user gives a bad function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I'll do that.
Oh wow, sorry for not reacting earlier, this was lost in limbo. +1 on this feature, however there are some merge problems with it right now. Could you try to rebase you work? Thanks, |
Hey David. Any chance you could take another look at your pull request and make the changes Alexis suggested? |
Hi David. Would you be so kind as to rebase and squash your changes as @ametaireau suggested? Would be great to get this wrapped up. (^_^) |
Thanks for the nudge Justin. I've had replies to this starred in my inbox for the past few months. Just been too busy to come back to it. If anyone else is reading this and wants to jump in, that'd be great. I may get to it, but just can't promise anything on timing. Free time ebbs and flows! |
Hey David. Just thought I'd nudge you again in the off-chance that your free time might be ebbing instead of flowing. (^_^) What say you? |
I squashed the commits (malept/pelican@0c69f4a) and added a test for ordered pages (malept/pelican@69ff7dd). I'm not quite sure how to test ordered articles, though. I can't seem to use the same pattern as the pages test because, I believe, of this code in ### line that got changed by this PR
self.articles, self.translations = process_translations(all_articles,
order_by=self.settings['ARTICLE_ORDER_BY'])
### [...block that I believe is not relevant to this discussion omitted for brevity...]
# sort the articles by date
### here's the offending line
self.articles.sort(key=attrgetter('date'), reverse=True)
self.dates = list(self.articles)
self.dates.sort(key=attrgetter('date'),
reverse=self.context['NEWEST_FIRST_ARCHIVES']) |
+1 for getting this in ... just having built a site with very weird menu ordering I'd like to fix |
I'm Interested in it too. |
Is this scrapped because its no longer necessary due to other implementation of this feature, or does it meat Pelican won't get this feature ever? |
Because of the other existing pull request, and because the submitter of this pull request is no longer active. |
The order of pages and articles when iterated in templates can now be set to a metadata attribute or a sorting function. By default to articles are sorted by slug (same as before) and pages are sorted by filename (new).
This fixes #420.
You can tweak how pages and articles are sorted in your
pelicanconf.py
. For example: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.