示例#1
0
文件: core.py 项目: elaOnMars/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.list_dirs_from_url(url)
        for i, _ in enumerate(dirs):
            fullpath = '/'.join(dirs[:i+1])
            if fullpath not in self.index:
                # If a collection is set in site.yaml for this URL, use the
                # corresponding template if set.
                template = self.templates['index']
                var = get_collection_var(fullpath, self.collection_paths)
                if var:
                    template = self.config['collections'][var].get(
                        'template', template)

                self.index[fullpath] = Collection(docs=[], template=template)

            self.index[fullpath].docs.append(doc)
示例#2
0
    def test_list_dirs_from_url(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 in tests:
            self.assertEqual(test[1], path.list_dirs_from_url(test[0]))
    def test_list_dirs_from_url(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 in tests:
            self.assertEqual(test[1], path.list_dirs_from_url(test[0]))