use mdstore::config::IdStrategy;
use mdstore::{CreateOptions, Filters, TypeConfig, TypeFeatures};
use std::collections::HashMap;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let base = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/output/slug_docs");
if base.exists() {
tokio::fs::remove_dir_all(&base).await?;
}
let type_dir = base.join("docs");
let config = TypeConfig {
name: "Doc".to_string(),
identifier: IdStrategy::Slug,
features: TypeFeatures::default(),
statuses: Vec::new(),
default_status: None,
priority_levels: None,
custom_fields: Vec::new(),
};
let doc1 = mdstore::create(
&type_dir,
&config,
CreateOptions {
title: "Getting Started".to_string(),
body: "Welcome to the project!\n\n## Installation\n\nRun `cargo add mdstore`."
.to_string(),
id: None,
status: None,
priority: None,
tags: None,
projects: None,
custom_fields: HashMap::new(),
comment: None,
},
)
.await?;
println!("Created: {} (id: {})", doc1.title, doc1.id);
let doc2 = mdstore::create(
&type_dir,
&config,
CreateOptions {
title: "API Reference".to_string(),
body: "Full API documentation for mdstore.".to_string(),
id: None,
status: None,
priority: None,
tags: None,
projects: None,
custom_fields: HashMap::new(),
comment: None,
},
)
.await?;
println!("Created: {} (id: {})", doc2.title, doc2.id);
let doc3 = mdstore::create(
&type_dir,
&config,
CreateOptions {
title: "FAQ".to_string(),
body: "Frequently asked questions.".to_string(),
id: Some("faq".to_string()),
status: None,
priority: None,
tags: None,
projects: None,
custom_fields: HashMap::new(),
comment: None,
},
)
.await?;
println!("Created: {} (id: {})", doc3.title, doc3.id);
let all_docs = mdstore::list(&type_dir, Filters::default()).await?;
println!("\nAll documents:");
for doc in &all_docs {
println!(" /{} - {}", doc.id, doc.title);
}
let fetched = mdstore::get(&type_dir, "getting-started").await?;
println!(
"\nFetched doc:\n Title: {}\n Body: {}",
fetched.title, fetched.body
);
let file_path = type_dir.join("getting-started.md");
let raw = tokio::fs::read_to_string(&file_path).await?;
println!("\nRaw file content:\n{raw}");
Ok(())
}