Files
AllinSSL/frontend/.kiro/specs/vite-html-to-php-plugin/requirements.md
2026-01-13 17:47:39 +08:00

4.8 KiB

Requirements Document

Introduction

This feature involves creating a Vite plugin that converts standard HTML files into PHP template format. The plugin should execute after the build process is complete to perform secondary transformations on the generated HTML files. The target PHP template format follows a specific structure with blocks for different content sections (title, keywords, description, CSS links, main content, and scripts).

Requirements

Requirement 1

User Story: As a developer, I want to automatically convert HTML files to PHP template format during the build process, so that I can integrate static HTML builds with PHP-based template systems.

Acceptance Criteria

  1. WHEN the Vite build process completes THEN the plugin SHALL automatically process HTML files in the output directory
  2. WHEN processing HTML files THEN the plugin SHALL extract content from specific HTML elements and place them in corresponding PHP template blocks
  3. WHEN the plugin runs THEN it SHALL execute as a post-build hook to ensure all HTML files are fully generated before processing

Requirement 2

User Story: As a developer, I want the plugin to extract and organize different types of content from HTML files, so that the resulting PHP template has properly structured blocks.

Acceptance Criteria

  1. WHEN processing an HTML file THEN the plugin SHALL extract the title element content and place it in a {block name="title"} block
  2. WHEN processing meta tags THEN the plugin SHALL extract keywords meta content and place it in a {block name="keywords"} block
  3. WHEN processing meta tags THEN the plugin SHALL extract description meta content and place it in a {block name="description"} block
  4. WHEN processing link elements THEN the plugin SHALL extract stylesheet links and place them in a {block name="csslink"} block
  5. WHEN processing script elements THEN the plugin SHALL extract JavaScript content (both inline and external) and place it in a {block name="script"} block
  6. WHEN processing the body element THEN the plugin SHALL extract all body content and place it in a {block name="main"} block

Requirement 3

User Story: As a developer, I want the plugin to handle different types of script and link elements correctly, so that all assets are properly extracted and organized.

Acceptance Criteria

  1. WHEN encountering script elements with type="text/javascript" THEN the plugin SHALL extract and include them in the script block
  2. WHEN encountering script elements with type="module" THEN the plugin SHALL extract and include them in the script block
  3. WHEN encountering link elements with rel="stylesheet" THEN the plugin SHALL extract and include them in the csslink block
  4. WHEN processing script or link elements THEN the plugin SHALL preserve all attributes and content exactly as they appear in the original HTML

Requirement 4

User Story: As a developer, I want the generated PHP template to follow a consistent structure, so that it integrates seamlessly with existing PHP template systems.

Acceptance Criteria

  1. WHEN generating the PHP template THEN the plugin SHALL start with the extend directive {extend name="main/newMain"/}
  2. WHEN generating blocks THEN the plugin SHALL use the exact block syntax {block name="blockname"}content{/block}
  3. WHEN generating the template THEN the plugin SHALL include HTML comments to identify each section
  4. WHEN generating the template THEN the plugin SHALL end with the footer block {block name="footer2"}{/block}
  5. WHEN no content exists for a specific block THEN the plugin SHALL still create the block structure but leave it empty

Requirement 5

User Story: As a developer, I want the plugin to be configurable, so that I can customize its behavior for different projects.

Acceptance Criteria

  1. WHEN initializing the plugin THEN it SHALL accept configuration options for input/output directories
  2. WHEN configured THEN the plugin SHALL allow specifying which HTML files to process (via glob patterns)
  3. WHEN configured THEN the plugin SHALL allow customizing the PHP template structure and block names
  4. WHEN no configuration is provided THEN the plugin SHALL use sensible defaults for all options

Requirement 6

User Story: As a developer, I want the plugin to handle errors gracefully, so that build failures are informative and recoverable.

Acceptance Criteria

  1. WHEN encountering malformed HTML THEN the plugin SHALL log a warning and continue processing other files
  2. WHEN file system operations fail THEN the plugin SHALL throw descriptive errors with file paths and operation details
  3. WHEN HTML parsing fails THEN the plugin SHALL provide clear error messages indicating the problematic file and location
  4. WHEN the plugin encounters unexpected content THEN it SHALL handle it gracefully without breaking the build process