# Pages Foundation Library

Page generation and template system for Rustelo web applications built with Leptos.

## Quick Start

### Basic Page Usage
```rust
use pages::{
    HomePage, AboutPage, ContactPage,
    content::{ContentIndexPage, ContentCategoryPage},
};

#[component]
fn App() -> impl IntoView {
    view! {
        <Router>
            <Routes>
                <Route path="/" view=HomePage />
                <Route path="/about" view=AboutPage />
                <Route path="/contact" view=ContactPage />
                <Route path="/blog" view=|| ContentIndexPage { content_type: "blog".to_string() } />
                <Route path="/blog/:category" view=ContentCategoryPage />
            </Routes>
        </Router>
    }
}
```

### Page Generation System
```rust
use pages::{PageGenerator, PageTemplate, PageConfig};

// Generate static pages from configuration
let generator = PageGenerator::new()
    .content_path("content/")
    .output_path("generated/")
    .template(PageTemplate::Blog)
    .build();

generator.generate_all().await?;
```

### Custom Page Templates
```rust
use pages::{PageBuilder, TemplateConfig};

#[component]
fn CustomBlogPage(
    #[prop(into)] title: String,
    #[prop(into)] content: String,
) -> impl IntoView {
    let page_config = PageConfig::builder()
        .title(title.clone())
        .description("Custom blog page")
        .template("blog")
        .build();
        
    PageBuilder::new(page_config)
        .with_content(content)
        .with_sidebar(BlogSidebar::new())
        .build()
}
```

## Usage Patterns

### 1. Pre-built Pages (Simplest)
Use foundation page components directly:
```rust
use pages::{HomePage, AboutPage};

// Ready-to-use page components
view! {
    <HomePage />
    <AboutPage />  
}
```

### 2. Generated Pages
Generate pages from content configuration:
```rust
use pages::{generate_pages, PageGeneratorConfig};

let config = PageGeneratorConfig::builder()
    .content_types(vec!["blog", "docs", "portfolio"])
    .languages(vec!["en", "es"]) 
    .templates_path("templates/")
    .build();

generate_pages(config).await?;
```

### 3. Custom Page Templates
Create custom page layouts:
```rust
use pages::{PageTemplate, create_page_from_template};

let blog_template = PageTemplate::new()
    .with_layout("blog-layout")
    .with_sidebar(true)
    .with_comments(true);

let page = create_page_from_template(blog_template, content).await?;
```

### 4. Content-Driven Pages
Pages generated from markdown and configuration:
```rust
use pages::{ContentPage, MarkdownProcessor};

// Automatically generate pages from markdown files
let processor = MarkdownProcessor::new()
    .content_dir("content/blog/")
    .template("blog-post")
    .enable_frontmatter(true);

let pages = processor.process_all().await?;
```

## Available Pages

### Content Pages
- `ContentIndexPage` - Content listing and index
- `ContentCategoryPage` - Category-based content filtering
- `PostViewerPage` - Individual post/article display

### Static Pages  
- `HomePage` - Main landing page
- `AboutPage` - About/company information
- `ContactPage` - Contact information and forms
- `LegalPage` - Legal documents and terms
- `PrivacyPage` - Privacy policy
- `NotFoundPage` - 404 error page

### User Pages
- `UserPage` - User profile and dashboard

### Admin Pages
- `AdminDashboardPage` - Admin control panel
- `AdminContentPage` - Content management
- `AdminUserPage` - User management
- `AdminRolePage` - Role and permissions

### Utility Pages
- `ExternalLinkPage` - External link redirects

## Page Generation System

### Content-Based Generation
```rust
use pages::{ContentPageGenerator, PageGenerationConfig};

let config = PageGenerationConfig {
    content_path: "content/".to_string(),
    template_path: "templates/".to_string(),
    output_path: "generated/".to_string(),
    languages: vec!["en".to_string(), "es".to_string()],
    content_types: vec!["blog".to_string(), "docs".to_string()],
};

ContentPageGenerator::new(config)
    .generate_all()
    .await?;
```

### Template System
```rust
use pages::{TemplateEngine, HandlebarsTemplate};

let template_engine = TemplateEngine::new()
    .register_template("blog", HandlebarsTemplate::from_file("blog.hbs")?)
    .register_template("page", HandlebarsTemplate::from_file("page.hbs")?)
    .register_helpers(custom_helpers());

let rendered = template_engine.render("blog", &context)?;
```

## Documentation

- [📚 Usage Patterns](docs/USAGE_PATTERNS.md) - Detailed usage examples
- [📄 Page System Guide](docs/PAGE_SYSTEM_GUIDE.md) - Complete page system
- [🎨 Template Guide](docs/TEMPLATE_GUIDE.md) - Template customization  
- [📝 Content Guide](docs/CONTENT_GUIDE.md) - Content processing
- [🔧 Generation Guide](docs/GENERATION_GUIDE.md) - Page generation system

## Examples

- [📁 examples/](examples/) - Complete usage examples
- [🏠 Basic Pages](examples/basic_pages.rs) - Simple page usage
- [📝 Blog System](examples/blog_system.rs) - Blog-style pages
- [🌐 Multi-language Pages](examples/multilang_pages.rs) - I18n support
- [🎨 Custom Templates](examples/custom_templates.rs) - Template customization

## Features

- `ssr` - Server-side rendering support
- `client` - Client-side hydration
- `generation` - Static page generation
- `templates` - Template system support
- `i18n` - Internationalization support

## Installation

Add to your `Cargo.toml`:
```toml
[dependencies]
pages = { path = "path/to/rustelo/crates/foundation/crates/pages" }

# Enable features as needed
pages = { path = "...", features = ["ssr", "generation", "i18n"] }
```
