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

Allow sorting on metadata keys. #202

Merged
merged 6 commits into from
May 2, 2016
Merged

Allow sorting on metadata keys. #202

merged 6 commits into from
May 2, 2016

Conversation

tohojo
Copy link
Contributor

@tohojo tohojo commented Apr 27, 2016

This makes it possible to specify metadata keys for the albums_sort_attr and medias_sort_attr configuration options. This is done by prefixing the key with 'meta.', so e.g. albums_sort_attr = 'meta.order' will sort albums on the 'order' metadata key (collected from the .md files in each directory).

Currently, there's no fallback so the metadata key has to exist for all albums/images and wasn't sure how to add tests (there doesn't seem to be any metadata handling in the test cases at all currently?). If you can provide some feedback on how best to do this I can update the pull request :)

This makes it possible to specify metadata keys for the albums_sort_attr
and medias_sort_attr configuration options. This is done by prefixing
the key with 'meta.', so e.g. albums_sort_attr = 'meta.order' will sort
albums on the 'order' metadata key (collected from the .md files in each
directory).

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
@tohojo tohojo mentioned this pull request Apr 27, 2016
@saimn
Copy link
Owner

saimn commented Apr 28, 2016

Thanks for working on this @tohojo !
There are some tests here: https://github.com/saimn/sigal/blob/master/tests/test_gallery.py#L167 (medias_sort_attr is tested, but not albums_sort_attr it seems).
It would be nice also if it doesn't fail if some md file doesn't have the meta. Maybe with something like
.meta.get(meta_key, [''])[0], which will make a long and ugly line, but ... And it will put the items without the meta key at the beginning which is not ideal.

@tohojo
Copy link
Contributor Author

tohojo commented May 1, 2016

Okay, added some tests. Adding an index.md file to the 'test2' directory in the test tree broke another test, so changed the behaviour of the read_markdown() function.

This is obviously a genuine change of behaviour, but it made sense to me: Why would simply having an index.md file with no title defined not still fall back to the directory name? However, if you prefer I do something else to fix the tests, let me know and I can change it :)

@saimn
Copy link
Owner

saimn commented May 1, 2016

Adding an index.md file to the 'test2' directory in the test tree broke another test, so changed the behaviour of the read_markdown() function.

Yes indeed, it was a bug so your fix is fine.

@@ -191,6 +191,18 @@ def test_albums_sort(settings):
a.sort_subdirs('title')
assert [im.title for im in a.albums] == list(reversed(titles))

orders = [d.meta['order'] for d in a.albums]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list could be hard-coded as it is the reference to do the test. It would avoid to rely on the metadata parsing code which is used later in the sort.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true; can do.

@saimn
Copy link
Owner

saimn commented May 1, 2016

If you can handle the case when one of the md files does not have the meta used for the sort, then we are good. Also please add yourself to the AUTHORS files ;). Thanks !

@tohojo
Copy link
Contributor Author

tohojo commented May 1, 2016

Ah yes, totally forgot about that. Will do!

tohojo added 5 commits May 2, 2016 00:17
Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
This fixes the test breakage from adding an index.md with only an Order
key defined.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
This test also tests the missing meta key functionality.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
@tohojo
Copy link
Contributor Author

tohojo commented May 1, 2016

Updated... Should be good to go now :)

@saimn saimn merged commit eabcd4a into saimn:master May 2, 2016
@saimn
Copy link
Owner

saimn commented May 2, 2016

Great, thanks @tohojo !

@saimn saimn added this to the 1.2.0 milestone May 2, 2016
@tohojo tohojo deleted the meta-sort branch May 2, 2016 09:01
kontza pushed a commit to kontza/sigal that referenced this pull request Aug 28, 2020
Allow sorting on metadata keys.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants