def test_parent(): assert paths.parent("/") == "/" assert paths.parent("a") == "" assert paths.parent("a/b") == "" assert paths.parent("/a/b") == "/" assert paths.parent("/a/b/") == "/a/" assert paths.parent("/a") == "/" assert paths.parent("/a/") == "/" assert paths.parent("/a/b/c/..") == "/a/"
def _find_ancestor(pages, dirpath): # Look for an _index file in the given directory, and if not found, # recursively look in parent directories spath = None while True: spath = pages.source_path(dirpath) if pages.exists(spath): return spath elif dirpath != "/": dirpath = paths.parent(dirpath) continue break return spath
def _get_parent_path(pages, path, block): # Find the path to the parent document attrs = block.get("attrs", {}) if "parent" in attrs: # If the author specified a parent, use that parent = attrs.get("parent") parentpath = pages.source_path(paths.join(path, parent)) elif pages.is_index_page(path): # If this is an index page, assume its parent is the _index page of # the parent directory parentpath = Parents._find_ancestor(pages, paths.parent(path)) else: # Assume the parent is the _index page for this directory parentpath = Parents._find_ancestor(pages, paths.directory(path)) return parentpath
def get_prefixed_paths(pages, prefix): prefixdir = prefix if prefix.endswith("/") else paths.parent(prefix) for path in pages.store.list_all(prefixdir): if not path.startswith(prefix): continue yield path