You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5KB

  1. use std::path::Path;
  2. use errors::Result;
  3. use site::Site;
  4. //use crate::console;
  5. pub fn index(
  6. root_dir: &Path,
  7. config_file: &str,
  8. base_url: Option<&str>,
  9. output_dir: &str,
  10. include_drafts: bool,
  11. index_type: &str,
  12. ) -> Result<()> {
  13. let mut site = Site::new(root_dir, config_file)?;
  14. site.set_output_path(output_dir);
  15. // TODO: is base_url even necessary for this command?
  16. if let Some(b) = base_url {
  17. site.set_base_url(b.to_string());
  18. }
  19. if include_drafts {
  20. site.include_drafts();
  21. }
  22. site.load()?;
  23. // TODO: could skipping the theme and/or sass prep end up
  24. // somehow impacting the search indexing? doesn't seem like
  25. // it could, but maybe
  26. #[cfg(feature = "tantivy-indexing")]
  27. {
  28. match index_type {
  29. "elasticlunr" => {
  30. site.build_search_index()?;
  31. }
  32. "tantivy" => {
  33. //if ! Path::new(output_dir).exists() {
  34. // std::fs::create_dir_all(output_dir)?;
  35. //}
  36. let index_dir = Path::new(output_dir).join("tantivy-index");
  37. utils::fs::ensure_directory_exists(&index_dir)?;
  38. let lang = &site.config.default_language;
  39. let library = site.library.read().unwrap(); // unwrap originally in Site::build_search_index, just parroting here, no idea if safe
  40. search::build_tantivy_index(lang, &library, output_dir)?;
  41. }
  42. _ => unreachable!()
  43. }
  44. }
  45. Ok(())
  46. }