def test_parent_dirs(self): tests = [ ('/index.html', []), ('/video/crouton-explained-hp-chromebook-11/', ['video']), ('__index__/index/', ['__index__']), ('/tags/video-tutorial/index.html', ['tags', 'video-tutorial']), ('/qotd/2015/03/22/', ['qotd', '2015', '03'])] for test_input, expected in tests: self.assertEqual(expected, path.parent_dirs(test_input))
def test_parent_dirs(self): tests = [('/index.html', []), ('/video/crouton-explained-hp-chromebook-11/', ['video']), ('__index__/index/', ['__index__']), ('/tags/video-tutorial/index.html', ['tags', 'video-tutorial']), ('/qotd/2015/03/22/', ['qotd', '2015', '03'])] for test_input, expected in tests: self.assertEqual(expected, path.parent_dirs(test_input))
def _update_index(self, doc, url=None): """Add a doc to index determined from given url. For each directory in the URL except for the one containing the content file itself a collection is created, if it doesn't exist, and the document is added to it. """ if url is None: url = doc['url'] dirs = path.parent_dirs(url) for fullpath in path.parent_paths(dirs): if fullpath not in self.index: template = self.get_index_template(fullpath) self.index[fullpath] = Collection(docs=[], template=template, urls=set()) # Don't add documents more than once to a collection. Important to # check and add doc['url'], because url can be an index url like tags. if doc['url'] not in self.index[fullpath].urls: self.index[fullpath].urls.add(doc['url']) self.index[fullpath].docs.append(doc)
def get_collection_var(url, collection_index): """Get collections var from site.yaml if url is in a subdirectory of the paths defined in collections.""" parent_path = '/'.join(path.parent_dirs(url)) return collection_index.get(parent_path)