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

Python utils.unslugify函数代码示例

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

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



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

示例1: render_gallery_index

    def render_gallery_index(
        self, template_name, output_name, context, index_dst_path, img_name_list, thumbs, file_dep, kw
    ):
        """Build the gallery index."""

        # The photo array needs to be created here, because
        # it relies on thumbnails already being created on
        # output

        photo_array = []
        d_name = os.path.dirname(output_name)
        for name, thumb_name in zip(img_name_list, thumbs):
            im = Image.open(os.path.join(d_name, thumb_name))
            w, h = im.size
            title = ""
            if kw["use_filename_as_title"]:
                title = utils.unslugify(os.path.splitext(name)[0])
            photo_array.append({"url": name, "url_thumb": thumb_name, "title": title, "size": {"w": w, "h": h}})
        context["photo_array_json"] = json.dumps(photo_array)
        context["photo_array"] = photo_array

        if os.path.exists(index_dst_path):
            with codecs.open(index_dst_path, "rb", "utf8") as fd:
                context["text"] = fd.read()
            file_dep.append(index_dst_path)
        else:
            context["text"] = ""
        self.site.render_template(template_name, output_name, context)
开发者ID:ralsina,项目名称:nikola,代码行数:28,代码来源:galleries.py


示例2: render_gallery_index

    def render_gallery_index(self, template_name, output_name, context, img_list, thumbs, file_dep):
        """Build the gallery index."""

        # The photo array needs to be created here, because
        # it relies on thumbnails already being created on
        # output

        def url_from_path(p):
            url = "/".join(os.path.relpath(p, os.path.dirname(output_name) + os.sep).split(os.sep))
            return url

        photo_array = []
        for img, thumb in zip(img_list, thumbs):
            im = Image.open(thumb)
            w, h = im.size
            title = ""
            if self.kw["use_filename_as_title"]:
                title = utils.unslugify(os.path.splitext(img)[0])
            # Thumbs are files in output, we need URLs
            photo_array.append(
                {"url": url_from_path(img), "url_thumb": url_from_path(thumb), "title": title, "size": {"w": w, "h": h}}
            )
        context["photo_array_json"] = json.dumps(photo_array)
        context["photo_array"] = photo_array

        self.site.render_template(template_name, output_name, context)
开发者ID:agustinhenze,项目名称:nikola,代码行数:26,代码来源:galleries.py


示例3: render_gallery_index

    def render_gallery_index(
            self,
            template_name,
            output_name,
            context,
            index_dst_path,
            img_name_list,
            thumbs,
            file_dep,
            kw):
        """Build the gallery index."""

        # The photo array needs to be created here, because
        # it relies on thumbnails already being created on
        # output

        photo_array = []
        d_name = os.path.dirname(output_name)
        for name, thumb_name in zip(img_name_list, thumbs):
            im = Image.open(os.path.join(d_name, thumb_name))
            w, h = im.size
            title = ''
            if kw['use_filename_as_title']:
                title = utils.unslugify(os.path.splitext(name)[0])
            photo_array.append({
                'url': name,
                'url_thumb': thumb_name,
                'title': title,
                'size': {
                    'w': w,
                    'h': h
                },
            })
        context['photo_array_json'] = json.dumps(photo_array)
        context['photo_array'] = photo_array

        if os.path.exists(index_dst_path):
            with codecs.open(index_dst_path, "rb", "utf8") as fd:
                context['text'] = fd.read()
            file_dep.append(index_dst_path)
        else:
            context['text'] = ''
        self.site.render_template(template_name, output_name, context)
开发者ID:verbalshadow,项目名称:nikola,代码行数:43,代码来源:galleries.py


示例4: extract_filename

    def extract_filename(self, filename: str, lang: str) -> dict:
        """Try to read the metadata from the filename based on the given re.

        This requires to use symbolic group names in the pattern.
        The part to read the metadata from the filename based on a regular
        expression is taken from Pelican - pelican/readers.py
        """
        match = re.match(self.site.config['FILE_METADATA_REGEXP'], filename)
        meta = {}

        if match:
            for key, value in match.groupdict().items():
                k = key.lower().strip()  # metadata must be lowercase
                if k == 'title' and self.site.config['FILE_METADATA_UNSLUGIFY_TITLES']:
                    meta[k] = unslugify(value, lang, discard_numbers=False)
                else:
                    meta[k] = value

        return meta
开发者ID:scp93ch,项目名称:nikola,代码行数:19,代码来源:metadata_extractors.py


示例5: render_gallery_index

    def render_gallery_index(
            self,
            template_name,
            output_name,
            context,
            img_list,
            thumbs,
            file_dep):
        """Build the gallery index."""

        # The photo array needs to be created here, because
        # it relies on thumbnails already being created on
        # output

        def url_from_path(p):
            url = '/'.join(os.path.relpath(p, os.path.dirname(output_name) + os.sep).split(os.sep))
            return url

        photo_array = []
        for img, thumb in zip(img_list, thumbs):
            im = Image.open(thumb)
            w, h = im.size
            title = ''
            if self.kw['use_filename_as_title']:
                title = utils.unslugify(os.path.splitext(img)[0])
            # Thumbs are files in output, we need URLs
            photo_array.append({
                'url': url_from_path(img),
                'url_thumb': url_from_path(thumb),
                'title': title,
                'size': {
                    'w': w,
                    'h': h
                },
            })
        context['photo_array_json'] = json.dumps(photo_array)
        context['photo_array'] = photo_array

        self.site.render_template(template_name, output_name, context)
开发者ID:Liessae,项目名称:nikola,代码行数:39,代码来源:galleries.py


示例6: 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


示例7: gen_tasks


#.........这里部分代码省略.........

            # Remove excluded images
            if excluded_image_name_list:
                for img, img_name in zip(excluded_image_list,
                                         excluded_image_name_list):
                    # img_name is "image_name.jpg"
                    # fname, ext are "image_name", ".jpg"
                    fname, ext = os.path.splitext(img_name)
                    excluded_thumb_dest_path = os.path.join(
                        output_gallery, ".thumbnail".join([fname, ext]))
                    excluded_dest_path = os.path.join(output_gallery, img_name)
                    yield {
                        'basename': str('render_galleries_clean'),
                        'name': excluded_thumb_dest_path,
                        'file_dep': [exclude_path],
                        #'targets': [excluded_thumb_dest_path],
                        'actions': [
                            (utils.remove_file, (excluded_thumb_dest_path,))
                        ],
                        'clean': True,
                        'uptodate': [utils.config_changed(kw)],
                    }
                    yield {
                        'basename': str('render_galleries_clean'),
                        'name': excluded_dest_path,
                        'file_dep': [exclude_path],
                        #'targets': [excluded_dest_path],
                        'actions': [
                            (utils.remove_file, (excluded_dest_path,))
                        ],
                        'clean': True,
                        'uptodate': [utils.config_changed(kw)],
                    }

            context = {}
            context["lang"] = kw["default_lang"]
            context["title"] = os.path.basename(gallery_path)
            context["description"] = kw["blog_description"]
            if kw['use_filename_as_title']:
                img_titles = ['id="{0}" alt="{1}" title="{2}"'.format(
                    fn[:-4], fn[:-4], utils.unslugify(fn[:-4])) for fn
                    in image_name_list]
            else:
                img_titles = [''] * len(image_name_list)
            context["images"] = list(zip(image_name_list, thumbs, img_titles))
            context["folders"] = folder_list
            context["crumbs"] = crumbs
            context["permalink"] = self.site.link(
                "gallery", gallery_name, None)
            context["enable_comments"] = (
                self.site.config["COMMENTS_IN_GALLERIES"])

            # Use galleries/name/index.txt to generate a blurb for
            # the gallery, if it exists
            index_path = os.path.join(gallery_path, "index.txt")
            cache_dir = os.path.join(kw["cache_folder"], 'galleries')
            if not os.path.isdir(cache_dir):
                os.makedirs(cache_dir)
            index_dst_path = os.path.join(
                cache_dir,
                str(hashlib.sha224(index_path.encode('utf-8')).hexdigest() +
                    '.html'))
            if os.path.exists(index_path):
                compile_html = self.site.get_compiler(index_path).compile_html
                yield {
                    'basename': str('render_galleries'),
                    'name': index_dst_path,
                    'file_dep': [index_path],
                    'targets': [index_dst_path],
                    'actions': [(compile_html, [index_path, index_dst_path])],
                    'clean': True,
                    'uptodate': [utils.config_changed(kw)],
                }

            file_dep = self.site.template_system.template_deps(
                template_name) + image_list

            def render_gallery(output_name, context, index_dst_path):
                if os.path.exists(index_dst_path):
                    with codecs.open(index_dst_path, "rb", "utf8") as fd:
                        context['text'] = fd.read()
                    file_dep.append(index_dst_path)
                else:
                    context['text'] = ''
                self.site.render_template(template_name, output_name, context)

            yield {
                'basename': str('render_galleries'),
                'name': output_name,
                'file_dep': file_dep,
                'targets': [output_name],
                'actions': [(render_gallery, (output_name, context,
                                              index_dst_path))],
                'clean': True,
                'uptodate': [utils.config_changed({
                    1: kw,
                    2: self.site.config['GLOBAL_CONTEXT'],
                    3: self.site.config["COMMENTS_IN_GALLERIES"],
                })],
            }
开发者ID:dflock,项目名称:nikola,代码行数:101,代码来源:task_render_galleries.py


示例8: 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


示例9: 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


示例10: gen_tasks


#.........这里部分代码省略.........
                    "file_dep": [img],
                    "targets": [orig_dest_path],
                    "actions": [(self.resize_image, (img, orig_dest_path, kw["max_image_size"]))],
                    "clean": True,
                    "uptodate": [utils.config_changed(kw)],
                }

            # Remove excluded images
            if excluded_image_name_list:
                for img, img_name in zip(excluded_image_list, excluded_image_name_list):
                    # img_name is "image_name.jpg"
                    # fname, ext are "image_name", ".jpg"
                    fname, ext = os.path.splitext(img_name)
                    excluded_thumb_dest_path = os.path.join(output_gallery, ".thumbnail".join([fname, ext]))
                    excluded_dest_path = os.path.join(output_gallery, img_name)
                    yield {
                        "basename": str("render_galleries_clean"),
                        "name": excluded_thumb_dest_path,
                        "file_dep": [exclude_path],
                        #'targets': [excluded_thumb_dest_path],
                        "actions": [(utils.remove_file, (excluded_thumb_dest_path,))],
                        "clean": True,
                        "uptodate": [utils.config_changed(kw)],
                    }
                    yield {
                        "basename": str("render_galleries_clean"),
                        "name": excluded_dest_path,
                        "file_dep": [exclude_path],
                        #'targets': [excluded_dest_path],
                        "actions": [(utils.remove_file, (excluded_dest_path,))],
                        "clean": True,
                        "uptodate": [utils.config_changed(kw)],
                    }

            # Use galleries/name/index.txt to generate a blurb for
            # the gallery, if it exists.

            index_path = os.path.join(gallery_path, "index.txt")
            cache_dir = os.path.join(kw["cache_folder"], "galleries")
            if not os.path.isdir(cache_dir):
                os.makedirs(cache_dir)
            index_dst_path = os.path.join(
                cache_dir, str(hashlib.sha224(index_path.encode("utf-8")).hexdigest() + ".html")
            )
            if os.path.exists(index_path):
                compile_html = self.site.get_compiler(index_path).compile_html
                yield {
                    "basename": str("render_galleries"),
                    "name": index_dst_path,
                    "file_dep": [index_path],
                    "targets": [index_dst_path],
                    "actions": [(compile_html, [index_path, index_dst_path, True])],
                    "clean": True,
                    "uptodate": [utils.config_changed(kw)],
                }

            context = {}
            context["lang"] = kw["default_lang"]
            context["title"] = os.path.basename(gallery_path)
            context["description"] = kw["blog_description"]
            if kw["use_filename_as_title"]:
                img_titles = [
                    'id="{0}" alt="{1}" title="{2}"'.format(fn[:-4], fn[:-4], utils.unslugify(fn[:-4]))
                    for fn in image_name_list
                ]
            else:
                img_titles = [""] * len(image_name_list)
            # In the future, remove images from context, use photo_array
            context["images"] = list(zip(image_name_list, thumbs, img_titles))
            context["folders"] = folder_list
            context["crumbs"] = crumbs
            context["permalink"] = self.site.link("gallery", gallery_name, None)
            context["enable_comments"] = self.site.config["COMMENTS_IN_GALLERIES"]
            context["thumbnail_size"] = kw["thumbnail_size"]

            file_dep = self.site.template_system.template_deps(template_name) + image_list

            yield {
                "basename": str("render_galleries"),
                "name": output_name,
                "file_dep": file_dep,
                "targets": [output_name],
                "actions": [
                    (
                        self.render_gallery_index,
                        (template_name, output_name, context, index_dst_path, image_name_list, thumbs, file_dep, kw),
                    )
                ],
                "clean": True,
                "uptodate": [
                    utils.config_changed(
                        {
                            1: kw,
                            2: self.site.config["GLOBAL_CONTEXT"],
                            3: self.site.config["COMMENTS_IN_GALLERIES"],
                            4: context,
                        }
                    )
                ],
            }
开发者ID:ralsina,项目名称:nikola,代码行数:101,代码来源:galleries.py


示例11: gen_tasks


#.........这里部分代码省略.........
                    'uptodate': [utils.config_changed(kw)],
                }
                yield {
                    'basename': 'render_galleries',
                    'name': orig_dest_path,
                    'file_dep': [img],
                    'targets': [orig_dest_path],
                    'actions': [
                        (create_resized_image, (img, orig_dest_path))
                    ],
                    'clean': True,
                    'uptodate': [utils.config_changed(kw)],
                }

            # Remove excluded images
            if excluded_image_name_list:
                for img, img_name in zip(excluded_image_list,
                        excluded_image_name_list):
                    # img_name is "image_name.jpg"
                    # fname, ext are "image_name", ".jpg"
                    fname, ext = os.path.splitext(img_name)
                    excluded_thumb_dest_path = os.path.join(output_gallery,
                        fname + ".thumbnail" + ext)
                    excluded_dest_path = os.path.join(output_gallery, img_name)
                    yield {
                        'basename': 'render_galleries',
                        'name': excluded_thumb_dest_path,
                        'file_dep': [exclude_path],
                        #'targets': [excluded_thumb_dest_path],
                        'actions': [
                            (utils.remove_file, (excluded_thumb_dest_path,))
                        ],
                        'clean': True,
                        'uptodate': [utils.config_changed(kw)],
                    }
                    yield {
                        'basename': 'render_galleries',
                        'name': excluded_dest_path,
                        'file_dep': [exclude_path],
                        #'targets': [excluded_dest_path],
                        'actions': [
                            (utils.remove_file, (excluded_dest_path,))
                        ],
                        'clean': True,
                        'uptodate': [utils.config_changed(kw)],
                    }

            output_name = os.path.join(output_gallery, "index.html")
            context = {}
            context["lang"] = kw["default_lang"]
            context["title"] = os.path.basename(gallery_path)
            context["description"] = kw["blog_description"]
            if kw['use_filename_as_title']:
                img_titles = ['title="%s"' % utils.unslugify(fn[:-4])
                              for fn in image_name_list]
            else:
                img_titles = [''] * len(image_name_list)
            context["images"] = zip(image_name_list, thumbs, img_titles)
            context["permalink"] = self.site.link(
                "gallery", gallery_name, None)

            # Use galleries/name/index.txt to generate a blurb for
            # the gallery, if it exists
            index_path = os.path.join(gallery_path, "index.txt")
            index_dst_path = os.path.join(gallery_path, "index.html")
            if os.path.exists(index_path):
                compile_html = self.site.get_compiler(index_path)
                yield {
                    'basename': 'render_galleries',
                    'name': index_dst_path.encode('utf-8'),
                    'file_dep': [index_path],
                    'targets': [index_dst_path],
                    'actions': [(compile_html,
                        [index_path, index_dst_path])],
                    'clean': True,
                    'uptodate': [utils.config_changed(kw)],
                }

            file_dep = self.site.template_system.template_deps(
                template_name) + image_list

            def render_gallery(output_name, context, index_dst_path):
                if os.path.exists(index_dst_path):
                    with codecs.open(index_dst_path, "rb", "utf8") as fd:
                        context['text'] = fd.read()
                    file_dep.append(index_dst_path)
                else:
                    context['text'] = ''
                self.site.render_template(template_name, output_name, context)

            yield {
                'basename': 'render_galleries',
                'name': gallery_path,
                'file_dep': file_dep,
                'targets': [output_name],
                'actions': [(render_gallery,
                    (output_name, context, index_dst_path))],
                'clean': True,
                'uptodate': [utils.config_changed(kw)],
            }
开发者ID:sureshvv,项目名称:nikola,代码行数:101,代码来源:task_render_galleries.py


示例12: 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


示例13: gen_tasks


#.........这里部分代码省略.........
                thumbs.append(os.path.basename(thumb_path))
                yield {
                    "basename": "render_galleries",
                    "name": thumb_path,
                    "file_dep": [img],
                    "targets": [thumb_path],
                    "actions": [(self.resize_image, (img, thumb_path, kw["thumbnail_size"]))],
                    "clean": True,
                    "uptodate": [utils.config_changed(kw)],
                }
                yield {
                    "basename": "render_galleries",
                    "name": orig_dest_path,
                    "file_dep": [img],
                    "targets": [orig_dest_path],
                    "actions": [(self.resize_image, (img, orig_dest_path, kw["max_image_size"]))],
                    "clean": True,
                    "uptodate": [utils.config_changed(kw)],
                }

            # Remove excluded images
            if excluded_image_name_list:
                for img, img_name in zip(excluded_image_list, excluded_image_name_list):
                    # img_name is "image_name.jpg"
                    # fname, ext are "image_name", ".jpg"
                    fname, ext = os.path.splitext(img_name)
                    excluded_thumb_dest_path = os.path.join(output_gallery, fname + ".thumbnail" + ext)
                    excluded_dest_path = os.path.join(output_gallery, img_name)
                    yield {
                        "basename": "render_galleries",
                        "name": excluded_thumb_dest_path,
                        "file_dep": [exclude_path],
                        #'targets': [excluded_thumb_dest_path],
                        "actions": [(utils.remove_file, (excluded_thumb_dest_path,))],
                        "clean": True,
                        "uptodate": [utils.config_changed(kw)],
                    }
                    yield {
                        "basename": "render_galleries",
                        "name": excluded_dest_path,
                        "file_dep": [exclude_path],
                        #'targets': [excluded_dest_path],
                        "actions": [(utils.remove_file, (excluded_dest_path,))],
                        "clean": True,
                        "uptodate": [utils.config_changed(kw)],
                    }

            output_name = os.path.join(output_gallery, "index.html")
            context = {}
            context["lang"] = kw["default_lang"]
            context["title"] = os.path.basename(gallery_path)
            context["description"] = kw["blog_description"]
            if kw["use_filename_as_title"]:
                img_titles = ['title="%s"' % utils.unslugify(fn[:-4]) for fn in image_name_list]
            else:
                img_titles = [""] * len(image_name_list)
            context["images"] = zip(image_name_list, thumbs, img_titles)
            context["folders"] = folder_list
            context["crumbs"] = crumbs
            context["permalink"] = self.site.link("gallery", gallery_name, None)

            # Use galleries/name/index.txt to generate a blurb for
            # the gallery, if it exists
            index_path = os.path.join(gallery_path, "index.txt")
            cache_dir = os.path.join(kw["cache_folder"], "galleries")
            if not os.path.isdir(cache_dir):
                os.makedirs(cache_dir)
            index_dst_path = os.path.join(cache_dir, unicode(uuid.uuid1()) + ".html")
            if os.path.exists(index_path):
                compile_html = self.site.get_compiler(index_path)
                yield {
                    "basename": "render_galleries",
                    "name": index_dst_path.encode("utf-8"),
                    "file_dep": [index_path],
                    "targets": [index_dst_path],
                    "actions": [(compile_html, [index_path, index_dst_path])],
                    "clean": True,
                    "uptodate": [utils.config_changed(kw)],
                }

            file_dep = self.site.template_system.template_deps(template_name) + image_list

            def render_gallery(output_name, context, index_dst_path):
                if os.path.exists(index_dst_path):
                    with codecs.open(index_dst_path, "rb", "utf8") as fd:
                        context["text"] = fd.read()
                    file_dep.append(index_dst_path)
                else:
                    context["text"] = ""
                self.site.render_template(template_name, output_name, context)

            yield {
                "basename": "render_galleries",
                "name": output_name,
                "file_dep": file_dep,
                "targets": [output_name],
                "actions": [(render_gallery, (output_name, context, index_dst_path))],
                "clean": True,
                "uptodate": [utils.config_changed({1: kw, 2: self.site.config["GLOBAL_CONTEXT"]})],
            }
开发者ID:debspot,项目名称:nikola,代码行数:101,代码来源:task_render_galleries.py


示例14: gen_tasks

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.write_metadata函数代码示例发布时间:2022-05-27
下一篇:
Python utils.slugify函数代码示例发布时间: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