pub fn find_page(
        &self,
        name: &str,
        languages: &[String],
        custom_pages_dir: Option<&Path>,
    ) -> Option<PageLookupResult> {
        let page_filename = format!("{}.md", name);
        let patch_filename = format!("{}.patch", name);
        let custom_filename = format!("{}.page", name);

        // Get cache dir
        let cache_dir = match Self::get_cache_dir() {
            Ok((cache_dir, _)) => cache_dir.join(TLDR_PAGES_DIR),
            Err(e) => {
                log::error!("Could not get cache directory: {}", e);
                return None;
            }
        };

        let lang_dirs: Vec<String> = languages
            .iter()
            .map(|lang| {
                if lang == "en" {
                    String::from("pages")
                } else {
                    format!("pages.{}", lang)
                }
            })
            .collect();

        // Look up custom page (<name>.page). If it exists, return it directly
        if let Some(config_dir) = custom_pages_dir {
            let custom_page = config_dir.join(custom_filename);
            if custom_page.exists() && custom_page.is_file() {
                return Some(PageLookupResult::with_page(custom_page));
            }
        }

        let patch_path = Self::find_patch(&patch_filename, custom_pages_dir);

        // Try to find a platform specific path next, append custom patch to it.
        if let Some(pf) = self.get_platform_dir() {
            if let Some(page) =
                Self::find_page_for_platform(&page_filename, &cache_dir, pf, &lang_dirs)
            {
                return Some(PageLookupResult::with_page(page).with_optional_patch(patch_path));
            }
        }

        // Did not find platform specific results, fall back to "common"
        Self::find_page_for_platform(&page_filename, &cache_dir, "common", &lang_dirs)
            .map(|page| PageLookupResult::with_page(page).with_optional_patch(patch_path))
    }
/// Search for a page and return the path to it.
Search for a page and return the path to it.
Search for a page and return the path to it .
pub fn find_page(
        &self,
        name: &str,
        languages: &[String],
        custom_pages_dir: Option<&Path>,
    ) -> Option<PageLookupResult> {
        let page_filename = format!("{}.md", name);
        let patch_filename = format!("{}.patch", name);
        let custom_filename = format!("{}.page", name);
        // Get cache dir
        let cache_dir = match Self::get_cache_dir() {
            Ok((cache_dir, _)) => cache_dir.join(TLDR_PAGES_DIR),
            Err(e) => {
                log::error!("Could not get cache directory: {}", e);
                return None;
            }
        };
        let lang_dirs: Vec<String> = languages
            .iter()
            .map(|lang| {
                if lang == "en" {
                    String::from("pages")
                } else {
                    format!("pages.{}", lang)
                }
            })
            .collect();
        // Look up custom page (<name>.page). If it exists, return it directly
        if let Some(config_dir) = custom_pages_dir {
            let custom_page = config_dir.join(custom_filename);
            if custom_page.exists() && custom_page.is_file() {
                return Some(PageLookupResult::with_page(custom_page));
            }
        }
        let patch_path = Self::find_patch(&patch_filename, custom_pages_dir);
        // Try to find a platform specific path next, append custom patch to it.
        if let Some(pf) = self.get_platform_dir() {
            if let Some(page) =
                Self::find_page_for_platform(&page_filename, &cache_dir, pf, &lang_dirs)
            {
                return Some(PageLookupResult::with_page(page).with_optional_patch(patch_path));
            }
        }
        // Did not find platform specific results, fall back to "common"
        Self::find_page_for_platform(&page_filename, &cache_dir, "common", &lang_dirs)
            .map(|page| PageLookupResult::with_page(page).with_optional_patch(patch_path))
    }
pub fn find_page ( & self , name : & str , languages : & [ String ] , custom_pages_dir : Option < & Path > , ) -> Option < PageLookupResult > { let page_filename = format ! ( " " name ) ; let patch_filename = format ! ( " " name ) ; let custom_filename = format ! ( " " name ) ; // Get cache dir let cache_dir = match Self :: get_cache_dir ( ) { Ok ( ( cache_dir , _ ) ) => cache_dir . join ( TLDR_PAGES_DIR ) , Err ( e ) => { log :: error ! ( " " e ) ; return None ; } } ; let lang_dirs : Vec < String > = languages . iter ( ) . map ( | lang | { if lang == " " { String :: from ( " " ) } else { format ! ( " " lang ) } } ) . collect ( ) ; // Look up custom page (<name>.page). If it exists, return it directly if let Some ( config_dir ) = custom_pages_dir { let custom_page = config_dir . join ( custom_filename ) ; if custom_page . exists ( ) && custom_page . is_file ( ) { return Some ( PageLookupResult :: with_page ( custom_page ) ) ; } } let patch_path = Self :: find_patch ( & patch_filename , custom_pages_dir ) ; // Try to find a platform specific path next, append custom patch to it. if let Some ( pf ) = self . get_platform_dir ( ) { if let Some ( page ) = Self :: find_page_for_platform ( & page_filename , & cache_dir , pf , & lang_dirs ) { return Some ( PageLookupResult :: with_page ( page ) . with_optional_patch ( patch_path ) ) ; } } // Did not find platform specific results, fall back to "common" Self :: find_page_for_platform ( & page_filename , & cache_dir , " " , & lang_dirs ) . map ( | page | PageLookupResult :: with_page ( page ) . with_optional_patch ( patch_path ) ) }
Search for a page and return the path to it.
Search for a page and return the path to it .
&self
name
&str
languages
&[String]
custom_pages_dir
Option<&Path>
&self
name
&str
languages
&[String]
custom_pages_dir
Option<&Path>