Add usage Section to Collections

This commit is contained in:
Jeremiah Snee 2025-09-30 10:42:09 -05:00
parent 629d7134e4
commit 30d42a1911
No known key found for this signature in database
GPG Key ID: 1FF35A0EE683E0C6
2 changed files with 51 additions and 15 deletions

View File

@ -57,6 +57,10 @@
"type": "string", "type": "string",
"description": "Type of the item", "description": "Type of the item",
"enum": ["prompt", "instruction", "chat-mode"] "enum": ["prompt", "instruction", "chat-mode"]
},
"usage": {
"type": "string",
"description": "Optional usage context for the item"
} }
} }
}, },

View File

@ -501,6 +501,9 @@ function generateCollectionReadme(collection, collectionId) {
content += `## Items in this Collection\n\n`; content += `## Items in this Collection\n\n`;
content += `| Title | Type | Description |\n| ----- | ---- | ----------- |\n`; content += `| Title | Type | Description |\n| ----- | ---- | ----------- |\n`;
let collectionUsageHeader = "## Collection Usage\n\n";
let collectionUsageContent = [];
// Sort items based on display.ordering setting // Sort items based on display.ordering setting
const items = [...collection.items]; const items = [...collection.items];
if (collection.display?.ordering === "alpha") { if (collection.display?.ordering === "alpha") {
@ -515,19 +518,48 @@ function generateCollectionReadme(collection, collectionId) {
const filePath = path.join(__dirname, item.path); const filePath = path.join(__dirname, item.path);
const title = extractTitle(filePath); const title = extractTitle(filePath);
const description = extractDescription(filePath) || "No description"; const description = extractDescription(filePath) || "No description";
const typeDisplay = item.kind === "chat-mode" ? "Chat Mode" : const typeDisplay =
item.kind === "instruction" ? "Instruction" : "Prompt"; item.kind === "chat-mode"
? "Chat Mode"
: item.kind === "instruction"
? "Instruction"
: "Prompt";
const link = `../${item.path}`; const link = `../${item.path}`;
// Create install badges for each item // Create install badges for each item
const badges = makeBadges(item.path, item.kind === "instruction" ? "instructions" : const badges = makeBadges(
item.kind === "chat-mode" ? "mode" : "prompt"); item.path,
item.kind === "instruction"
? "instructions"
: item.kind === "chat-mode"
? "mode"
: "prompt",
);
content += `| [${title}](${link})<br />${badges} | ${typeDisplay} | ${description} |\n`; const usageDescription = item.usage
? `${description} [see usage](#${title
.replace(/\s+/g, "-")
.toLowerCase()})`
: description;
content += `| [${title}](${link})<br />${badges} | ${typeDisplay} | ${usageDescription} |\n`;
// Generate Usage section for each collection
if (item.usage && item.usage.trim()) {
collectionUsageContent.push(`### ${title}\n\n${item.usage.trim()}\n\n---\n\n`);
}
} }
// Append the usage section if any items had usage defined
if (collectionUsageContent.length > 0) {
content += `\n${collectionUsageHeader}${collectionUsageContent.join("")}`;
} else if (collection.display?.show_badge) {
content += "\n---\n";
}
// Optional badge note at the end if show_badge is true
if (collection.display?.show_badge) { if (collection.display?.show_badge) {
content += `\n---\n*This collection includes ${items.length} curated items for ${name.toLowerCase()}.*`; content += `*This collection includes ${items.length} curated items for ${name.toLowerCase()}.*`;
} }
return content; return content;