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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- **Theme Screenshot Skill** — Makes a theme's 1200 by 900 `screenshot.png` from the site's logo, the theme.json palette and an industry line, rendered with Puppeteer. ([#4010](https://github.com/lightspeedwp/.github/issues/4010))
- **Site to Figma Components Skill** — Rebuilds a live site's components, patterns and templates in Figma after the reviewer approves an inventory. ([#3992](https://github.com/lightspeedwp/.github/issues/3992))
- **Site to Design Tokens Skill** — For rebuilds: proposes design tokens from a live site, then creates the Figma variables and a theme.json export once approved. ([#3990](https://github.com/lightspeedwp/.github/issues/3990))
- **Figma to Block Theme Skill** — One skill turns Figma variables into theme.json presets, Figma frames into block patterns, and fills theme.json gaps. ([#3989](https://github.com/lightspeedwp/.github/issues/3989))
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"test:js": "jest --config .jest.config.cjs --coverage --forceExit --detectOpenHandles",
"test:figma-to-block-theme": "jest --config skills/figma-to-block-theme/scripts/jest.config.cjs",
"test:site-to-design-tokens": "jest --config skills/site-to-design-tokens/scripts/jest.config.cjs",
"test:theme-screenshot": "jest --config skills/theme-screenshot/scripts/jest.config.cjs",
"test:site-to-figma-components": "jest --config skills/site-to-figma-components/scripts/jest.config.cjs",
"test:agent-spec-validation": "node .github/scripts/__tests__/validate-agent-specs.test.js",
"test:index-generator": "node .github/scripts/__tests__/generate-agent-index.test.js",
Expand Down
81 changes: 81 additions & 0 deletions skills/theme-screenshot/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
name: theme-screenshot
description: Make a WordPress theme's screenshot.png (1200 by 900) from the site's logo. Use when a block theme has no screenshot, so Appearance > Themes shows a blank card and Theme Check flags it. Finds the logo from a file or a live site (custom logo, header logo, then og:image), takes colours from the theme.json palette with overrides, adds an industry line and the year, and renders the image with Puppeteer in the style of the KWV and Southern Destinations themes.
---

# Theme Screenshot

## Overview

Generated block themes need a `screenshot.png`. This skill makes one in the house style: the site's logo centred on a soft radial gradient in the theme's colours, a thin divider, an industry line in spaced capitals, and "WordPress block theme · 2026" (the current year).

```text
logo (file or live site) + theme.json palette + industry line → HTML → Puppeteer → screenshot.png (1200 x 900)
```

References for the look: `kwv-theme-2026` (dark background, gold accent) and `sd-theme-2026` (light background, brown logo).

## Before you start

The script runs from the `.github` repository checkout and needs its dependencies and a browser:

- Run `npm ci` in the `.github` checkout. Without it `tsx` and Puppeteer are missing.
- If the browser fails to launch, run `npx puppeteer browsers install chrome`. npm 11 blocks Puppeteer's install script, so the browser is not downloaded automatically.

## Workflow

### 1. Gather the inputs

Ask for:

- **The logo.** A file (PNG, JPG, GIF, WebP or SVG; SVG is best), or the live site's URL. From a live site the script looks for the custom logo (`.custom-logo`), then a header image named or labelled "logo", then `og:image`. It reads one public page and one image.
- **The theme's `theme.json`**, for the colours. Without one the script uses black and white, so pass `--base`, `--contrast` and `--accent`.
- **The industry line**, for example "Tour operator" or "Wine & spirits".
- **The year**, if it is not the current one.

### 2. Make the screenshot

```bash
npx tsx ${CLAUDE_SKILL_DIR}/scripts/make-theme-screenshot.ts \
--site https://www.example.com \
--theme-json wp-content/themes/my-theme/theme.json \
--industry "Tour operator" \
--out wp-content/themes/my-theme/screenshot.png
```

Use `--logo logo.svg` instead of `--site` for a file. Other options:

| Option | Does |
| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `--mode light\|dark\|auto` | Light uses the `base` colour. Dark uses `contrast`. `auto` (default) gives a light logo a dark background and a dark logo a light one. |
| `--base`, `--contrast`, `--accent` | Override a palette colour with a hex value. The accent is the divider and, in dark mode, the tagline. |
| `--label` | Replaces "WordPress block theme". |
| `--year` | Replaces the current year. |

The accent is the first of `brand-600`, `brand-500`, `primary-600`, `primary-500`, `cta-600` and `cta-500` that the palette has.

### 3. Look at the image

Open the PNG before handing it over. Check that the logo is sharp and not clipped, the text is readable on the background, and the colours match the theme. If the logo came from `og:image` it may be a photo or a cropped banner: ask for a proper logo file instead. If the logo has little contrast with the background, set `--mode` or the colours.

## Rules

- **Public pages only.** The script reads the one page and image you point it at and nothing else. It refuses anything that is not http or https.
- **Keep the output with the theme** (`screenshot.png` in the theme root, not in a scratch folder), but make test runs in a scratch folder.
- **Never invent a logo.** If none is found, the script stops and asks for a file.
- **A raster logo is never enlarged**, because that blurs it. A small raster logo stays small, so ask for a larger file or an SVG.

## Scripts

TypeScript run with `tsx` (`npx tsx <script> --help`). Tests are in `scripts/__tests__/`: run `npm run test:theme-screenshot` from the repository root.

| Script | Does |
| ---------------------------------- | ----------------------------------------------------------- |
| `scripts/make-theme-screenshot.ts` | Command line, orchestration and the Puppeteer renderer |
| `scripts/lib/logo.ts` | Finds the logo on a live site and loads it from file or URL |
| `scripts/lib/palette.ts` | Reads the theme.json palette and plans the colours |
| `scripts/lib/template.ts` | The HTML for the screenshot and the logo sizing |
| `scripts/lib/colour.ts` | Hex parsing, mixing and luminance |

*Built by 🧱 LightSpeedWP with ☕, 🚀, and open-source spirit!*
[Contributors](https://github.com/lightspeedwp/.github/graphs/contributors)
4 changes: 4 additions & 0 deletions skills/theme-screenshot/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface:
display_name: 'Theme Screenshot'
short_description: "Make a theme screenshot.png from the site's logo"
default_prompt: 'Use $theme-screenshot to make a 1200 by 900 screenshot.png for this theme from the site logo, the theme.json palette and an industry line, then look at the image before handing it over.'
19 changes: 19 additions & 0 deletions skills/theme-screenshot/scripts/__tests__/colour.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BLACK, Rgb, WHITE } from '../lib/colour';

describe('Rgb', () => {
it('parses short and long hex and rejects anything else', () => {
expect(Rgb.parse('#fff')).toEqual(WHITE);
expect(Rgb.parse(' #0a0a0A ')).toEqual(new Rgb(10, 10, 10));
expect(Rgb.parse('red')).toBeUndefined();
expect(Rgb.parse('#12')).toBeUndefined();
expect(Rgb.parse(undefined)).toBeUndefined();
});

it('mixes, measures luminance and writes hex', () => {
expect(BLACK.mix(WHITE, 0.5).toHex()).toBe('#808080');
expect(WHITE.luminance()).toBeCloseTo(1, 5);
expect(BLACK.luminance()).toBe(0);
expect(new Rgb(10, 10, 10).luminance()).toBeLessThan(0.01);
expect(new Rgb(1, 2, 3).toHex()).toBe('#010203');
});
});
99 changes: 99 additions & 0 deletions skills/theme-screenshot/scripts/__tests__/logo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Fetcher, FileReader, LogoLoader, LogoLocator } from '../lib/logo';

const page = (body: string, head = '') => `<html><head>${head}</head><body>${body}</body></html>`;

describe('LogoLocator', () => {
const locator = new LogoLocator();
const url = 'https://example.com/shop/';

it('prefers the custom logo, then the header logo, then og:image', () => {
const html = page(
`<header><img class="x" alt="Brand logo" src="/header.png"></header>
<img src='/other.png'><img class="custom-logo wp-image-5" src="/wp-content/logo.svg">`,
'<meta property="og:image" content="https://cdn.example.com/og.jpg">'
);
expect(locator.find(html, url)).toEqual({
url: 'https://example.com/wp-content/logo.svg',
source: 'custom-logo',
});
expect(
locator.find(page('<header><img alt="Brand logo" src="header.png"></header>'), url)
).toEqual({
url: 'https://example.com/shop/header.png',
source: 'header-logo',
});
expect(
locator.find(
page('<p>hi</p>', '<meta property="og:image" content="/og.jpg?a=1&amp;b=2">'),
url
)
).toEqual({ url: 'https://example.com/og.jpg?a=1&b=2', source: 'og:image' });
});

it('skips header images that are not logos and unusable URLs', () => {
expect(
locator.find(page('<header><img src="/hero.jpg" alt="Hero"></header>'), url)
).toBeUndefined();
expect(
locator.find(page('<img class="custom-logo" src="data:image/png;base64,AAAA">'), url)
).toBeUndefined();
expect(locator.find(page('<img class="custom-logo" src="http://[bad">'), url)).toBeUndefined();
expect(locator.find(page('<img class="custom-logo">'), url)).toBeUndefined();
});
});

describe('LogoLoader', () => {
const files: FileReader = { read: jest.fn(() => Buffer.from('FILE')) };
const fetcher = (html: string, type = 'image/png'): Fetcher => ({
text: jest.fn(async () => html),
bytes: jest.fn(async () => ({ data: Buffer.from('IMG'), type })),
});

it('loads a logo file as a data URI by its extension', async () => {
const loader = new LogoLoader(fetcher(''), files);
const logo = await loader.fromFile('logo.SVG');
expect(logo).toEqual({
dataUri: `data:image/svg+xml;base64,${Buffer.from('FILE').toString('base64')}`,
source: 'file',
origin: 'logo.SVG',
});
await expect(loader.fromFile('logo.bmp')).rejects.toThrow('must be PNG, JPG');
});

it('finds and downloads a logo from a live site', async () => {
const f = fetcher(page('<img class="custom-logo" src="/logo.webp">'));
const logo = await new LogoLoader(f, files).fromSite('https://example.com');
expect(logo.dataUri.startsWith('data:image/webp;base64,')).toBe(true);
expect(logo).toMatchObject({ source: 'custom-logo', origin: 'https://example.com/logo.webp' });
expect(f.bytes).toHaveBeenCalledWith('https://example.com/logo.webp');
});

it('uses the response type when the URL has no known extension', async () => {
const f = fetcher(
page('<img class="custom-logo" src="/logo?id=3">'),
'image/png; charset=binary'
);
const logo = await new LogoLoader(f, files).fromSite('https://example.com');
expect(logo.dataUri.startsWith('data:image/png;base64,')).toBe(true);
});

it('refuses non-http sites, missing logos and non-images', async () => {
await expect(new LogoLoader(fetcher(''), files).fromSite('file:///etc/passwd')).rejects.toThrow(
'http or https'
);
await expect(
new LogoLoader(fetcher(page('<p>x</p>')), files).fromSite('https://example.com')
).rejects.toThrow('No logo found');
await expect(
new LogoLoader(
fetcher(page('<img class="custom-logo" src="/x">'), 'text/html'),
files
).fromSite('https://example.com')
).rejects.toThrow('is not an image');
await expect(
new LogoLoader(fetcher(page('<img class="custom-logo" src="/x">'), ''), files).fromSite(
'https://example.com'
)
).rejects.toThrow('unknown type');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { Fetcher, FileReader, LogoLoader } from '../lib/logo';
import {
CliDeps,
runScreenshotCli,
ScreenshotRenderer,
ThemeScreenshotMaker,
} from '../make-theme-screenshot';

const themeJson = JSON.stringify({
settings: {
color: {
palette: [
{ slug: 'base', color: '#faf7f2' },
{ slug: 'brand-600', color: '#8d621f' },
],
},
},
});

function setup(luminance = 0.2) {
const files: FileReader = {
read: jest.fn((path: string) => Buffer.from(path.endsWith('.json') ? themeJson : 'LOGO')),
};
const fetcher: Fetcher = {
text: jest.fn(async () => '<img class="custom-logo" src="/logo.png">'),
bytes: jest.fn(async () => ({ data: Buffer.from('IMG'), type: 'image/png' })),
};
const renderer: ScreenshotRenderer = {
inspect: jest.fn(async () => ({ width: 300, height: 100, luminance })),
render: jest.fn(async () => Buffer.from('PNG')),
close: jest.fn(async () => undefined),
};
const maker = new ThemeScreenshotMaker(
new LogoLoader(fetcher, files),
files,
renderer,
undefined,
() => new Date('2026-11-09T00:00:00Z')
);
return { files, fetcher, renderer, maker };
}

describe('ThemeScreenshotMaker', () => {
it('renders a light screenshot from a logo file and the theme palette', async () => {
const { maker, renderer } = setup();
const result = await maker.make({
logo: 'logo.svg',
themeJson: 'theme.json',
industry: 'Tour operator',
});
expect(result).toMatchObject({ mode: 'light', logo: { source: 'file' } });
expect(result.png.toString()).toBe('PNG');
const [html, width, height] = (renderer.render as jest.Mock).mock.calls[0];
expect([width, height]).toEqual([1200, 900]);
expect(html).toContain('Tour operator');
expect(html).toContain('WordPress block theme &middot; 2026');
expect(html).toContain('#8d621f');
expect(html).toContain('width: 560px; height: 187px');
});

it('picks dark for a light logo, finds the logo on a site and honours year, label and mode', async () => {
const { maker, renderer } = setup(0.9);
const result = await maker.make({
site: 'https://example.com',
industry: 'Wine',
year: 2030,
label: 'Block theme',
});
expect(result.mode).toBe('dark');
expect(result.logo.source).toBe('custom-logo');
expect((renderer.render as jest.Mock).mock.calls[0][0]).toContain('Block theme &middot; 2030');
const forced = await maker.make({
site: 'https://example.com',
industry: 'Wine',
mode: 'light',
});
expect(forced.mode).toBe('light');
});

it('needs a logo file or a site', async () => {
await expect(setup().maker.make({ industry: 'x' })).rejects.toThrow('Pass --logo');
});
});

describe('runScreenshotCli', () => {
function run(argv: string[], luminance = 0.2) {
const { maker, renderer } = setup(luminance);
const written: Record<string, Buffer> = {};
const out: string[] = [];
const err: string[] = [];
const deps: CliDeps = {
createMaker: () => ({ maker, close: () => renderer.close() }),
writeFile: (path, data) => {
written[path] = data;
},
stdout: (t) => out.push(t),
stderr: (t) => err.push(t),
};
return runScreenshotCli(argv, deps).then((code) => ({ code, written, out, err, renderer }));
}

it('writes the screenshot and closes the browser', async () => {
const r = await run([
'--logo',
'logo.png',
'--theme-json',
'theme.json',
'--industry',
'Wine',
'--out',
'shot.png',
'--year',
'2027',
'--label',
'Theme',
'--mode',
'dark',
'--base',
'#fff',
'--contrast',
'#000',
'--accent',
'#b08d3c',
]);
expect(r.code).toBe(0);
expect(r.written['shot.png'].toString()).toBe('PNG');
expect(r.out.join('')).toContain('Wrote shot.png (1200x900, dark mode)');
expect(r.renderer.close).toHaveBeenCalled();
});

it('defaults the output path and prints help', async () => {
const r = await run(['--site', 'https://example.com', '--industry', 'Wine']);
expect(r.written['screenshot.png']).toBeDefined();
const help = await run(['-h']);
expect(help.code).toBe(0);
expect(help.out.join('')).toContain('Usage: make-theme-screenshot');
});

it.each([
[[], 'Pass --industry'],
[['--industry', 'x'], 'Pass --logo'],
[['--industry'], '--industry needs a value'],
[['--nope'], 'Unknown option --nope'],
[['--industry', 'x', '--year', '99'], '--year takes a four digit year'],
[['--industry', 'x', '--mode', 'blue'], '--mode takes light, dark or auto'],
[['--industry', 'x', '--accent', 'gold'], 'is not a hex colour'],
[['--industry', 'x', '--logo', 'logo.bmp'], 'must be PNG'],
])('fails cleanly for %j', async (argv, message) => {
const r = await run(argv as string[]);
expect(r.code).toBe(1);
expect(r.err.join('')).toContain(message);
});
});
Loading
Loading