Repository navigation
Expand file tree
/
Copy pathrender.js
More file actions
27 lines (27 loc) · 10.2 KB
/
Copy pathrender.js
File metadata and controls
27 lines (27 loc) · 10.2 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
export const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
export const jsonLD = value => JSON.stringify(value).replace(/</g, '\\u003c');
const link = (label, url, cls='') => `<a class="${esc(cls)}" href="${esc(url)}">${esc(label)}</a>`;
export function card(e) {
return `<article class="listing" data-tool-id="${esc(e.id)}" data-type="${esc(e.type)}" data-category="${esc(e.category)}" data-search="${esc([e.name,e.summary,e.type,e.category].join(' '))}"><div class="thumb${e.image?' has-logo':''}"><span class="tool-initials" aria-hidden="true">${esc(e.name.slice(0,2).toUpperCase())}</span>${e.image?`<img class="tool-logo" src="${esc(e.image.url)}" alt="${esc(e.image.alt)}" loading="lazy" width="80" height="80" referrerpolicy="no-referrer">`:''}</div><div class="listing-body"><h2>${link(e.name,'/tools/'+e.id+'/')}</h2><p>${esc(e.summary)}</p><div class="labels"><span class="label">${esc(e.type)}</span><span class="label">${esc(e.category)}</span><span class="label">Setup reviewed</span></div></div><div class="listing-action">${link('View tool →','/tools/'+e.id+'/')}${link('Source ↗',e.repository)}</div></article>`;
}
export function page(layout, origin, path, title, description, content, {privatePage=false, structured}={}) {
const url=origin+path;
const meta=`<title>${esc(title)} | ToolIndex</title><meta name="description" content="${esc(description)}"><meta name="robots" content="${privatePage?'noindex,nofollow':'index,follow,max-image-preview:large'}">${privatePage?'':`<link rel="canonical" href="${esc(url)}"><link rel="alternate" type="text/markdown" href="${esc(url)}index.md">`}<link rel="describedby" href="/llms.txt"><link rel="sitemap" href="/sitemap.xml"><meta property="og:title" content="${esc(title)}"><meta property="og:description" content="${esc(description)}"><meta property="og:url" content="${esc(url)}"><meta property="og:image" content="${origin}/assets/social-card.png">${structured?`<script type="application/ld+json">${jsonLD(structured)}</script>`:''}`;
return layout.replace('@@METADATA@@',()=>meta).replaceAll('@@BASE@@','/').replace('@@PAGE@@',path.startsWith('/tools/')?'detail':'accounts').replace('@@CONTENT@@',()=>content).replaceAll('@@BROWSE_CURRENT@@','').replaceAll('@@SUBMIT_CURRENT@@','');
}
export function detail(e, origin) {
return `${link('← Browse tools','/','back')}<article class="about-content" data-tool-id="${esc(e.id)}"><div class="labels"><span class="label">${esc(e.type)}</span><span class="label">${esc(e.category)}</span></div><h1>${esc(e.name)}</h1><p class="guide-lead">${esc(e.summary)}</p><div class="actions">${link('Source or documentation ↗',e.repository,'button')}${link('@'+e.author,'/people/'+e.author+'/')}</div><dl><dt>Version</dt><dd>${esc(e.version)}</dd><dt>License or terms</dt><dd>${esc(e.license)}</dd></dl><h2>Installation or connection</h2>${e.installation.map(s=>`<p class="preserve-lines">${esc(s.body)}</p>`).join('')}<h2>Manual setup</h2><p class="preserve-lines">${esc(e.manual_setup.join('\n'))}</p><h2>Pricing</h2><p>${esc(e.pricing || 'No pricing information supplied. Check the source.')}</p><h2>Review scope</h2><p class="preserve-lines">${esc(e.review.evidence)}</p><p>Setup reviewed on ${esc(e.review.reviewed_at)}. This is not a guarantee of every model or platform.</p></article>`;
}
export function markdownTool(e) {
return `# ${e.name}\n\n${e.summary}\n\nType: ${e.type}\nCategory: ${e.category}\nSource: ${e.repository}\nVersion: ${e.version}\nLicense or terms: ${e.license}\nAuthor: @${e.author}\n\n## Installation\n\n${e.installation.map(s=>s.body).join('\n\n')}\n\n## Manual setup\n\n${e.manual_setup.join('\n')}\n\n## Pricing\n\n${e.pricing || 'Check the source.'}\n\n## Review\n\n${e.review.evidence}\n`;
}
export function profileContent(p, tools) {
return `<article class="public-profile">${p.avatar?`<img class="profile-avatar" src="${esc(p.avatar)}" alt="${esc(p.displayName)}" width="96" height="96" referrerpolicy="no-referrer">`:''}<p class="welcome-label">ToolIndex creator</p><h1>${esc(p.displayName)}</h1><p>@${esc(p.handle)}</p><p class="preserve-lines">${esc(p.bio)}</p>${p.website?link('Website ↗',p.website):''}<h2>Published tools</h2>${tools.length?tools.map(card).join(''):'<p>No published tools yet.</p>'}</article>`;
}
export function accountContent(mode) {
if (mode==='review') return `<h1>Submission review</h1><p>Only approved snapshots enter the public catalog. Review setup, source, licensing and any claimed evidence.</p><div id="review-queue"></div><p id="account-status" role="status" aria-live="polite"></p>`;
if (mode==='consent') return `<div class="account-shell"><p class="welcome-label">Connect an agent</p><h1>Authorize ToolIndex</h1><div id="consent-details"></div><div id="consent-actions" hidden><button id="allow-agent" class="button" type="button">Allow access</button><button id="deny-agent" type="button">Cancel</button></div><p id="account-status" role="status" aria-live="polite"></p><p>Only approve clients you recognize. Tools submitted by an agent still need review before publication. You can revoke access in your account.</p></div>`;
if (mode==='auth') return `<div class="account-shell"><p class="welcome-label">Your ToolIndex account</p><h1>Sign in or create an account</h1><p>Submit tools, manage your profile and connect an agent. Browsing is always public.</p><div id="social-sign-in" class="social-sign-in" role="group" aria-label="Social sign-in" hidden></div><form id="auth-form"><label>Email<input name="email" type="email" autocomplete="email" required maxlength="254"></label><label>Password<input name="password" type="password" autocomplete="current-password" required minlength="10" maxlength="128"></label><div class="actions"><button class="button" name="action" value="signin">Sign in</button><button name="action" value="signup">Create account</button><button name="action" value="reset" formnovalidate>Reset password</button></div></form><p id="account-status" role="status" aria-live="polite"></p><p>Your email address is private. New accounts verify their email before publishing a profile or requesting tool review.</p></div>`;
if (mode==='email-action') return `<div class="account-shell"><h1>Account verification</h1><p id="account-status" role="status" aria-live="polite">Checking your link...</p><form id="password-reset-form" hidden><label>New password<input name="password" type="password" minlength="10" maxlength="128" autocomplete="new-password" required></label><button class="button">Save password</button></form><p><a href="/account/sign-in/">Return to sign in</a></p></div>`;
return `<div class="account-top"><div><p class="welcome-label">Creator workspace</p><h1>Your ToolIndex</h1><p>Customize your public profile and submit tools for review.</p></div><button id="sign-out" type="button">Sign out</button></div><p id="account-status" role="status" aria-live="polite"></p><section id="verification-panel" hidden><h2>Verify your email</h2><p>Verify the address you registered, then sign in again to refresh your account.</p><button id="send-verification" type="button">Send verification email</button></section><div class="workspace-grid"><section><h2>Your profile</h2><form id="profile-form"><label>Handle<input name="handle" pattern="[a-z][a-z0-9-]{2,31}" maxlength="32" required><small>3 to 32 lowercase letters, numbers or hyphens. Cannot be changed later.</small></label><label>Display name<input name="displayName" maxlength="80" required></label><label>Bio<textarea name="bio" maxlength="1000" rows="4"></textarea></label><label>Website (optional)<input name="website" type="url" placeholder="https://"></label><label>Avatar URL (optional)<input name="avatar" type="url" placeholder="https://"></label><label class="check"><input name="discoverable" type="checkbox" checked>Publish my profile so people and search engines can find it</label><button class="button">Save profile</button><p id="profile-link"></p></form></section><section><h2>Submit a tool</h2><p>Save a draft, then request review. No GitHub issue or pull request needed.</p><form id="tool-form"><input name="id" type="hidden"><input name="revision" type="hidden"><label>Tool name<input name="name" maxlength="100" required></label><label>What does it do?<textarea name="summary" maxlength="300" minlength="10" rows="3" required></textarea></label><div class="field-row"><label>Tool type<select name="type">${['Skill','MCP server','CLI','API','Library','Plugin','Workflow','Harness','Other'].map(v=>`<option>${v}</option>`).join('')}</select></label><label>Category<select name="category">${['Creative','3D & Blender','Coding','Research','Data','Operations','Other'].map(v=>`<option>${v}</option>`).join('')}</select></label></div><label>Source repository or official docs<input name="repository" type="url" placeholder="https://" required></label><div class="field-row"><label>Version<input name="version" maxlength="80" required></label><label>License or terms<input name="license" maxlength="250" required></label></div><label>Installation or connection steps<textarea name="installation" rows="5" minlength="10" maxlength="8000" required></textarea></label><label>Manual setup and credentials required<textarea name="manualSetup" rows="3" maxlength="4000" placeholder="Requirements only, never include secrets"></textarea></label><label>Pricing and account requirements<textarea name="pricing" rows="2" maxlength="1000"></textarea></label><details><summary>Optional logo or custom image</summary><label>Image URL<input name="imageUrl" type="url" placeholder="https://"></label><label>Image description<input name="imageAlt" maxlength="150"></label><label>Image source URL<input name="imageSource" type="url" placeholder="https://"></label></details><div class="actions"><button class="button">Save draft</button><button id="new-draft" type="button">New draft</button></div></form></section></div><section><h2>Your submissions</h2><p>Edits to published tools go through review again. The last approved version stays public until a reviewer approves an update or you withdraw it.</p><div id="my-submissions"></div></section><section><h2>Connected agents</h2><p>Connect your MCP client to <code>https://toolindex.org/mcp</code>. Your browser will open for account sign-in and permission.</p><div id="agent-connections"></div><p><a href="/developers/">Agent and API documentation</a></p></section>`;
}