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
6 changes: 5 additions & 1 deletion skills/citepo/references/frontmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand All @@ -56,6 +56,10 @@ Quote titles and descriptions that contain `:` or start with a special character
`citepo image add <file> --post <slug>` 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
Expand Down
24 changes: 23 additions & 1 deletion src/engine/check/index.test.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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'))
Expand Down
27 changes: 24 additions & 3 deletions src/engine/check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -235,10 +239,14 @@ async function checkPost(input: CheckPostInput): Promise<PostRecord | undefined>
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)
Expand Down Expand Up @@ -283,6 +291,19 @@ async function checkPost(input: CheckPostInput): Promise<PostRecord | undefined>
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)
Expand Down
12 changes: 12 additions & 0 deletions src/engine/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ export async function encodeAsWebp(input: Buffer, ext: string): Promise<Buffer |
}

/** Whether `citepo image optimize` would shrink this source image (reads only the header). */
/** Width divided by height as displayed (EXIF rotation applied); undefined if unreadable. */
export async function imageAspectRatio(filePath: string): Promise<number | undefined> {
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<boolean> {
if (!isOptimizableImage(filePath) || bytes < SOURCE_MIN_BYTES) return false
try {
Expand Down
12 changes: 10 additions & 2 deletions src/theme/wabi/components/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ export default function PostCard({
<article className="flex flex-col sm:flex-row gap-4 sm:gap-6 p-4 rounded-lg border border-transparent hover:border-border/50 hover:bg-muted/30 transition-colors duration-200">
{coverImage && (
<div className="sm:w-48 sm:flex-shrink-0">
<div className="relative aspect-video sm:aspect-[4/3] rounded-md overflow-hidden bg-muted border">
{/* 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. */}
<div className="relative aspect-[1200/630] rounded-md overflow-hidden bg-muted border">
<img
src={coverImage}
alt=""
aria-hidden="true"
className="absolute inset-0 object-cover w-full h-full scale-110 blur-xl opacity-60"
/>
<img
src={coverImage}
alt={title}
className="object-cover w-full h-full group-hover:scale-[1.02] transition-transform duration-200"
className="relative object-contain w-full h-full group-hover:scale-[1.02] transition-transform duration-200"
/>
</div>
</div>
Expand Down
Loading