# Blog

## Objective

Publish articles from inside the app to public pages with authors and categories.

A blog with authored posts, categories, scheduling, and public article and index pages.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Scope this honestly. The minimum coherent version is a post with a title, body, author, category, publish state, and a public page at a stable URL, plus an index and a feed. Defer multi-language content, per-post custom layouts, and a general page builder rather than half-building them.
2. Do not build a new editor. Extend the app's existing Rich Text Editor or Markdown Editor with whatever a post needs, and inherit its autosave, unsaved-change warning, and undo instead of reinventing them.
3. Reuse the app's existing Draft and Publish States and Scheduled Publishing rather than adding a second publish workflow for posts. Reuse SEO Setup for titles, descriptions, and social previews.
4. Give every post a permanent identifier separate from its slug, and keep old slugs redirecting so a link shared anywhere keeps working after an edit.
5. Do not render the full body of every post on the index page. Store or derive an excerpt, and paginate, or the index gets slower with every article published.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Two posts can generate the same slug, and an editor will change a slug after the post has been shared. Enforce uniqueness, and keep every previous slug redirecting to the current one permanently.
- Unpublishing a post that other sites already link to must not return a bare error page. Decide deliberately between a gone response and a redirect to the index, and say which the app does.
- A post scheduled for nine in the morning must appear at nine in a defined time zone. Store the scheduled moment absolutely, show the author which zone they are scheduling in, and confirm the resulting local date.
- Very long posts blow out the index and the feed. Use excerpts on listings, paginate the index, and cap how much content the feed carries per item.
- Deleting an author or a category that live posts reference must not leave broken public pages. Block the deletion, or require a reassignment, before anything is removed.
- Comments, if enabled, are public user-generated content and need moderation, spam handling, and a way to report abuse before the blog is public.
- Images in posts need alt text and reserved dimensions, so article pages do not reflow as the reader scrolls.
- Embeds from third parties inside a post must degrade to a visible link when the provider is blocked or down, not leave a hole in the article.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Authors can write, save, schedule, publish, and unpublish a post from inside the app.
- [ ] Every post has a public page at a stable URL, and previous slugs redirect to the current one.
- [ ] Index and category pages are paginated and render excerpts, not full bodies.
- [ ] Scheduled posts appear at the intended local time in the stated time zone.
- [ ] Authors and categories referenced by live posts cannot be deleted without reassignment.
- [ ] Posts use the app's existing editor, publish states, and SEO fields rather than parallel systems.
- [ ] A feed is available and bounded in size per item.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
