Log in Sign up

How to sort tags alphabetically?

I'm using the Magazine template and would like to sort the tags in the sidebar alphabetically. Is that possible?


a month ago, 2 replies   developers   magazine-template   Edit question

It's not yet possible to sort tags alphabetically using Blot's template engine. However, you can do this easily using some JavaScript.

You will need to fork an editable version of the Magazine template if you haven't done so already, then paste the following snippet into the script.js file, perhaps at the very end:

const list = document.querySelector('.clip-tags');

[...list.children]
  .sort((a, b) => a.innerText > b.innerText ? 1 : -1)
  .forEach(node => list.appendChild(node));

Source: Easiest way to sort DOM nodes?

Answered 4 years ago · Edit answer

Edited the answer above to fix a bug in the JavaScript – thanks for the report

Answered a month ago · Edit answer