Generate customizable widget plugins for the prompts.chat feed system
This skill guides creation of widget plugins for prompts.chat. Widgets are injected into prompt feeds to display promotional content, sponsor cards, or custom interactive components.
Widgets support two rendering modes:
PromptCard styling (like coderabbit.ts)book.tsx)Before creating a widget, gather from the user:
| Parameter | Required | Description |
|---|---|---|
| Widget ID | ✅ | Unique identifier (kebab-case, e.g., my-sponsor) |
| Widget Name | ✅ | Display name for the plugin |
| Rendering Mode | ✅ | standard or custom |
| Sponsor Info | ❌ | Name, logo, logoDark, URL (for sponsored widgets) |
Ask the user for the following configuration options:
- id: string (unique, kebab-case)
- name: string (display name)
- slug: string (URL-friendly identifier)
- title: string (card title)
- description: string (card description)
- content: string (prompt content, can be multi-line markdown)
- type: "TEXT" | "STRUCTURED"
- structuredFormat?: "json" | "yaml" (if type is STRUCTURED)
- tags?: string[] (e.g., ["AI", "Development"])
- category?: string (e.g., "Development", "Writing")
- actionUrl?: string (CTA link)
- actionLabel?: string (CTA button text)
- sponsor?: {
name: string
logo: string (path to light mode logo)
logoDark?: string (path to dark mode logo)
url: string (sponsor website)
}
- positioning: {
position: number (0-indexed start position, default: 2)
mode: "once" | "repeat" (default: "once")
repeatEvery?: number (for repeat mode, e.g., 30)
maxCount?: number (max occurrences, default: 1 for once, unlimited for repeat)
}
- shouldInject?: (context) => boolean
Context contains:
- filters.q: search query
- filters.category: category name
- filters.categorySlug: category slug
- filters.tag: tag filter
- filters.sort: sort option
- itemCount: total items in feed
Create file: src/lib/plugins/widgets/{widget-id}.ts
import type { WidgetPlugin } from "./types";
export const {widgetId}Widget: WidgetPlugin = {
id: "{widget-id}",
name: "{Widget Name}",
prompts: [
{
id: "{prompt-id}",
slug: "{prompt-slug}",
title: "{Title}",
description: "{Description}",
content: `{Multi-line content here}`,
type: "TEXT",
// Optional sponsor
sponsor: {
name: "{Sponsor Name}",
logo: "/sponsors/{sponsor}.svg",
logoDark: "/sponsors/{sponsor}-dark.svg",
url: "{sponsor-url}",
},
tags: ["{Tag1}", "{Tag2}"],
category: "{Category}",
actionUrl: "{action-url}",
actionLabel: "{Action Label}",
positioning: {
position: 2,
mode: "repeat",
repeatEvery: 50,
maxCount: 3,
},
shouldInject: (context) => {
const { filters } = context;
// Always show when no filters active
if (!filters?.q && !filters?.category && !filters?.tag) {
return true;
}
// Add custom filter logic here
return false;
},
},
],
};
Create file: src/lib/plugins/widgets/{widget-id}.tsx
import Link from "next/link";
import Image from "next/image";
import { Button } from "@/components/ui/button";
import type { WidgetPlugin } from "./types";
function {WidgetName}Widget() {
return (
<div className="group border rounded-[var(--radius)] overflow-hidden hover:border-foreground/20 transition-colors bg-gradient-to-br from-primary/5 via-background to-primary/10 p-5">
{/* Custom widget content */}
<div className="flex flex-col items-center gap-4">
{/* Image/visual element */}
<div className="relative w-full aspect-video">
<Image
src="/path/to/image.jpg"
alt="{Alt text}"
fill
className="object-cover rounded-lg"
/>
</div>
{/* Content */}
<div className="w-full text-center">
<h3 className="font-semibold text-base mb-1.5">{Title}</h3>
<p className="text-xs text-muted-foreground mb-4">{Description}</p>
<Button asChild size="sm" className="w-full">
<Link href="{action-url}">{Action Label}</Link>
</Button>
</div>
</div>
</div>
);
}
export const {widgetId}Widget: WidgetPlugin = {
id: "{widget-id}",
name: "{Widget Name}",
prompts: [
{
id: "{prompt-id}",
slug: "{prompt-slug}",
title: "{Title}",
description: "{Description}",
content: "",
type: "TEXT",
tags: ["{Tag1}", "{Tag2}"],
category: "{Category}",
actionUrl: "{action-url}",
actionLabel: "{Action Label}",
positioning: {
position: 10,
mode: "repeat",
repeatEvery: 60,
maxCount: 4,
},
shouldInject: () => true,
render: () => <{WidgetName}Widget />,
},
],
};
Edit src/lib/plugins/widgets/index.ts:
import { {widgetId}Widget } from "./{widget-id}";
widgetPlugins array:const widgetPlugins: WidgetPlugin[] = [
coderabbitWidget,
bookWidget,
{widgetId}Widget, // Add new widget
];
If the widget has a sponsor:
public/sponsors/{sponsor}.svgpublic/sponsors/{sponsor}-dark.svg