terminal_velocity/
lib.rs

1pub mod anthropic;
2pub mod config;
3pub mod constants;
4pub mod errors;
5pub mod generator;
6pub mod git;
7pub mod init;
8pub mod markdown;
9pub mod post;
10pub mod serve;
11
12#[cfg(test)]
13pub mod tests {
14    use crate::config::{Author, BuildConfig, Config, ServerConfig};
15    use crate::post::{Post, PostMetadata};
16    use std::fs;
17    use tempfile::TempDir;
18
19    pub fn create_test_config(temp_dir: &TempDir) -> Config {
20        let site_dir = temp_dir.path().to_path_buf();
21        Config {
22            site_dir,
23            base_url: "http://localhost:8000".to_string(),
24            title: "Test Blog".to_string(),
25            description: "Test Description".to_string(),
26            author: Author {
27                name: "Test Author".to_string(),
28                email: "test@example.com".to_string(),
29            },
30            server: ServerConfig {
31                auto_build: true,
32                port: 8000,
33                hot_reload: true,
34            },
35            build: BuildConfig {
36                verbose: false,
37                output_dir: "dist".to_string(),
38                posts_dir: "posts".to_string(),
39                templates_dir: "templates".to_string(),
40                static_dir: "static".to_string(),
41                post_assets_dir: "assets".to_string(),
42            },
43        }
44    }
45
46    pub fn setup_test_site(temp_dir: &TempDir) -> std::io::Result<()> {
47        // Create required directories
48        fs::create_dir(temp_dir.path().join("posts"))?;
49        fs::create_dir(temp_dir.path().join("templates"))?;
50        fs::create_dir_all(temp_dir.path().join("static/css"))?;
51
52        // Create test post with assets
53        let test_post = Post {
54            metadata: PostMetadata {
55                title: "Test Post".to_string(),
56                date: "2024-01-01".to_string(),
57                author: "Test Author".to_string(),
58                tags: vec!["test".to_string()],
59                preview: "Test preview".to_string(),
60                slug: "test-post".to_string(),
61                read_time: 0,
62            },
63            content: String::new(),
64            html_content: String::new(),
65        };
66
67        let config = create_test_config(temp_dir);
68        let post_dir = config.posts_dir().join(&test_post.metadata.slug);
69        let assets_dir = test_post.assets_dir(&config);
70
71        fs::create_dir_all(&post_dir)?;
72        fs::create_dir_all(&assets_dir)?;
73
74        // Create a test asset
75        fs::write(assets_dir.join("test-image.txt"), "test image content")?;
76
77        // Create test post
78        fs::write(
79            post_dir.join("post.md"),
80            r#"---
81title: "Test Post"
82date: 2024-01-01
83author: "Test Author"
84tags: ["test"]
85preview: "Test preview"
86slug: "test-post"
87---
88# Test Content
89Test body
90
91![Test Image](./assets/test-image.txt)"#,
92        )?;
93
94        // Create test templates
95        fs::write(
96            temp_dir.path().join("templates/base.html"),
97            "{% block content %}{% endblock %}",
98        )?;
99        fs::write(
100            temp_dir.path().join("templates/post.html"),
101            "{% extends \"base.html\" %}{% block content %}{{ post.html_content | safe }}{% endblock %}",
102        )?;
103        fs::write(
104            temp_dir.path().join("templates/index.html"),
105            "{% extends \"base.html\" %}{% block content %}{% for post in posts %}{{ post.metadata.title }}{% endfor %}{% endblock %}",
106        )?;
107
108        // Create test static file
109        fs::write(
110            temp_dir.path().join("static/css/style.css"),
111            "body { color: black; }",
112        )?;
113
114        Ok(())
115    }
116}