def test_pages_sort() -> None: """Test i18pages sort correctness.""" plugin = Translator() test_lang = "test" index_page = File("/tmp/theme/index.md", "/tmp", "/tmp", use_directory_urls=False) index_page.url = "lang/theme/" second = File("/tmp/theme/b.md", "/tmp", "/tmp", use_directory_urls=False) second.url = "lang/theme/b/" plugin.i18pages[test_lang].append( second, ) plugin.i18pages[test_lang].append( index_page, ) plugin._sort_translated_files() doc_pages = plugin.i18pages[test_lang].documentation_pages() assert doc_pages[0] == index_page
def get_files(base_dir, config, site): files = [] exclude = ['.*', '/templates'] base = os.path.relpath(base_dir, config['docs_dir']) for source_dir, dirnames, filenames in os.walk(base_dir, followlinks=True): relative_dir = os.path.relpath(source_dir, config['docs_dir']) for dirname in list(dirnames): path = os.path.normpath(os.path.join(relative_dir, dirname)) # Skip any excluded directories if _filter_paths(basename=dirname, path=path, is_dir=True, exclude=exclude): dirnames.remove(dirname) dirnames.sort() for filename in _sort_files(filenames): path = os.path.normpath(os.path.join(relative_dir, filename)) # Skip any excluded files if _filter_paths(basename=filename, path=path, is_dir=False, exclude=exclude): continue f = File(path, config['docs_dir'], config['site_dir'], config['use_directory_urls']) f.dest_path = f.dest_path.replace(base + '/', '') f.abs_dest_path = os.path.normpath( os.path.join(config['site_dir'], f.dest_path)) f.url = f.url.replace(base + '/', '') if f.url == '': # Skip docs/index.md, use the one from root repo continue files.append(f) return (files, {file.src_path: file for file in files})