(
items: T[],
sort: ExtensionSortOption
): T[] {
return [...items].sort((a, b) => {
if (sort === "lastUpdated") {
const dateA = a.lastUpdated ? new Date(a.lastUpdated).getTime() : 0;
const dateB = b.lastUpdated ? new Date(b.lastUpdated).getTime() : 0;
return dateB - dateA;
}
return a.name.localeCompare(b.name);
});
}
export function renderExtensionsHtml(items: RenderableExtension[]): string {
if (items.length === 0) {
return renderEmptyStateHtml(
"No extensions found",
"No canvas extensions are available right now."
);
}
return items
.map((item) => {
const installUrl =
item.installUrl ||
(item.path && item.ref
? `https://github.com/github/awesome-copilot/tree/${item.ref}/${item.path.replace(
/\\/g,
"/"
)}`
: "");
const sourceUrl =
item.sourceUrl || (item.path ? getGitHubUrl(item.path) : "");
const previewMediaHtml = item.imageUrl
? ``
: `Canvas
`;
const infoExtraHtml = `
${
item.keywords && item.keywords.length > 0
? item.keywords
.map((kw) => `${escapeHtml(kw)}`)
.join("")
: ""
}
`;
const metaHtml = `
${item.external ? 'External' : ""}
${getLastUpdatedHtml(item.lastUpdated)}
`;
const actionsHtml = `
${
sourceUrl
? `Source`
: ""
}
`;
return renderSharedCardHtml({
title: item.name,
description: item.description || "Canvas extension",
previewMediaHtml,
infoExtraHtml,
metaHtml,
actionsHtml,
tabIndex: 0,
articleAttributes: {
id: item.id,
"data-extension-id": item.id,
},
});
})
.join("");
}