Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 53 additions & 8 deletions .github/appstore.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.commonmark.Extension;
import org.commonmark.ext.autolink.AutolinkExtension;
Expand Down Expand Up @@ -335,16 +337,59 @@ class Template {

class Cataloger {
public final int aliasCount;
public final List<CatalogItem> aliases;
private List<CatalogItem> templates;
private int templateCount;
public final int templateCount;
public final List<CatalogEntry> catalogs;

public Cataloger(List<CatalogItem> items, List<CatalogItem> sortedTemplates) {
this.aliases = items;
aliasCount = items.size();
public Cataloger(List<CatalogItem> aliasItems, List<CatalogItem> templateItems) {
// Group by repo
Map<String, CatalogEntry> entries = new LinkedHashMap<>();

this.templates = sortedTemplates;
this.templateCount = sortedTemplates.size();
for (CatalogItem item : aliasItems) {
entries.computeIfAbsent(item.repoOwner + "/" + item.repoName,
k -> new CatalogEntry(item.repoOwner, item.repoName, item.stars, item.icon_url, item.link))
.aliases.add(new CompactItem(item));
}
for (CatalogItem item : templateItems) {
entries.computeIfAbsent(item.repoOwner + "/" + item.repoName,
k -> new CatalogEntry(item.repoOwner, item.repoName, item.stars, item.icon_url, item.link))
.templates.add(new CompactItem(item));
}

this.catalogs = new ArrayList<>(entries.values());
this.aliasCount = aliasItems.size();
this.templateCount = templateItems.size();
}
}

class CatalogEntry {
public final String owner;
public final String name;
public final int stars;
public final String icon;
public final String link;
public final List<CompactItem> aliases = new ArrayList<>();
public final List<CompactItem> templates = new ArrayList<>();

public CatalogEntry(String owner, String name, int stars, String icon, String link) {
this.owner = owner;
this.name = name;
this.stars = stars;
this.icon = icon;
this.link = link;
}
}

class CompactItem {
public final String a; // alias
public final String d; // description (nullable)
public final String s; // scriptRef (nullable)
public final String c; // command

public CompactItem(CatalogItem item) {
this.a = item.alias;
this.d = item.description;
this.s = item.scriptRef;
this.c = item.command;
}
}

Expand Down
39 changes: 15 additions & 24 deletions content/appstore.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,19 @@ <h2>JBang AppStore</h2>
fetch('/assets/data/jbang-appstore.json')
.then(r => { if (!r.ok) throw new Error(r.status); return r.json(); })
.then(data => {
allGroups = groupByRepo(data.aliases || []);
allGroups = (data.catalogs || []).map(function(cat) {
return {
repo: cat.owner + '/' + cat.name,
icon: cat.icon,
owner: cat.owner,
name: cat.name,
stars: cat.stars || 0,
link: cat.link || ('https://github.com/' + cat.owner + '/' + cat.name),
aliases: (cat.aliases || []).map(function(a) {
return { command: a.c, description: a.d || null };
})
};
});
loadingEl.style.display = 'none';
contentEl.style.display = 'block';
applyFilter();
Expand All @@ -104,27 +116,6 @@ <h2>JBang AppStore</h2>
errorEl.style.display = 'block';
});

// Group aliases by repo
function groupByRepo(aliases) {
const map = new Map();
for (const a of aliases) {
const key = a.repoOwner + '/' + a.repoName;
if (!map.has(key)) {
map.set(key, {
repo: key,
icon: a.icon_url,
owner: a.repoOwner,
name: a.repoName,
stars: a.stars || 0,
link: 'https://github.com/' + key,
aliases: []
});
}
map.get(key).aliases.push(a);
}
return Array.from(map.values());
}

// Search
searchInput.addEventListener('input', function() {
currentPage = 1;
Expand All @@ -144,7 +135,7 @@ <h2>JBang AppStore</h2>
filteredGroups = [];
for (const g of allGroups) {
const matchingAliases = g.aliases.filter(a =>
a.command.toLowerCase().includes(q) ||
(a.command && a.command.toLowerCase().includes(q)) ||
(a.description && a.description.toLowerCase().includes(q)) ||
g.repo.toLowerCase().includes(q)
);
Expand Down Expand Up @@ -184,7 +175,7 @@ <h2>JBang AppStore</h2>
${g.aliases.map(a => `
<tr>
<td class="appstore-alias-cell">
<button class="appstore-copy outline small" title="Copy jbang command" data-cmd="${esc(a.fullcommand)}">
<button class="appstore-copy outline small" title="Copy jbang command" data-cmd="jbang ${esc(a.command)}">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</button>
<code>${esc(a.command)}</code>
Expand Down
Loading
Loading