• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.get_crumbs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nikola.utils.get_crumbs函数的典型用法代码示例。如果您正苦于以下问题:Python get_crumbs函数的具体用法?Python get_crumbs怎么用?Python get_crumbs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_crumbs函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_get_crumbs

def test_get_crumbs():
    crumbs = get_crumbs('galleries')
    assert len(crumbs) == 1
    assert crumbs[0] == ['#', 'galleries']

    crumbs = get_crumbs(os.path.join('galleries', 'demo'))
    assert len(crumbs) == 2
    assert crumbs[0] == ['..', 'galleries']
    assert crumbs[1] == ['#', 'demo']

    crumbs = get_crumbs(os.path.join('listings', 'foo', 'bar'), is_file=True)
    assert len(crumbs) == 3
    assert crumbs[0] == ['..', 'listings']
    assert crumbs[1] == ['.', 'foo']
    assert crumbs[2] == ['#', 'bar']
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:15,代码来源:test_utils.py


示例2: render_listing

 def render_listing(in_name, out_name):
     with open(in_name, 'r') as fd:
         try:
             lexer = get_lexer_for_filename(in_name)
         except:
             lexer = TextLexer()
         code = highlight(fd.read(), lexer,
                          HtmlFormatter(cssclass='code',
                                        linenos="table", nowrap=False,
                                        lineanchors=utils.slugify(f),
                                        anchorlinenos=True))
     title = os.path.basename(in_name)
     print("CRUMBSINOUT", in_name, out_name)
     #crumbs = out_name.split(os.sep)[1:-1] + [title]
     # TODO: write this in human
     #paths = ['/'.join(['..'] * (len(crumbs) - 2 - i)) for i in
              #range(len(crumbs[:-2]))] + ['.', '#']
     crumbs = utils.get_crumbs(os.path.relpath(out_name, kw['output_folder']), is_file=True)
     context = {
         'code': code,
         'title': title,
         'crumbs': crumbs,
         'lang': kw['default_lang'],
         'description': title,
     }
     self.site.render_template('listing.tmpl', out_name.encode('utf8'),
                               context)
开发者ID:Almad,项目名称:nikola,代码行数:27,代码来源:task_render_listings.py


示例3: render_listing

 def render_listing(in_name, out_name, folders=[], files=[]):
     if in_name:
         with open(in_name, 'r') as fd:
             try:
                 lexer = get_lexer_for_filename(in_name)
             except:
                 lexer = TextLexer()
             code = highlight(fd.read(), lexer,
                              HtmlFormatter(cssclass='code',
                                            linenos="table", nowrap=False,
                                            lineanchors=utils.slugify(f),
                                            anchorlinenos=True))
         title = os.path.basename(in_name)
     else:
         code = ''
         title = ''
     crumbs = utils.get_crumbs(os.path.relpath(out_name,
                                               kw['output_folder']),
                               is_file=True)
     context = {
         'code': code,
         'title': title,
         'crumbs': crumbs,
         'lang': kw['default_lang'],
         'folders': folders,
         'files': files,
         'description': title,
     }
     self.site.render_template('listing.tmpl', out_name,
                               context)
开发者ID:chensy0203,项目名称:nikola,代码行数:30,代码来源:task_render_listings.py


示例4: render_listing

 def render_listing(in_name, out_name, input_folder, output_folder, folders=[], files=[]):
     needs_ipython_css = False
     if in_name and in_name.endswith('.ipynb'):
         # Special handling: render ipynbs in listings (Issue #1900)
         ipynb_compiler = self.site.plugin_manager.getPluginByName("ipynb", "PageCompiler").plugin_object
         ipynb_raw = ipynb_compiler.compile_html_string(in_name, True)
         ipynb_html = lxml.html.fromstring(ipynb_raw)
         # The raw HTML contains garbage (scripts and styles), we can’t leave it in
         code = lxml.html.tostring(ipynb_html.xpath('//*[@id="notebook"]')[0], encoding='unicode')
         title = os.path.basename(in_name)
         needs_ipython_css = True
     elif in_name:
         with open(in_name, 'r') as fd:
             try:
                 lexer = get_lexer_for_filename(in_name)
             except:
                 lexer = TextLexer()
             code = highlight(fd.read(), lexer, utils.NikolaPygmentsHTML(in_name))
         title = os.path.basename(in_name)
     else:
         code = ''
         title = os.path.split(os.path.dirname(out_name))[1]
     crumbs = utils.get_crumbs(os.path.relpath(out_name,
                                               self.kw['output_folder']),
                               is_file=True)
     permalink = self.site.link(
         'listing',
         os.path.join(
             input_folder,
             os.path.relpath(
                 out_name[:-5],  # remove '.html'
                 os.path.join(
                     self.kw['output_folder'],
                     output_folder))))
     if self.site.config['COPY_SOURCES'] and in_name:
         source_link = permalink[:-5]  # remove '.html'
     else:
         source_link = None
     context = {
         'code': code,
         'title': title,
         'crumbs': crumbs,
         'permalink': permalink,
         'lang': self.kw['default_lang'],
         'folders': natsort.natsorted(
             folders, alg=natsort.ns.F | natsort.ns.IC),
         'files': natsort.natsorted(
             files, alg=natsort.ns.F | natsort.ns.IC),
         'description': title,
         'source_link': source_link,
         'pagekind': ['listing'],
     }
     if needs_ipython_css:
         # If someone does not have ipynb posts and only listings, we
         # need to enable ipynb CSS for ipynb listings.
         context['needs_ipython_css'] = True
     self.site.render_template('listing.tmpl', out_name, context)
开发者ID:Cadair,项目名称:nikola,代码行数:57,代码来源:listings.py


示例5: render_listing

 def render_listing(in_name, out_name, input_folder, output_folder, folders=[], files=[]):
     if in_name:
         with open(in_name, 'r') as fd:
             try:
                 lexer = get_lexer_for_filename(in_name)
             except:
                 lexer = TextLexer()
             code = highlight(fd.read(), lexer,
                              HtmlFormatter(cssclass='code',
                                            linenos="table", nowrap=False,
                                            lineanchors=utils.slugify(in_name, force=True),
                                            anchorlinenos=True))
         # the pygments highlighter uses <div class="codehilite"><pre>
         # for code.  We switch it to reST's <pre class="code">.
         code = CODERE.sub('<pre class="code literal-block">\\1</pre>', code)
         title = os.path.basename(in_name)
     else:
         code = ''
         title = os.path.split(os.path.dirname(out_name))[1]
     crumbs = utils.get_crumbs(os.path.relpath(out_name,
                                               self.kw['output_folder']),
                               is_file=True)
     permalink = self.site.link(
         'listing',
         os.path.join(
             input_folder,
             os.path.relpath(
                 out_name[:-5],  # remove '.html'
                 os.path.join(
                     self.kw['output_folder'],
                     output_folder))))
     if self.site.config['COPY_SOURCES']:
         source_link = permalink[:-5]  # remove '.html'
     else:
         source_link = None
     context = {
         'code': code,
         'title': title,
         'crumbs': crumbs,
         'permalink': permalink,
         'lang': self.kw['default_lang'],
         'folders': natsort.natsorted(folders),
         'files': natsort.natsorted(files),
         'description': title,
         'source_link': source_link,
     }
     self.site.render_template('listing.tmpl', out_name, context)
开发者ID:kqij2015,项目名称:nikola,代码行数:47,代码来源:listings.py


示例6: render_listing

 def render_listing(in_name, out_name, folders=[], files=[]):
     if in_name:
         with open(in_name, 'r') as fd:
             try:
                 lexer = get_lexer_for_filename(in_name)
             except:
                 lexer = TextLexer()
             code = highlight(fd.read(), lexer,
                              HtmlFormatter(cssclass='code',
                                            linenos="table", nowrap=False,
                                            lineanchors=utils.slugify(in_name),
                                            anchorlinenos=True))
         title = os.path.basename(in_name)
     else:
         code = ''
         title = ''
     crumbs = utils.get_crumbs(os.path.relpath(out_name,
                                               kw['output_folder']),
                               is_file=True)
     permalink = self.site.link(
         'listing',
         os.path.relpath(
             out_name,
             os.path.join(
                 kw['output_folder'],
                 kw['listings_folder'])))
     if self.site.config['COPY_SOURCES']:
         source_link = permalink[:-5]
     else:
         source_link = None
     context = {
         'code': code,
         'title': title,
         'crumbs': crumbs,
         'permalink': permalink,
         'lang': kw['default_lang'],
         'folders': natsort.natsorted(folders),
         'files': natsort.natsorted(files),
         'description': title,
         'source_link': source_link,
     }
     self.site.render_template('listing.tmpl', out_name,
                               context)
开发者ID:carriercomm,项目名称:nikola,代码行数:43,代码来源:listings.py


示例7: render_listing

 def render_listing(in_name, out_name, input_folder, output_folder, folders=[], files=[]):
     if in_name:
         with open(in_name, 'r') as fd:
             try:
                 lexer = get_lexer_for_filename(in_name)
             except:
                 lexer = TextLexer()
             code = highlight(fd.read(), lexer, utils.NikolaPygmentsHTML(in_name))
         title = os.path.basename(in_name)
     else:
         code = ''
         title = os.path.split(os.path.dirname(out_name))[1]
     crumbs = utils.get_crumbs(os.path.relpath(out_name,
                                               self.kw['output_folder']),
                               is_file=True)
     permalink = self.site.link(
         'listing',
         os.path.join(
             input_folder,
             os.path.relpath(
                 out_name[:-5],  # remove '.html'
                 os.path.join(
                     self.kw['output_folder'],
                     output_folder))))
     if self.site.config['COPY_SOURCES'] and in_name:
         source_link = permalink[:-5]  # remove '.html'
     else:
         source_link = None
     context = {
         'code': code,
         'title': title,
         'crumbs': crumbs,
         'permalink': permalink,
         'lang': self.kw['default_lang'],
         'folders': natsort.natsorted(
             folders, alg=natsort.ns.F | natsort.ns.IC),
         'files': natsort.natsorted(
             files, alg=natsort.ns.F | natsort.ns.IC),
         'description': title,
         'source_link': source_link,
         'pagekind': ['listing'],
     }
     self.site.render_template('listing.tmpl', out_name, context)
开发者ID:carlosvin,项目名称:nikola,代码行数:43,代码来源:listings.py


示例8: gen_tasks

    def gen_tasks(self):
        """Render image galleries."""

        if Image is None:
            req_missing(['pillow'], 'render galleries')

        self.logger = utils.get_logger('render_galleries', self.site.loghandlers)
        self.image_ext_list = ['.jpg', '.png', '.jpeg', '.gif', '.svg', '.bmp', '.tiff']
        self.image_ext_list.extend(self.site.config.get('EXTRA_IMAGE_EXTENSIONS', []))

        self.kw = {
            'thumbnail_size': self.site.config['THUMBNAIL_SIZE'],
            'max_image_size': self.site.config['MAX_IMAGE_SIZE'],
            'output_folder': self.site.config['OUTPUT_FOLDER'],
            'cache_folder': self.site.config['CACHE_FOLDER'],
            'default_lang': self.site.config['DEFAULT_LANG'],
            'use_filename_as_title': self.site.config['USE_FILENAME_AS_TITLE'],
            'gallery_path': self.site.config['GALLERY_PATH'],
            'sort_by_date': self.site.config['GALLERY_SORT_BY_DATE'],
            'filters': self.site.config['FILTERS'],
            'translations': self.site.config['TRANSLATIONS'],
            'global_context': self.site.GLOBAL_CONTEXT,
            "feed_length": self.site.config['FEED_LENGTH'],
        }

        yield self.group_task()

        template_name = "gallery.tmpl"

        # Find all galleries we need to process
        self.find_galleries()

        # Create all output folders
        for task in self.create_galleries():
            yield task

        # For each gallery:
        for gallery in self.gallery_list:

            # Create subfolder list
            folder_list = [(x, x.split(os.sep)[-2]) for x in
                           glob.glob(os.path.join(gallery, '*') + os.sep)]

            # Parse index into a post (with translations)
            post = self.parse_index(gallery)

            # Create image list, filter exclusions
            image_list = self.get_image_list(gallery)

            # Sort as needed
            # Sort by date
            if self.kw['sort_by_date']:
                image_list.sort(key=lambda a: self.image_date(a))
            else:  # Sort by name
                image_list.sort()

            # Create thumbnails and large images in destination
            for image in image_list:
                for task in self.create_target_images(image):
                    yield task

            # Remove excluded images
            for image in self.get_excluded_images(gallery):
                for task in self.remove_excluded_image(image):
                    yield task

            crumbs = utils.get_crumbs(gallery, index_folder=self)

            # Create index.html for each language
            for lang in self.kw['translations']:
                dst = os.path.join(
                    self.kw['output_folder'],
                    self.site.path(
                        "gallery",
                        os.path.relpath(gallery, self.kw['gallery_path']), lang))
                dst = os.path.normpath(dst)

                context = {}
                context["lang"] = lang
                if post:
                    context["title"] = post.title(lang)
                else:
                    context["title"] = os.path.basename(gallery)
                context["description"] = None

                image_name_list = [os.path.basename(p) for p in image_list]

                if self.kw['use_filename_as_title']:
                    img_titles = []
                    for fn in image_name_list:
                        name_without_ext = os.path.splitext(fn)[0]
                        img_titles.append(
                            'id="{0}" alt="{1}" title="{2}"'.format(
                                name_without_ext,
                                name_without_ext,
                                utils.unslugify(name_without_ext)))
                else:
                    img_titles = [''] * len(image_name_list)

                thumbs = ['.thumbnail'.join(os.path.splitext(p)) for p in image_list]
#.........这里部分代码省略.........
开发者ID:Liessae,项目名称:nikola,代码行数:101,代码来源:galleries.py


示例9: gen_tasks

    def gen_tasks(self):
        """Render image galleries."""

        kw = {
            'thumbnail_size': self.site.config['THUMBNAIL_SIZE'],
            'max_image_size': self.site.config['MAX_IMAGE_SIZE'],
            'output_folder': self.site.config['OUTPUT_FOLDER'],
            'cache_folder': self.site.config['CACHE_FOLDER'],
            'default_lang': self.site.config['DEFAULT_LANG'],
            'blog_description': self.site.config['BLOG_DESCRIPTION'],
            'use_filename_as_title': self.site.config['USE_FILENAME_AS_TITLE'],
            'gallery_path': self.site.config['GALLERY_PATH']
        }

        # FIXME: lots of work is done even when images don't change,
        # which should be moved into the task.

        template_name = "gallery.tmpl"

        gallery_list = []
        for root, dirs, files in os.walk(kw['gallery_path']):
            gallery_list.append(root)
        if not gallery_list:
            yield {
                'basename': str('render_galleries'),
                'actions': [],
            }
            return

        # gallery_path is "gallery/name"
        for gallery_path in gallery_list:
            # gallery_name is "name"
            splitted = gallery_path.split(os.sep)[1:]
            if not splitted:
                gallery_name = ''
            else:
                gallery_name = os.path.join(*splitted)
            # output_gallery is "output/GALLERY_PATH/name"
            output_gallery = os.path.dirname(os.path.join(
                kw["output_folder"], self.site.path("gallery", gallery_name,
                                                    None)))
            output_name = os.path.join(output_gallery, self.site.config['INDEX_FILE'])
            if not os.path.isdir(output_gallery):
                yield {
                    'basename': str('render_galleries'),
                    'name': output_gallery,
                    'actions': [(os.makedirs, (output_gallery,))],
                    'targets': [output_gallery],
                    'clean': True,
                    'uptodate': [utils.config_changed(kw)],
                }
            # image_list contains "gallery/name/image_name.jpg"
            image_list = glob.glob(gallery_path + "/*jpg") +\
                glob.glob(gallery_path + "/*JPG") +\
                glob.glob(gallery_path + "/*PNG") +\
                glob.glob(gallery_path + "/*png")

            # Filter ignore images
            try:
                def add_gallery_path(index):
                    return "{0}/{1}".format(gallery_path, index)

                exclude_path = os.path.join(gallery_path, "exclude.meta")
                try:
                    f = open(exclude_path, 'r')
                    excluded_image_name_list = f.read().split()
                except IOError:
                    excluded_image_name_list = []

                excluded_image_list = list(map(add_gallery_path,
                                               excluded_image_name_list))
                image_set = set(image_list) - set(excluded_image_list)
                image_list = list(image_set)
            except IOError:
                pass

            # List of sub-galleries
            folder_list = [x.split(os.sep)[-2] for x in
                           glob.glob(os.path.join(gallery_path, '*') + os.sep)]

            crumbs = utils.get_crumbs(gallery_path)

            image_list = [x for x in image_list if "thumbnail" not in x]
            # Sort by date
            image_list.sort(key=lambda a: self.image_date(a))
            image_name_list = [os.path.basename(x) for x in image_list]
            thumbs = []
            # Do thumbnails and copy originals
            for img, img_name in list(zip(image_list, image_name_list)):
                # img is "galleries/name/image_name.jpg"
                # img_name is "image_name.jpg"
                # fname, ext are "image_name", ".jpg"
                fname, ext = os.path.splitext(img_name)
                # thumb_path is
                # "output/GALLERY_PATH/name/image_name.thumbnail.jpg"
                thumb_path = os.path.join(output_gallery,
                                          ".thumbnail".join([fname, ext]))
                # thumb_path is "output/GALLERY_PATH/name/image_name.jpg"
                orig_dest_path = os.path.join(output_gallery, img_name)
                thumbs.append(os.path.basename(thumb_path))
#.........这里部分代码省略.........
开发者ID:dflock,项目名称:nikola,代码行数:101,代码来源:task_render_galleries.py


示例10: gen_tasks

    def gen_tasks(self):
        """Render image galleries."""
        self.image_ext_list = self.image_ext_list_builtin
        self.image_ext_list.extend(self.site.config.get('EXTRA_IMAGE_EXTENSIONS', []))

        for k, v in self.site.GLOBAL_CONTEXT['template_hooks'].items():
            self.kw['||template_hooks|{0}||'.format(k)] = v._items

        yield self.group_task()

        template_name = "gallery.tmpl"

        # Create all output folders
        for task in self.create_galleries():
            yield task

        # For each gallery:
        for gallery, input_folder, output_folder in self.gallery_list:

            # Create subfolder list
            folder_list = [(x, x.split(os.sep)[-2]) for x in
                           glob.glob(os.path.join(gallery, '*') + os.sep)]

            # Parse index into a post (with translations)
            post = self.parse_index(gallery, input_folder, output_folder)

            # Create image list, filter exclusions
            image_list = self.get_image_list(gallery)

            # Create thumbnails and large images in destination
            for image in image_list:
                for task in self.create_target_images(image, input_folder):
                    yield task

            # Remove excluded images
            for image in self.get_excluded_images(gallery):
                for task in self.remove_excluded_image(image, input_folder):
                    yield task

            for lang in self.kw['translations']:
                # save navigation links as dependencies
                self.kw['navigation_links|{0}'.format(lang)] = self.kw['global_context']['navigation_links'](lang)

            # Create index.html for each language
            for lang in self.kw['translations']:

                dst = os.path.join(
                    self.kw['output_folder'],
                    self.site.path("gallery", gallery, lang))
                dst = os.path.normpath(dst)

                for k in self.site._GLOBAL_CONTEXT_TRANSLATABLE:
                    self.kw[k] = self.site.GLOBAL_CONTEXT[k](lang)

                context = {}
                context["lang"] = lang
                if post:
                    context["title"] = post.title(lang)
                else:
                    context["title"] = os.path.basename(gallery)
                context["description"] = None

                image_name_list = [os.path.basename(p) for p in image_list]

                if self.kw['use_filename_as_title']:
                    img_titles = []
                    for fn in image_name_list:
                        name_without_ext = os.path.splitext(os.path.basename(fn))[0]
                        img_titles.append(utils.unslugify(name_without_ext))
                else:
                    img_titles = [''] * len(image_name_list)

                thumbs = ['.thumbnail'.join(os.path.splitext(p)) for p in image_list]
                thumbs = [os.path.join(self.kw['output_folder'], output_folder, os.path.relpath(t, input_folder)) for t in thumbs]
                dst_img_list = [os.path.join(output_folder, os.path.relpath(t, input_folder)) for t in image_list]
                dest_img_list = [os.path.join(self.kw['output_folder'], t) for t in dst_img_list]

                folders = []

                # Generate friendly gallery names
                for path, folder in folder_list:
                    fpost = self.parse_index(path, input_folder, output_folder)
                    if fpost:
                        ft = fpost.title(lang) or folder
                    else:
                        ft = folder
                    if not folder.endswith('/'):
                        folder += '/'
                    folders.append((folder, ft))

                context["folders"] = natsort.natsorted(
                    folders, alg=natsort.ns.F | natsort.ns.IC)
                context["crumbs"] = utils.get_crumbs(gallery, index_folder=self, lang=lang)
                context["permalink"] = self.site.link("gallery", gallery, lang)
                context["enable_comments"] = self.kw['comments_in_galleries']
                context["thumbnail_size"] = self.kw["thumbnail_size"]
                context["pagekind"] = ["gallery_front"]

                if post:
                    yield {
#.........这里部分代码省略.........
开发者ID:davidak,项目名称:nikola,代码行数:101,代码来源:galleries.py


示例11: gen_tasks

    def gen_tasks(self):
        """Render image galleries."""

        self.logger = utils.get_logger("render_galleries", self.site.loghandlers)
        self.image_ext_list = [".jpg", ".png", ".jpeg", ".gif", ".svg", ".bmp", ".tiff"]
        self.image_ext_list.extend(self.site.config.get("EXTRA_IMAGE_EXTENSIONS", []))

        self.kw = {
            "thumbnail_size": self.site.config["THUMBNAIL_SIZE"],
            "max_image_size": self.site.config["MAX_IMAGE_SIZE"],
            "output_folder": self.site.config["OUTPUT_FOLDER"],
            "cache_folder": self.site.config["CACHE_FOLDER"],
            "default_lang": self.site.config["DEFAULT_LANG"],
            "use_filename_as_title": self.site.config["USE_FILENAME_AS_TITLE"],
            "gallery_path": self.site.config["GALLERY_PATH"],
            "sort_by_date": self.site.config["GALLERY_SORT_BY_DATE"],
            "filters": self.site.config["FILTERS"],
            "translations": self.site.config["TRANSLATIONS"],
            "global_context": self.site.GLOBAL_CONTEXT,
            "feed_length": self.site.config["FEED_LENGTH"],
        }

        yield self.group_task()

        template_name = "gallery.tmpl"

        # Find all galleries we need to process
        self.find_galleries()

        # Create all output folders
        for task in self.create_galleries():
            yield task

        # For each gallery:
        for gallery in self.gallery_list:

            # Create subfolder list
            folder_list = [(x, x.split(os.sep)[-2]) for x in glob.glob(os.path.join(gallery, "*") + os.sep)]

            # Parse index into a post (with translations)
            post = self.parse_index(gallery)

            # Create image list, filter exclusions
            image_list = self.get_image_list(gallery)

            # Sort as needed
            # Sort by date
            if self.kw["sort_by_date"]:
                image_list.sort(key=lambda a: self.image_date(a))
            else:  # Sort by name
                image_list.sort()

            # Create thumbnails and large images in destination
            for image in image_list:
                for task in self.create_target_images(image):
                    yield task

            # Remove excluded images
            for image in self.get_excluded_images(gallery):
                for task in self.remove_excluded_image(image):
                    yield task

            crumbs = utils.get_crumbs(gallery)

            # Create index.html for each language
            for lang in self.kw["translations"]:
                dst = os.path.join(
                    self.kw["output_folder"],
                    self.site.path("gallery", os.path.relpath(gallery, self.kw["gallery_path"]), lang),
                )
                dst = os.path.normpath(dst)

                context = {}
                context["lang"] = lang
                if post:
                    context["title"] = post.title(lang)
                else:
                    context["title"] = os.path.basename(gallery)
                context["description"] = None

                image_name_list = [os.path.basename(p) for p in image_list]

                if self.kw["use_filename_as_title"]:
                    img_titles = []
                    for fn in image_name_list:
                        name_without_ext = os.path.splitext(fn)[0]
                        img_titles.append(
                            'id="{0}" alt="{1}" title="{2}"'.format(
                                name_without_ext, name_without_ext, utils.unslugify(name_without_ext)
                            )
                        )
                else:
                    img_titles = [""] * len(image_name_list)

                thumbs = [".thumbnail".join(os.path.splitext(p)) for p in image_list]
                thumbs = [os.path.join(self.kw["output_folder"], t) for t in thumbs]

                folders = []

                # Generate friendly gallery names
#.........这里部分代码省略.........
开发者ID:agustinhenze,项目名称:nikola,代码行数:101,代码来源:galleries.py


示例12: gen_tasks

    def gen_tasks(self):
        """Render image galleries."""

        kw = {
            "thumbnail_size": self.site.config["THUMBNAIL_SIZE"],
            "max_image_size": self.site.config["MAX_IMAGE_SIZE"],
            "output_folder": self.site.config["OUTPUT_FOLDER"],
            "cache_folder": self.site.config["CACHE_FOLDER"],
            "default_lang": self.site.config["DEFAULT_LANG"],
            "blog_description": self.site.config["BLOG_DESCRIPTION"],
            "use_filename_as_title": self.site.config["USE_FILENAME_AS_TITLE"],
            "gallery_path": self.site.config["GALLERY_PATH"],
        }

        # FIXME: lots of work is done even when images don't change,
        # which should be moved into the task.

        template_name = "gallery.tmpl"

        gallery_list = []
        for root, dirs, files in os.walk(kw["gallery_path"]):
            gallery_list.append(root)
        if not gallery_list:
            yield {"basename": str("render_galleries"), "actions": []}
            return

        # gallery_path is "gallery/name"
        for gallery_path in gallery_list:
            # gallery_name is "name"
            splitted = gallery_path.split(os.sep)[1:]
            if not splitted:
                gallery_name = ""
            else:
                gallery_name = os.path.join(*splitted)

            # Task to create gallery in output/
            # output_gallery is "output/GALLERY_PATH/name"
            output_gallery = os.path.dirname(
                os.path.join(kw["output_folder"], self.site.path("gallery", gallery_name, None))
            )
            output_name = os.path.join(output_gallery, self.site.config["INDEX_FILE"])
            if not os.path.isdir(output_gallery):
                yield {
                    "basename": str("render_galleries"),
                    "name": output_gallery,
                    "actions": [(os.makedirs, (output_gallery,))],
                    "targets": [output_gallery],
                    "clean": True,
                    "uptodate": [utils.config_changed(kw)],
                }

            # Gather image_list contains "gallery/name/image_name.jpg"
            image_list = (
                glob.glob(gallery_path + "/*jpg")
                + glob.glob(gallery_path + "/*JPG")
                + glob.glob(gallery_path + "/*png")
                + glob.glob(gallery_path + "/*PNG")
            )

            # Filter ignored images
            try:
                exclude_path = os.path.join(gallery_path, "exclude.meta")
                try:
                    f = open(exclude_path, "r")
                    excluded_image_name_list = f.read().split()
                except IOError:
                    excluded_image_name_list = []
                excluded_image_list = ["{0}/{1}".format(gallery_path, i) for i in excluded_image_name_list]
                image_set = set(image_list) - set(excluded_image_list)
                image_list = list(image_set)
            except IOError:
                pass

            # List of sub-galleries
            folder_list = [x.split(os.sep)[-2] for x in glob.glob(os.path.join(gallery_path, "*") + os.sep)]

            crumbs = utils.get_crumbs(gallery_path)

            image_list = [x for x in image_list if "thumbnail" not in x]
            # Sort by date
            image_list.sort(key=lambda a: self.image_date(a))
            image_name_list = [os.path.basename(x) for x in image_list]

            # Do thumbnails and copy originals
            thumbs = []
            for img, img_name in list(zip(image_list, image_name_list)):
                # img is "galleries/name/image_name.jpg"
                # img_name is "image_name.jpg"
                # fname, ext are "image_name", ".jpg"
                fname, ext = os.path.splitext(img_name)
                # thumb_path is
                # "output/GALLERY_PATH/name/image_name.thumbnail.jpg"
                thumb_path = os.path.join(output_gallery, ".thumbnail".join([fname, ext]))
                # thumb_path is "output/GALLERY_PATH/name/image_name.jpg"
                orig_dest_path = os.path.join(output_gallery, img_name)
                thumbs.append(os.path.basename(thumb_path))
                yield {
                    "basename": str("render_galleries"),
                    "name": thumb_path,
                    "file_dep": [img],
#.........这里部分代码省略.........
开发者ID:ralsina,项目名称:nikola,代码行数:101,代码来源:galleries.py


示例13: gen_tasks

    def gen_tasks(self):
        """Render image galleries."""

        if Image is None:
            req_missing(["pillow"], "render galleries")

        self.image_ext_list = self.image_ext_list_builtin
        self.image_ext_list.extend(self.site.config.get("EXTRA_IMAGE_EXTENSIONS", []))

        for k, v in self.site.GLOBAL_CONTEXT["template_hooks"].items():
            self.kw["||template_hooks|{0}||".format(k)] = v._items

        yield self.group_task()

        template_name = "gallery.tmpl"

        # Create all output folders
        for task in self.create_galleries():
            yield task

        # For each gallery:
        for gallery, input_folder, output_folder in self.gallery_list:

            # Create subfolder list
            folder_list = [(x, x.split(os.sep)[-2]) for x in glob.glob(os.path.join(gallery, "*") + os.sep)]

            # Parse index into a post (with translations)
            post = self.parse_index(gallery, input_folder, output_folder)

            # Create image list, filter exclusions
            image_list = self.get_image_list(gallery)

            # Sort as needed
            # Sort by date
            if self.kw["sort_by_date"]:
                image_list.sort(key=lambda a: self.image_date(a))
            else:  # Sort by name
                image_list.sort()

            # Create thumbnails and large images in destination
            for image in image_list:
                for task in self.create_target_images(image, input_folder):
                    yield task

            # Remove excluded images
            for image in self.get_excluded_images(gallery):
                for task in self.remove_excluded_image(image, input_folder):
                    yield task

            crumbs = utils.get_crumbs(gallery, index_folder=self)

            # Create index.html for each language
            for lang in self.kw["translations"]:
                # save navigation links as dependencies
                self.kw["navigation_links|{0}".format(lang)] = self.kw["global_context"]["navigation_links"](lang)

                dst = os.path.join(self.kw["output_folder"], self.site.path("gallery", gallery, lang))
                dst = os.path.normpath(dst)

                for k in self.site._GLOBAL_CONTEXT_TRANSLATABLE:
                    self.kw[k] = self.site.GLOBAL_CONTEXT[k](lang)

                context = {}
                context["lang"] = lang
                if post:
                    context["title"] = post.title(lang)
                else:
                    context["title"] = os.path.basename(gallery)
                context["description"] = None

                image_name_list = [os.path.basename(p) for p in image_list]

                if self.kw["use_filename_as_title"]:
                    img_titles = []
                    for fn in image_name_list:
                        name_without_ext = os.path.splitext(os.path.basename(fn))[0]
                        img_titles.append(utils.unslugify(name_without_ext))
                else:
                    img_titles = [""] * len(image_name_list)

                thumbs = [".thumbnail".join(os.path.splitext(p)) for p in image_list]
                thumbs = [
                    os.path.join(self.kw["output_folder"], output_folder, os.path.relpath(t, input_folder))
                    for t in thumbs
                ]
                dst_img_list = [os.path.join(output_folder, os.path.relpath(t, input_folder)) for t in image_list]
                dest_img_list = [os.path.join(self.kw["output_folder"], t) for t in dst_img_list]

                folders = []

                # Generate friendly gallery names
                for path, folder in folder_list:
                    fpost = self.parse_index(path, input_folder, output_folder)
                    if fpost:
                        ft = fpost.title(lang) or folder
                    else:
                        ft = folder
                    if not folder.endswith("/"):
                        folder += "/"
                    folders.append((folder, ft))
#.........这里部分代码省略.........
开发者ID:mgaitan,项目名称:nikola,代码行数:101,代码来源:galleries.py


示例14: gen_tasks

    def gen_tasks(self):
        """Render image galleries."""

        if Image is None:
            req_missing(['pillow'], 'render galleries')

        self.logger = utils.get_logger('render_galleries', self.site.loghandlers)
        self.image_ext_list = ['.jpg', '.png', '.jpeg', '.gif', '.svg', '.bmp', '.tiff']
        self.image_ext_list.extend(self.site.config.get('EXTRA_IMAGE_EXTENSIONS', []))

        self.kw = {
            'thumbnail_size': self.site.config['THUMBNAIL_SIZE'],
            'max_image_size': self.site.config['MAX_IMAGE_SIZE'],
            'output_folder': self.site.config['OUTPUT_FOLDER'],
            'cache_folder': self.site.config['CACHE_FOLDER'],
            'default_lang': self.site.config['DEFAULT_LANG'],
            'use_filename_as_title': self.site.config['USE_FILENAME_AS_TITLE'],
            'gallery_path': self.site.config['GALLERY_PATH'],
            'sort_by_date': self.site.config['GALLERY_SORT_BY_DATE'],
            'filters': self.site.config['FILTERS'],
            'translations': self.site.config['TRANSLATIONS'],
            'global_context': self.site.GLOBAL_CONTEXT,
            'feed_length': self.site.config['FEED_LENGTH'],
            'tzinfo': self.site.tzinfo,
            'comments_in_galleries': self.site.config['COMMENTS_IN_GALLERIES'],
            'generate_rss': self.site.config['GENERATE_RSS'],
        }

        for k, v in self.site.GLOBAL_CONTEXT['template_hooks'].items():
            self.kw['||template_hooks|{0}||'.format(k)] = v._items

        yield self.group_task()

        template_name = "gallery.tmpl"

        # Find all galleries we need to process
        self.find_galleries()

        # Create all output folders
        for task in self.create_galleries():
            yield task

        # For each gallery:
        for gallery in self.gallery_list:

            # Create subfolder list
            folder_list = [(x, x.split(os.sep)[-2]) for x in
                           glob.glob(os.path.join(gallery, '*') + os.sep)]

            # Parse index into a post (with translations)
            post = self.parse_index(gallery)

            # Create image list, filter exclusions
            image_list = self.get_image_list(gallery)

            # Sort as needed
            # Sort by date
            if self.kw['sort_by_date']:
                image_list.sort(key=lambda a: self.image_date(a))
            else:  # Sort by name
                image_list.sort()

            # Create thumbnails and large images in destination
            for image in image_list:
                for task in self.create_target_images(image):
                    yield task

            # Remove excluded images
            for image in self.get_excluded_images(gallery):
                for task in self.remove_excluded_image(image):
                    yield task

            crumbs = utils.get_crumbs(gallery, index_folder=self)

            # Create index.html for each language
            for lang in self.kw['translations']:
                # save navigation links as dependencies
                self.kw['navigation_links|{0}'.format(lang)] = self.kw['global_context']['navigation_links'](lang)

                dst = os.path.join(
                    self.kw['output_folder'],
                    self.site.path(
                        "gallery",
                        os.path.relpath(gallery, self.kw['gallery_path']), lang))
                dst = os.path.normpath(dst)

                for k in self.site._GLOBAL_CONTEXT_TRANSLATABLE:
                    self.kw[k] = self.site.GLOBAL_CONTEXT[k](lang)

                context = {}
                context["lang"] = lang
                if post:
                    context["title"] = post.title(lang)
                else:
                    context["title"] = os.path.basename(gallery)
                context["description"] = None

                image_name_list = [os.path.basename(p) for p in image_list]

                if self.kw['use_filename_as_title']:
#.........这里部分代码省略.........
开发者ID:follower,项目名称:nikola,代码行数:101,代码来源:galleries.py



注:本文中的nikola.utils.get_crumbs函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_logger函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_asset_path函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap