if (Meteor.isClient) {

  Template.library.get_works = function() {
    /* TODO support {sort: [blah]} */
    return Works.find({}, {
      fields: {
        title: 1,
        author: 1,
        summary: 1,
        annotationsCount: 1,
        year: 1
      }
    });
  }

  Template.library.grid_classes = function() {
    if (Session.equals('library-mode', 'grid')) {
      return 'grid small-block-grid-1 medium-block-grid-2 large-block-grid-3'
    } else  {
      return '';
    }
  }

  Template.work.published = function() {
    if (this.year !== null) {
      return ', ' + this.year.toString();
    } else {
      return '';
    }
  }

}

@@ -69,41 +69,396 @@
     
-/* TODO support %7Bsort: %5Bblah%5D%7D */
+var sortby = Session.get('library-sort'),%0A        sort_spec = %5B'title'%5D,%0A        sort_add = null;%0A%0A    if (sortby === 'annos') %7B%0A      sort_add = %5B'annotationsCount', 'desc'%5D;%0A    %7D else if (sortby === 'author') %7B%0A      sort_add = 'author';%0A    %7D else if (sortby === 'year') %7B%0A      sort_add = %5B'year', 'desc'%5D;%0A    %7D%0A%0A    if (sort_add !== null) %7B%0A      sort_spec.unshift(sort_add)%0A    %7D%0A
 %0A   
@@ -604,15 +604,38 @@
 : 1%0A
-
       %7D
+,%0A      sort: sort_spec
 %0A   

Add sorting by title, author, # of annotations, and publication year.