def get_content(items, in_ext): """ Create a tree of files for processing. Inputs: items: [list[dict(),...] A list of dict items, each dict entry must contain the 'root_dir' and 'content' fields that are passed to the doc_import function. in_ext[tuple]: Set of extensions to be converted (e.g., ('.md', )). out_ext[str]: The extension of rendered result (e.g., '.html'). """ if not isinstance(items, list) or any(not isinstance(x, dict) for x in items): LOG.error( 'The supplied items must be a list of dict items, each with a "root_dir" and ' 'optionally a "content" entry.') return None roots = set() nodes = dict() for root, filename, external in get_files(items, in_ext): roots.add(root) key = filename.replace(root, '').strip('/') parts = key.split('/') # Create directory nodes if they don't exist for i in range(1, len(parts)): dir_key = os.path.join(*parts[:i]) if dir_key not in nodes: nodes[dir_key] = pages.Directory(dir_key, external=external, source=os.path.join( root, dir_key)) # Create the file node, if it doesn't already exist. This enforces that the first # item in the supplied content lists is the page that is rendered. if key not in nodes: nodes[key] = create_file_page(key, filename, in_ext) nodes[key].external = external # Update the project files for root in roots: if mooseutils.is_git_repo(root): MooseDocs.PROJECT_FILES.update( mooseutils.git_ls_files(mooseutils.git_root_dir(root))) else: MooseDocs.PROJECT_FILES.update(mooseutils.list_files(root)) return list(nodes.values())
def get_content(items, in_ext): """ Create a tree of files for processing. Inputs: items: [list[dict(),...] A list of dict items, each dict entry must contain the 'root_dir' and 'content' fields that are passed to the doc_import function. in_ext[tuple]: Set of extensions to be converted (e.g., ('.md', )). out_ext[str]: The extension of rendered result (e.g., '.html'). """ if not isinstance(items, list) or any(not isinstance(x, dict) for x in items): LOG.error('The supplied items must be a list of dict items, each with a "root_dir" and ' 'optionally a "content" entry.') return None roots = set() nodes = dict() for root, filename in get_files(items, in_ext): roots.add(root) key = filename.replace(root, '').strip('/') parts = key.split('/') # Create directory nodes if they don't exist for i in range(1, len(parts)): dir_key = os.path.join(*parts[:i]) if dir_key not in nodes: nodes[dir_key] = MooseDocs.tree.pages.Directory(dir_key, source=os.path.join(root, dir_key)) # Create the file node, if it doesn't already exist. This enforces that the first # item in the supplied content lists is the page that is rendered. if key not in nodes: nodes[key] = create_file_page(key, filename, in_ext) # Update the project files for root in roots: if mooseutils.is_git_repo(root): MooseDocs.PROJECT_FILES.update(mooseutils.git_ls_files(mooseutils.git_root_dir(root))) else: MooseDocs.PROJECT_FILES.update(mooseutils.list_files(root)) return nodes.values()