Skip to content

Commit

Permalink
add sort
Browse files Browse the repository at this point in the history
$Product
Instructure
AWS
  • Loading branch information
thedannywahl committed Feb 16, 2024
1 parent 65adeaa commit 13b7ca6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion isp-site/src/utils/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,33 @@ async function getGithubRepoContents(owner, repo, branch) {
});
const data = await response.json();

return data.tree || null;
return data.tree.sort(sortProduct).reverse() || null;
} catch (error) {
console.error(`Error: ${error.message}`);
return null;
}
}

function sortProduct(a, b) {
const getPriorityIndex = (path) => {
const uPath = path.toLocaleUpperCase();
const index = priorityStrings.findIndex((str) =>
uPath.startsWith(str.toLocaleUpperCase()),
);
return index !== -1 ? index : priorityStrings.length;
};

const priorityStrings = ["Amazon Web Services", "Instructure"];

const priorityA = getPriorityIndex(a.path);
const priorityB = getPriorityIndex(b.path);

if (priorityA !== priorityB) {
return priorityA - priorityB;
}
return a.path.localeCompare(b.path);
}

function formatGithubContents(contents, owner, repo, name, language) {
const l = language;
const s = getStrings(strings, l);
Expand Down

0 comments on commit 13b7ca6

Please sign in to comment.