コード例 #1
0
ファイル: test_path.py プロジェクト: yaph/logya
    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))
コード例 #2
0
    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))
コード例 #3
0
ファイル: core.py プロジェクト: thinkinpg/logya
    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)
コード例 #4
0
    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)
コード例 #5
0
ファイル: core.py プロジェクト: thinkinpg/logya
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)
コード例 #6
0
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)