-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·456 lines (408 loc) · 18.6 KB
/
index.html
File metadata and controls
executable file
·456 lines (408 loc) · 18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
---
layout: default
meta_title: "APIs.io - Search APIs by What You Want to Accomplish"
meta_description: "Search APIs by capability, provider, schema, or name. Find the right API for what you want to accomplish."
---
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "{{ site.name }}",
"url": "{{ site.url }}",
"description": "{{ site.description }}",
"potentialAction": {
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "{{ site.url }}/?search={search_term_string}"
},
"query-input": "required name=search_term_string"
}
}
</script>
<div style="text-align: center; padding: 2rem 0 1rem;">
<h1 style="font-size: 2rem; margin-bottom: 0.5rem;">API Search</h1>
<p id="search-stats" style="color: #666; margin-bottom: 1.5rem;">
Search across <strong>{{ site.data.stats.providers }}</strong> providers, <strong>{{ site.data.stats.apis }}</strong> APIs, <strong>{{ site.data.stats.capabilities }}</strong> capabilities, and <strong>{{ site.data.stats.schemas }}</strong> schemas
</p>
<form onsubmit="runSearch(); return false;" style="max-width: 640px; margin: 0 auto; position: relative;" autocomplete="off">
<div class="input-group mb-3">
<input type="text" class="form-control form-control-lg" id="api-search" placeholder="What do you want to accomplish?" aria-label="Search" autocomplete="off">
<button class="btn btn-dark btn-lg" type="submit">Search</button>
</div>
<!-- Dimension filter tabs -->
<div class="d-flex justify-content-center gap-2 flex-wrap mb-2" id="dimension-tabs">
<button type="button" class="btn btn-sm btn-dark dim-tab active" data-dim="all">All</button>
<button type="button" class="btn btn-sm btn-outline-success dim-tab" data-dim="capability">Capabilities</button>
<button type="button" class="btn btn-sm btn-outline-primary dim-tab" data-dim="api">APIs</button>
<button type="button" class="btn btn-sm btn-outline-secondary dim-tab" data-dim="provider">Providers</button>
<button type="button" class="btn btn-sm btn-outline-danger dim-tab" data-dim="schema">Schemas</button>
<button type="button" class="btn btn-sm btn-outline-info dim-tab" data-dim="asyncapi">AsyncAPI</button>
<button type="button" class="btn btn-sm btn-outline-purple dim-tab" data-dim="jsonld">JSON-LD</button>
<button type="button" class="btn btn-sm btn-outline-warning dim-tab" data-dim="rules">Rules</button>
</div>
<p style="font-size: 0.8rem; color: #999; margin-top: 0.5rem;">
Try: "run reports", "firewall rules", "event tracking", "audience segmentation", "compliance"
<br><a href="https://vocabularies.apis.io/" style="color: #0d6efd;">Advanced Search</a> — search by resource, action, persona, domain, and schema
</p>
</form>
</div>
<div id="active-filters" style="max-width: 800px; margin: 1rem auto 0; text-align: center; display: none;"></div>
<div id="status-bar" style="max-width: 800px; margin: 1.5rem auto 0.5rem; display: none; color: #666; font-size: 0.9rem;">
<span id="status-text"></span>
</div>
<div id="search-results" style="max-width: 800px; margin: 0 auto;"></div>
<div id="pagination" style="max-width: 800px; margin: 1.5rem auto; text-align: center;"></div>
<noscript>
<h2>Browse APIs</h2>
<p>Visit <a href="https://providers.apis.io/">providers.apis.io</a> to browse all providers, or <a href="https://apis.apis.io/">apis.apis.io</a> to browse individual APIs.</p>
</noscript>
<style>
mark.hl { background: #fff3a3; padding: 0 2px; border-radius: 2px; }
.result-card { transition: background 0.1s; }
.result-card:hover { background: #f8f9fa; }
.tag-chip { cursor: pointer; user-select: none; }
.tag-chip:hover { background: #6c757d !important; color: white !important; }
.tag-chip.active { background: #0d6efd !important; color: white !important; }
.dim-tab { transition: all 0.15s; }
.dim-tab.active { pointer-events: none; }
.type-badge { font-size: 0.65rem; font-weight: 600; padding: 0.15em 0.5em; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.5px; vertical-align: middle; color: white; }
.type-provider { background: #6c757d; }
.type-api { background: #0d6efd; }
.type-capability { background: #198754; }
.type-schema { background: #dc3545; }
.type-asyncapi { background: #1e40af; }
.type-jsonld { background: #7c3aed; }
.type-rules { background: #c2410c; }
.btn-outline-purple { color: #7c3aed; border-color: #7c3aed; }
.btn-outline-purple:hover { background: #7c3aed; color: white; border-color: #7c3aed; }
.btn-purple { background: #7c3aed; color: white; border-color: #7c3aed; }
</style>
<script src="/assets/minisearch.min.js"></script>
<script>
(function() {
var PAGE_SIZE = 25;
var index = null;
var miniSearch = null;
var indexLoading = null;
var currentResults = [];
var currentPage = 0;
var currentQuery = '';
var activeTags = new Set();
var activeDimension = 'all';
var debounceTimer = null;
// Federated search indexes from all subdomain sites
var INDEXES = [
'https://providers.apis.io/search-index.json',
'https://apis.apis.io/search-index.json',
'https://capabilities.apis.io/search-index.json',
'https://schemas.apis.io/search-index.json',
'https://asyncapi.apis.io/search-index.json',
'https://json-ld.apis.io/search-index.json',
'https://rules.apis.io/search-index.json'
];
function loadIndex() {
if (indexLoading) return indexLoading;
setStatus('Loading search index...');
indexLoading = Promise.all(INDEXES.map(function(url) {
return fetch(url).then(function(r) { return r.json(); }).catch(function() { return []; });
})).then(function(results) {
// Merge all indexes, re-index the i field sequentially
var merged = [];
var idx = 0;
for (var r = 0; r < results.length; r++) {
for (var j = 0; j < results[r].length; j++) {
var item = results[r][j];
item.i = idx++;
merged.push(item);
}
}
index = merged;
// Update stats
var counts = {};
merged.forEach(function(it) { counts[it.type] = (counts[it.type] || 0) + 1; });
var statsEl = document.getElementById('search-stats');
if (statsEl) {
var parts = [];
if (counts.provider) parts.push('<strong>' + counts.provider + '</strong> providers');
if (counts.api) parts.push('<strong>' + counts.api + '</strong> APIs');
if (counts.capability) parts.push('<strong>' + counts.capability + '</strong> capabilities');
if (counts.schema) parts.push('<strong>' + counts.schema + '</strong> schemas');
if (counts.asyncapi) parts.push('<strong>' + counts.asyncapi + '</strong> event specs');
if (counts.jsonld) parts.push('<strong>' + counts.jsonld + '</strong> vocabularies');
if (counts.rules) parts.push('<strong>' + counts.rules + '</strong> rulesets');
statsEl.innerHTML = 'Search across ' + parts.join(', ');
}
miniSearch = new MiniSearch({
fields: ['n', 'd', 't', 'st'],
storeFields: ['i'],
idField: 'i',
extractField: function(doc, field) {
if (field === 't') return (doc.t || []).join(' ');
return doc[field] || '';
},
searchOptions: {
boost: { n: 4, st: 3, t: 2, d: 1 },
prefix: true,
fuzzy: 0.2,
combineWith: 'AND'
}
});
miniSearch.addAll(merged);
setStatus('');
return index;
});
return indexLoading;
}
function setStatus(text) {
var bar = document.getElementById('status-bar');
if (!text) { bar.style.display = 'none'; return; }
document.getElementById('status-text').innerHTML = text;
bar.style.display = '';
}
function escapeHtml(s) {
if (s == null) return '';
return String(s).replace(/[&<>"']/g, function(c) {
return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c];
});
}
function highlight(text, query) {
if (!text || !query) return escapeHtml(text);
var escaped = escapeHtml(text);
var terms = query.trim().split(/\s+/).filter(function(t) { return t.length > 1; });
terms.forEach(function(term) {
var re = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')', 'gi');
escaped = escaped.replace(re, '<mark class="hl">$1</mark>');
});
return escaped;
}
function applyFilters(results) {
if (activeDimension !== 'all') {
results = results.filter(function(item) { return item.type === activeDimension; });
}
if (activeTags.size > 0) {
results = results.filter(function(item) {
if (!item.t) return false;
var lowerTags = item.t.map(function(x) { return (x || '').toLowerCase(); });
var allMatch = true;
activeTags.forEach(function(tag) {
if (lowerTags.indexOf(tag.toLowerCase()) === -1) allMatch = false;
});
return allMatch;
});
}
return results;
}
function executeSearch(query) {
if (!miniSearch) return [];
if (!query) return index.slice();
var hits = miniSearch.search(query);
return hits.map(function(h) { return index[h.i]; });
}
function runSearch() {
var query = document.getElementById('api-search').value.trim();
currentQuery = query;
currentPage = 0;
loadIndex().then(function() {
var results;
if (!query && activeTags.size === 0 && activeDimension === 'all') {
renderResults([], 0);
return;
}
results = executeSearch(query);
results = applyFilters(results);
currentResults = results;
renderResults(results, currentPage);
updateUrl(query);
});
}
function getTypeBadge(type) {
var labels = { provider: 'Provider', api: 'API', capability: 'Capability', schema: 'Schema', asyncapi: 'AsyncAPI', jsonld: 'JSON-LD', rules: 'Rules' };
return '<span class="type-badge type-' + type + '">' + (labels[type] || type) + '</span>';
}
function getBorderColor(type) {
var colors = { provider: '#6c757d', api: '#0d6efd', capability: '#198754', schema: '#dc3545', asyncapi: '#1e40af', jsonld: '#7c3aed', rules: '#c2410c' };
return colors[type] || '#6c757d';
}
function renderResults(results, page) {
var container = document.getElementById('search-results');
var total = results.length;
var start = page * PAGE_SIZE;
var end = Math.min(start + PAGE_SIZE, total);
if (total === 0) {
if (currentQuery || activeTags.size > 0 || activeDimension !== 'all') {
setStatus('No results found. Try different terms or remove filters.');
} else {
setStatus('');
}
container.innerHTML = '';
renderPagination(0, 0);
return;
}
var dimLabels = { capability: 'capabilities', asyncapi: 'AsyncAPI specs', jsonld: 'JSON-LD vocabularies' };
var dimLabel = activeDimension === 'all' ? 'results' : (dimLabels[activeDimension] || activeDimension + 's');
setStatus('Found <strong>' + total + '</strong> ' + dimLabel + (currentQuery ? ' matching "' + escapeHtml(currentQuery) + '"' : '') + ' (showing ' + (start + 1) + '–' + end + ')');
var html = '<div class="list-group">';
for (var i = start; i < end; i++) {
var item = results[i];
var name = highlight(item.n || '', currentQuery);
var desc = highlight(item.d || '', currentQuery);
var borderColor = getBorderColor(item.type);
html += '<div class="list-group-item result-card" style="border-left: 3px solid ' + borderColor + ';">';
html += '<div class="d-flex justify-content-between align-items-start">';
html += '<div style="flex: 1; min-width: 0;">';
html += '<h6 style="margin-bottom: 0.25rem;">';
html += '<a href="' + item.u + '" style="text-decoration: none;">' + name + '</a> ';
html += getTypeBadge(item.type);
if (item.p) html += ' <small style="color: #999; font-weight: normal;">· ' + escapeHtml(item.p) + '</small>';
html += '</h6>';
if (item.d) html += '<p style="font-size: 0.85rem; color: #666; margin-bottom: 0.4rem;">' + desc + '</p>';
if (item.type === 'provider') {
html += '<div style="font-size: 0.8rem; color: #999;">';
if (item.ac) html += item.ac + ' APIs';
if (item.cc) html += ' · ' + item.cc + ' Capabilities';
html += '</div>';
}
if (item.t && item.t.length > 0) {
html += '<div style="display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.3rem;">';
var maxTags = Math.min(item.t.length, 5);
for (var t = 0; t < maxTags; t++) {
if (item.t[t]) {
var tagSafe = escapeHtml(item.t[t]);
html += '<span class="badge bg-light text-dark tag-chip" data-tag="' + tagSafe + '" style="font-size: 0.7rem; font-weight: 500;">' + tagSafe + '</span>';
}
}
html += '</div>';
}
html += '</div>';
html += '<div class="d-flex gap-2 ms-3 flex-shrink-0">';
if (item.h) html += '<a href="' + item.h + '" target="_blank" rel="noopener" class="btn btn-sm btn-outline-primary">Docs</a>';
if (item.type === 'capability') html += '<a href="https://github.com/naftiko/fleet" target="_blank" rel="noopener" class="btn btn-sm btn-success">Run with Naftiko</a>';
html += '<a href="' + item.u + '" class="btn btn-sm btn-outline-dark">View</a>';
html += '</div>';
html += '</div>';
html += '</div>';
}
html += '</div>';
container.innerHTML = html;
container.querySelectorAll('.tag-chip').forEach(function(el) {
el.addEventListener('click', function() { addTagFilter(el.getAttribute('data-tag')); });
});
renderPagination(total, page);
}
function renderPagination(total, page) {
var container = document.getElementById('pagination');
if (total <= PAGE_SIZE) { container.innerHTML = ''; return; }
var totalPages = Math.ceil(total / PAGE_SIZE);
var html = '<nav><ul class="pagination justify-content-center">';
html += '<li class="page-item' + (page === 0 ? ' disabled' : '') + '"><a class="page-link" href="#" data-page="' + (page - 1) + '">Previous</a></li>';
var startP = Math.max(0, page - 2);
var endP = Math.min(totalPages, startP + 5);
if (startP > 0) html += '<li class="page-item"><a class="page-link" href="#" data-page="0">1</a></li><li class="page-item disabled"><span class="page-link">…</span></li>';
for (var p = startP; p < endP; p++) {
html += '<li class="page-item' + (p === page ? ' active' : '') + '"><a class="page-link" href="#" data-page="' + p + '">' + (p + 1) + '</a></li>';
}
if (endP < totalPages) html += '<li class="page-item disabled"><span class="page-link">…</span></li><li class="page-item"><a class="page-link" href="#" data-page="' + (totalPages - 1) + '">' + totalPages + '</a></li>';
html += '<li class="page-item' + (page >= totalPages - 1 ? ' disabled' : '') + '"><a class="page-link" href="#" data-page="' + (page + 1) + '">Next</a></li>';
html += '</ul></nav>';
container.innerHTML = html;
container.querySelectorAll('.page-link[data-page]').forEach(function(el) {
el.addEventListener('click', function(e) {
e.preventDefault();
var p = parseInt(el.getAttribute('data-page'), 10);
if (p < 0 || p >= totalPages) return;
currentPage = p;
renderResults(currentResults, currentPage);
window.scrollTo({ top: document.querySelector('form').offsetTop, behavior: 'smooth' });
});
});
}
function addTagFilter(tag) {
activeTags.add(tag);
renderActiveFilters();
runSearch();
}
function removeTagFilter(tag) {
activeTags.delete(tag);
renderActiveFilters();
runSearch();
}
function renderActiveFilters() {
var container = document.getElementById('active-filters');
if (activeTags.size === 0) { container.style.display = 'none'; return; }
var html = '<small style="color: #888;">Filtering by: </small>';
activeTags.forEach(function(tag) {
html += '<span class="badge bg-primary" style="margin-right: 0.3rem; cursor: pointer;" data-rm="' + escapeHtml(tag) + '">' + escapeHtml(tag) + ' ×</span>';
});
container.innerHTML = html;
container.style.display = '';
container.querySelectorAll('[data-rm]').forEach(function(el) {
el.addEventListener('click', function() { removeTagFilter(el.getAttribute('data-rm')); });
});
}
function updateUrl(query) {
if (window.history.replaceState) {
var url = query ? '?search=' + encodeURIComponent(query) : window.location.pathname;
window.history.replaceState(null, '', url);
}
}
// Dimension tab switching
document.querySelectorAll('.dim-tab').forEach(function(btn) {
btn.addEventListener('click', function() {
document.querySelectorAll('.dim-tab').forEach(function(b) {
b.classList.remove('active');
b.classList.remove('btn-dark', 'btn-success', 'btn-primary', 'btn-secondary', 'btn-danger', 'btn-info', 'btn-purple', 'btn-warning');
var dim = b.getAttribute('data-dim');
var outlineClass = {
all: 'btn-outline-dark',
capability: 'btn-outline-success',
api: 'btn-outline-primary',
provider: 'btn-outline-secondary',
schema: 'btn-outline-danger',
asyncapi: 'btn-outline-info',
jsonld: 'btn-outline-purple',
rules: 'btn-outline-warning'
}[dim] || 'btn-outline-dark';
b.classList.add(outlineClass);
});
btn.classList.add('active');
var dim = btn.getAttribute('data-dim');
var solidMap = {
all: ['btn-outline-dark', 'btn-dark'],
capability: ['btn-outline-success', 'btn-success'],
api: ['btn-outline-primary', 'btn-primary'],
provider: ['btn-outline-secondary', 'btn-secondary'],
schema: ['btn-outline-danger', 'btn-danger'],
asyncapi: ['btn-outline-info', 'btn-info'],
jsonld: ['btn-outline-purple', 'btn-purple'],
rules: ['btn-outline-warning', 'btn-warning']
};
var pair = solidMap[dim] || solidMap.all;
btn.classList.remove(pair[0]);
btn.classList.add(pair[1]);
activeDimension = dim;
runSearch();
});
});
// Wire up events
var input = document.getElementById('api-search');
input.addEventListener('focus', loadIndex);
input.addEventListener('input', function() {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(runSearch, 200);
});
input.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
runSearch();
}
});
window.runSearch = runSearch;
// Init from URL query
var qs = getQueryVariable('search');
if (qs && qs !== '') {
input.value = qs;
loadIndex().then(runSearch);
}
})();
</script>