logspot icon indicating copy to clipboard operation
logspot copied to clipboard

My bad needed a more in depth fix

Open versecafe opened this issue 1 year ago • 3 comments

was originally sorting off unknown fetch order, which appears to have been the URL path string, now it reorders the data off the version in:

const { data } = await useAsyncData("feed", () =>
  queryContent("/posts").find()
);
const sorted_data = data.value.sort((a, b) => {
  const a_version = a.version.split('.').map(Number);
  const b_version = b.version.split('.').map(Number);
  const max_length = Math.max(a_version.length, b_version.length);
  for (let i = 0; i < max_length; i++) {
    const a_part = a_version[i] || 0;
    const b_part = b_version[i] || 0;
    if (a_part < b_part) {
      return 1;
    } else if (a_part > b_part) {
      return -1;
    }
  }
  return 0;
});

Example Image

image

I did test that this works as you continue up in versions, it will not work for things like .10 but sorting by date does not

versecafe avatar Nov 27 '23 04:11 versecafe