diff --git a/doctreecmd/src/main.rs b/doctreecmd/src/main.rs index 3107e1d..b9cd3a9 100644 --- a/doctreecmd/src/main.rs +++ b/doctreecmd/src/main.rs @@ -72,7 +72,12 @@ fn main() -> Result<()> { .subcommand( SubCommand::with_name("export_to_ipfs") .about("Export a collection to IPFS") - .arg(Arg::with_name("collection").required(true).help("Name of the collection")) + .arg(Arg::with_name("collection") + .short("c".chars().next().unwrap()) + .long("collection") + .takes_value(true) + .required(false) + .help("Name of the collection (export all if not specified)")) .arg(Arg::with_name("output").required(true).help("Output directory for IPFS export")) .arg(Arg::with_name("doctree").long("doctree").takes_value(true).help("Name of the doctree (default: 'default')")), ) @@ -350,13 +355,13 @@ fn main() -> Result<()> { doctree.delete_collection(collection)?; println!("Collection '{}' deleted successfully", collection); } else if let Some(matches) = matches.subcommand_matches("export_to_ipfs") { - let collection_name = matches.value_of("collection").unwrap(); - let output_path = matches.value_of("output").unwrap(); + let output_path_str = matches.value_of("output").unwrap(); + let output_path = Path::new(output_path_str); let doctree_name = matches.value_of("doctree").unwrap_or("default"); + let collection_name_opt = matches.value_of("collection"); if debug_mode { - println!("DEBUG: Exporting collection '{}' from doctree '{}' to IPFS output path '{}'", - collection_name, doctree_name, output_path); + println!("DEBUG: Handling export_to_ipfs command."); } // Create a storage with the specified doctree name @@ -377,14 +382,36 @@ fn main() -> Result<()> { // Load collections from Redis doctree.load_collections_from_redis()?; - // Get the collection - let collection = doctree.get_collection(collection_name)?; - - // Call the synchronous export_collection_to_ipfs_sync function from the doctree crate - let output_path = Path::new(output_path); - doctree.export_collection_to_ipfs(collection_name, output_path)?; - - println!("Successfully exported collection '{}' to IPFS and generated metadata CSV at {:?}.", collection_name, output_path.join(format!("{}.csv", collection_name))); + match collection_name_opt { + Some(collection_name) => { + // Export a specific collection + if debug_mode { + println!("DEBUG: Exporting specific collection '{}'", collection_name); + } + doctree.export_collection_to_ipfs(collection_name, output_path)?; + println!("Successfully exported collection '{}' to IPFS and generated metadata CSV at {:?}.", collection_name, output_path.join(format!("{}.csv", collection_name))); + } + None => { + // Export all collections + if debug_mode { + println!("DEBUG: Exporting all collections."); + } + let collections = doctree.list_collections(); + if collections.is_empty() { + println!("No collections found to export."); + } else { + println!("Exporting the following collections:"); + for collection_name in collections { + println!("- {}", collection_name); + if let Err(e) = doctree.export_collection_to_ipfs(&collection_name, output_path) { + eprintln!("Error exporting collection '{}': {}", collection_name, e); + } else { + println!("Successfully exported collection '{}' to IPFS and generated metadata CSV at {:?}.", collection_name, output_path.join(format!("{}.csv", collection_name))); + } + } + } + } + } } else if let Some(matches) = matches.subcommand_matches("reset") { let doctree_name = matches.value_of("doctree").unwrap_or("default"); diff --git a/examples/doctreenew/sites/demo1/collection.hjson b/examples/doctreenew/sites/demo1/collection.hjson new file mode 100644 index 0000000..e5c842c --- /dev/null +++ b/examples/doctreenew/sites/demo1/collection.hjson @@ -0,0 +1,20 @@ +[ + { + name: docs_hero + #existing docusaurus site can be used as collection as long as no duplicates + url: https://git.ourworld.tf/tfgrid/docs_tfgrid4/src/branch/main/aibox/docs + description: Documentation for the ThreeFold Hero project. + } + + { + name: biz + url: https://git.ourworld.tf/tfgrid/docs_tfgrid4/src/branch/main/aibox/collectios/aaa + description: Business documentation. + } + + { + name: products + url: https://git.ourworld.tf/tfgrid/docs_tfgrid4/src/branch/main/aibox/collectios/vvv + description: Information about ThreeFold products. + } +] diff --git a/examples/doctreenew/sites/demo1/footer.hjson b/examples/doctreenew/sites/demo1/footer.hjson new file mode 100644 index 0000000..52d0553 --- /dev/null +++ b/examples/doctreenew/sites/demo1/footer.hjson @@ -0,0 +1,33 @@ +# Footer configuration for the site + +title: "Explore More" + +sections: [ + { + title: "Pages" + links: [ + { label: "Home", href: "/" } + { label: "About Us", href: "/about" } + { label: "Contact", href: "/contact" } + { label: "Blog", href: "/blog" } + ] + } + + { + title: "Resources" + links: [ + { label: "Docs", href: "/docs" } + { label: "API", href: "/api" } + ] + } + + { + title: "Social" + links: [ + { label: "GitHub", href: "https://github.com/yourproject" } + { label: "Twitter", href: "https://twitter.com/yourhandle" } + ] + } +] + +copyright: "© 2025 YourSite. All rights reserved." diff --git a/examples/doctreenew/sites/demo1/header.hjson b/examples/doctreenew/sites/demo1/header.hjson new file mode 100644 index 0000000..957d898 --- /dev/null +++ b/examples/doctreenew/sites/demo1/header.hjson @@ -0,0 +1,32 @@ +# Site Branding +logo: + src: /img/logo.svg + alt: Site Logo + +# Site Title +title: ThreeFold Hero + +# Navigation Menu +menu: [ + { + label: Home + link: / + } + { + label: Docs + link: /docs/ + } + { + label: About + link: /about/ + } +] + +# Login Button +login: + visible: true + label: Login + link: /login/ + + + \ No newline at end of file diff --git a/examples/doctreenew/sites/demo1/main.hjson b/examples/doctreenew/sites/demo1/main.hjson new file mode 100644 index 0000000..39358d5 --- /dev/null +++ b/examples/doctreenew/sites/demo1/main.hjson @@ -0,0 +1,14 @@ +# Site Main Info +title: ThreeFold Hero Docs +tagline: Your Personal Hero +favicon: img/favicon.png +url: https://threefold.info + +# SEO / Social Metadata +metadata: + title: ThreeFold Hero Docs + description: ThreeFold Hero - Your Personal Hero + image: https://threefold.info/herodocs/img/tf_graph.png + +# Copyright Notice +copyright: ThreeFold diff --git a/examples/doctreenew/sites/demo1/pages.hjson b/examples/doctreenew/sites/demo1/pages.hjson new file mode 100644 index 0000000..7502009 --- /dev/null +++ b/examples/doctreenew/sites/demo1/pages.hjson @@ -0,0 +1,33 @@ +[ + { + name: home + title: Home Page + description: This is the main landing page. + navPath: / + collection: acollection + } + + { + name: about + title: About Us + navPath: /about + collection: acollection + } + + { + name: docs + title: Documentation + navPath: /sub/docs + collection: docs_hero + } + + { + name: hidden-page + title: Hidden Page + description: This page is not shown in navigation. + hidden: true + navPath: /cantsee + collection: acollection + } + ] + \ No newline at end of file