ux-at-icfnext / 11

0 stars 0 forks source link

alpha sort for side menu #24

Open dara-icf opened 1 month ago

dara-icf commented 1 month ago

11ty doesn't have sort out-of the box (aside from create date -- and reverse create date)

we tried a few code blocks in the config file including

eleventyConfig.addCollection("patterns", function (collectionApi) {
    return collectionApi.getAll().sort(function (a, b) {
      //return a.date - b.date; // sort by date - ascending
      return a.title - b.title; // sort by date - descending
      //return a.inputPath.localeCompare(b.inputPath); // sort by path - ascending
      //return b.inputPath.localeCompare(a.inputPath); // sort by path - descending
    });
  });

and

 eleventyConfig.addCollection("patterns", collection =>
    collection
      .getAll()
      .filter(function(item) {
        return "patterns" in item.data;
      })
      .sort((a, b) => {
        return (a.data.patterns.title - b.data.patterns.title);
      })
  );
dara-icf commented 1 month ago

A hackey way to do this is to just date: the files in YAML.

Not sustainable -- but since components are slow to come out of USWDS... maybe this works 🤷🏽‍♀️