diff --git a/skills/citepo/references/frontmatter.md b/skills/citepo/references/frontmatter.md index 4b100a9..ee6485a 100644 --- a/skills/citepo/references/frontmatter.md +++ b/skills/citepo/references/frontmatter.md @@ -38,7 +38,7 @@ The post starts here. | `date` | yes | `YYYY-MM-DD` | Publish date; posts are sorted by it | | `tags` | no | list of text | Tag pages and keywords; reuse existing spellings (`citepo tag list`) | | `authors` | no | list of text | Shown on the post and in structured data | -| `coverImage` | no | image path | Image at the top of the post and in post lists | +| `coverImage` | no | image path | Image at the top of the post and in post lists; 1200x630 works best | | `draft` | no | `true` / `false` | Drafts are never published | | `updated` | no | `YYYY-MM-DD` | Last significant update; sent to search engines as the modified date | | `noindex` | no | `true` / `false` | Keep it out of search results and the sitemap (still in lists, RSS) | @@ -56,6 +56,10 @@ Quote titles and descriptions that contain `:` or start with a special character `citepo image add --post ` copies an image to the right place, compresses it and prints the Markdown to paste. Always write alt text: `![What the image shows](/images/...)`. +Make the cover 1200x630, the size of share cards. Post lists show the whole cover in that +frame, and share cards on social sites crop other ratios. `citepo check` warns when a cover is +much taller or wider. + ## Links Link to other posts by URL, not by file: `[Read more](/hello-world)`, or diff --git a/src/engine/check/index.test.ts b/src/engine/check/index.test.ts index 2c01afc..d7251ec 100644 --- a/src/engine/check/index.test.ts +++ b/src/engine/check/index.test.ts @@ -1,6 +1,7 @@ import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import path from 'node:path' +import sharp from 'sharp' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { frontmatterLine, resolveSourceImage, runCheck, type CheckReport } from './index.js' @@ -123,7 +124,7 @@ describe('runCheck', () => { describe('runCheck image and link edge cases', () => { let dir: string - const write = async (file: string, content: string) => { + const write = async (file: string, content: string | Buffer) => { await mkdir(path.dirname(path.join(dir, file)), { recursive: true }) await writeFile(path.join(dir, file), content) } @@ -158,6 +159,27 @@ describe('runCheck image and link edge cases', () => { ) }) + it('warns when the cover is far from the share-card ratio', async () => { + const png = (width: number, height: number) => + sharp({ create: { width, height, channels: 3, background: '#888' } }) + .png() + .toBuffer() + await write('asset/images/wide.png', await png(1280, 640)) + await write('asset/images/square.png', await png(600, 600)) + await write( + 'content/a.mdx', + post('title: A\ndescription: x\ndate: 2026-01-01\ncoverImage: /images/wide.png'), + ) + await write( + 'content/b.mdx', + post('title: B\ndescription: x\ndate: 2026-01-01\ncoverImage: /images/square.png'), + ) + const report = await runCheck(dir) + expect(report.issues.map((i) => `${i.severity}:${i.rule}:${i.file}:${i.line}`)).toEqual([ + 'warning:cover_aspect:content/b.mdx:5', + ]) + }) + it('reports a single prefixed link as broken, not as a base path', async () => { await write('content/a.mdx', post('title: A\ndescription: x\ndate: 2026-01-01', '[b](/foo/b)')) await write('content/b.mdx', post('title: B\ndescription: x\ndate: 2026-01-01')) diff --git a/src/engine/check/index.ts b/src/engine/check/index.ts index 4d593ad..e6b02a8 100644 --- a/src/engine/check/index.ts +++ b/src/engine/check/index.ts @@ -4,13 +4,17 @@ import path from 'node:path' import { loadBlogConfig, normalizeBasePath, type BlogConfig } from '../config.js' import { detectLang, parseFrontmatter, toEntryId } from '../content.js' import { PostFrontmatterSchema } from '../frontmatter.js' -import { canShrinkSourceImage, MAX_IMAGE_WIDTH } from '../images.js' +import { canShrinkSourceImage, imageAspectRatio, MAX_IMAGE_WIDTH } from '../images.js' import { HOSTED_LIMITS, LIMIT_WARNING_RATIO } from '../limits.js' import { CONTENT_IMAGES_DIR } from '../remark-relative-images.js' import { scanMdxContent } from '../security.js' import { postPathWithoutBase } from '../sitemap.js' import { analyzeMdx, MDX_COMPONENT_NAMES, type MdxReference } from './mdx.js' +/** Covers between 16:10 and 2.2:1 fit the 1.91:1 list and share-card frames closely enough. */ +const COVER_MIN_RATIO = 1.6 +const COVER_MAX_RATIO = 2.2 + /** * `citepo check`: everything that can be verified without building the site. * Each issue names a rule, a file and line, and how to fix it, so both people and @@ -235,10 +239,14 @@ async function checkPost(input: CheckPostInput): Promise const mdxDir = path.dirname(absolutePath) const images = [...analysis.images] // Read the raw values, so images are checked even when other fields are invalid + let coverRef: (typeof images)[number] | undefined for (const key of ['coverImage', 'ogImage'] as const) { const value = parsed.frontmatter[key] - if (typeof value === 'string' && value) - images.push({ url: value, line: frontmatterLine(raw, key) }) + if (typeof value === 'string' && value) { + const ref = { url: value, line: frontmatterLine(raw, key) } + if (key === 'coverImage') coverRef = ref + images.push(ref) + } } for (const image of images) { const target = resolveSourceImage(image.url, mdxDir, assetDir, config.basePath) @@ -283,6 +291,19 @@ async function checkPost(input: CheckPostInput): Promise const size = (await stat(target)).size if (await canShrinkSourceImage(target, size)) largeImages.set(toPosix(path.relative(projectDir, target)), size) + if (image === coverRef) { + const ratio = await imageAspectRatio(target) + if (ratio && (ratio < COVER_MIN_RATIO || ratio > COVER_MAX_RATIO)) { + issues.push({ + rule: 'cover_aspect', + severity: 'warning', + message: `coverImage is ${ratio.toFixed(2)}:1; post lists and share cards use 1.91:1 (1200x630)`, + file, + line: image.line, + hint: 'Lists show the whole cover with blurred edges, and share cards crop it. Use a 1200x630 image, or set ogImage separately.', + }) + } + } } const id = fm?.slug || toEntryId(relative) diff --git a/src/engine/images.ts b/src/engine/images.ts index d8e55cf..5e9a06f 100644 --- a/src/engine/images.ts +++ b/src/engine/images.ts @@ -198,6 +198,18 @@ export async function encodeAsWebp(input: Buffer, ext: string): Promise { + try { + const meta = await sharp(filePath).metadata() + if (!meta.width || !meta.height) return undefined + const rotated = (meta.orientation ?? 1) >= 5 + return rotated ? meta.height / meta.width : meta.width / meta.height + } catch { + return undefined + } +} + export async function canShrinkSourceImage(filePath: string, bytes: number): Promise { if (!isOptimizableImage(filePath) || bytes < SOURCE_MIN_BYTES) return false try { diff --git a/src/theme/wabi/components/PostCard.tsx b/src/theme/wabi/components/PostCard.tsx index b36d7bd..f7ce62c 100644 --- a/src/theme/wabi/components/PostCard.tsx +++ b/src/theme/wabi/components/PostCard.tsx @@ -35,11 +35,19 @@ export default function PostCard({
{coverImage && (
-
+ {/* Share-card ratio (1200x630). The whole cover is shown so titles on it are never + cut off; a blurred copy fills any space left by covers of another ratio. */} +
+ {title}