Skip to content

Instantly share code, notes, and snippets.

@mgirouard
Last active December 20, 2015 17:19
Show Gist options
  • Select an option

  • Save mgirouard/6168062 to your computer and use it in GitHub Desktop.

Select an option

Save mgirouard/6168062 to your computer and use it in GitHub Desktop.
var years = {};
$('.blog-sidebar .widget_archive a').each(function () {
var year = this.innerHTML.match(/\d{4}/)[0];
if (!years[year]) years[year] = [];
years[year].push(this);
});
_.each(years, function (links, year) {
var li = $('<li/>'), a = $('<a/>'), ul = $('<ul/>');
a.appendTo(li).attr('href', '/blog/' + year).text(year);
ul.appendTo(li);
_.each(links, function (link) {
var parent = $(link).parent();
$('<li/>').appendTo(ul).append(link);
parent.remove();
});
$('.blog-sidebar .widget_archive > ul').prepend(li);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment