-
Notifications
You must be signed in to change notification settings - Fork 169
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
Conversation
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]>
Thanks for working on this @tohojo ! |
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 :) |
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] |
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.
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.
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.
That is true; can do.
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 ! |
Ah yes, totally forgot about that. Will do! |
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]>
Updated... Should be good to go now :) |
Great, thanks @tohojo ! |
Allow sorting on metadata keys.
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 :)