/hyde/layouts/starter/content/advanced/sorter.html

http://github.com/hyde/hyde · HTML · 53 lines · 42 code · 11 blank · 0 comment · 0 complexity · 1e52eb3c3ef8c71ebb005f598c8382ff MD5 · raw file

  1. ---
  2. index: 2
  3. title: Sorting
  4. tags:
  5. - sort
  6. learning_order: 1
  7. ---
  8. Sorting
  9. =======
  10. There will come a time when you will need to list and sort resources. Hyde
  11. allows you to walk the site tree and sort the resources by the predefined
  12. settings in your configuration file.
  13. You can list and sort by name all your content files.
  14. {# With every sorter defined in the configuration file, nodes get a method
  15. to call. Notice that in the first and last example the method is called
  16. on the whole content of the site, while the second example shows how to
  17. invoke it only on one specific node (in this case the current one).
  18. Also, some new Jinja filters were used to style the output.
  19. #}
  20. {% for res in site.content.walk_resources_sorted_by_name() %}
  21. * [{{ res.slug|capitalize|replace("-"," ") }}]({{ res.full_url }})
  22. ({{ res.name }})
  23. {% endfor %}
  24. Or list only those in the current node (folder). In this case that would be
  25. all advanced topics.
  26. {# Have in mind that using the next example in a content page (like here) or
  27. using it in a layout (Jinja template that is extended or include by
  28. content pages) will yield very different results.
  29. In this case it will be called only once, for this resource, and shown
  30. only on this page. If it was in a layout, it would be called for EVERY
  31. resource that uses that layout. In that case the context would be
  32. different, the parent node of the resource could be different and the
  33. results will probably be different too.
  34. #}
  35. {% for res in resource.node.walk_resources_sorted_by_index() %}
  36. {{ loop.index }}. [{{ res.slug|capitalize }}]({{ res.full_url }})
  37. {% endfor %}
  38. Or sort files by type and then by size.
  39. {% for res in site.content.walk_resources_sorted_by_file_type() %}
  40. * [{{ res.source_file.kind|upper }}] {{ res.name }}
  41. {% endfor %}
  42. {{ macros.render_bottom_article_nav() }}