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

Python utils.write_metadata函数代码示例

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

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



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

示例1: test_write_metadata_with_formats

def test_write_metadata_with_formats():
    data = {'slug': 'hello-world', 'title': 'Hello, world!', 'b': '2', 'a': '1'}
    # Nikola: defaults first, then sorted alphabetically
    # YAML: all sorted alphabetically
    # TOML: insertion order (py3.6), random (py3.5 or older)
    assert write_metadata(data, 'nikola') == """\
.. title: Hello, world!
.. slug: hello-world
.. a: 1
.. b: 2

"""
    assert write_metadata(data, 'yaml') == """\
---
a: '1'
b: '2'
slug: hello-world
title: Hello, world!
---
"""
    toml = write_metadata(data, 'toml')
    assert toml.startswith('+++\n')
    assert toml.endswith('+++\n')
    assert 'slug = "hello-world"' in toml
    assert 'title = "Hello, world!"' in toml
    assert 'b = "2"' in toml
    assert 'a = "1"' in toml
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:27,代码来源:test_utils.py


示例2: test_write_metadata_from_site_and_fallbacks

def test_write_metadata_from_site_and_fallbacks():
    site = dummy()
    site.config = {'METADATA_FORMAT': 'yaml'}
    data = {'title': 'xx'}
    assert write_metadata(data, site=site) == '---\ntitle: xx\n---\n'
    assert write_metadata(data) == '.. title: xx\n\n'
    assert write_metadata(data, 'foo') == '.. title: xx\n\n'
    assert write_metadata(data, 'filename_regex') == '.. title: xx\n\n'
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:8,代码来源:test_utils.py


示例3: test_write_metadata_pelican_detection

def test_write_metadata_pelican_detection():
    rest_fake, md_fake, html_fake = dummy(), dummy(), dummy()
    rest_fake.name = 'rest'
    md_fake.name = 'markdown'
    html_fake.name = 'html'
    data = {'title': 'xx'}

    assert write_metadata(data, 'pelican', compiler=rest_fake) == '==\nxx\n==\n\n'
    assert write_metadata(data, 'pelican', compiler=md_fake) == 'title: xx\n\n'
    assert write_metadata(data, 'pelican', compiler=html_fake) == '.. title: xx\n\n'
    assert write_metadata(data, 'pelican', compiler=None) == '.. title: xx\n\n'
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:11,代码来源:test_utils.py


示例4: test_write_metadata_comment_wrap

def test_write_metadata_comment_wrap():
    data = {'title': 'Hello, world!', 'slug': 'hello-world'}
    assert write_metadata(data, 'nikola') == """\
.. title: Hello, world!
.. slug: hello-world

"""
    assert write_metadata(data, 'nikola', True) == """\
<!--
.. title: Hello, world!
.. slug: hello-world
-->

"""
    assert write_metadata(data, 'nikola', ('111', '222')) == """\
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:15,代码来源:test_utils.py


示例5: create_post

    def create_post(self, path, **kw):
        content = kw.pop('content', None)
        onefile = kw.pop('onefile', False)
        kw.pop('is_page', False)

        metadata = OrderedDict()
        metadata.update(self.default_metadata)
        metadata.update(kw)
        makedirs(os.path.dirname(path))

        with codecs.open(path, "wb+", "utf8") as fd:
            if onefile:
                fd.write("#+BEGIN_COMMENT\n")
                if write_metadata:
                    fd.write(write_metadata(metadata))
                else:
                    for k, v in metadata.items():
                        fd.write('.. {0}: {1}\n'.format(k, v))
                fd.write("#+END_COMMENT\n")
                fd.write("\n\n")

            if content:
                fd.write(content)
            else:
                fd.write('Write your post here.')
开发者ID:MarkWh1te,项目名称:blackmagic,代码行数:25,代码来源:orgmode.py


示例6: create_post

 def create_post(self, path, **kw):
     """Create a new post."""
     content = kw.pop('content', None)
     onefile = kw.pop('onefile', False)
     # is_page is not used by create_post as of now.
     kw.pop('is_page', False)
     metadata = {}
     metadata.update(self.default_metadata)
     metadata.update(kw)
     if not metadata['description']:
         # For PHP, a description must be set.  Otherwise, Nikola will
         # take the first 200 characters of the post as the Open Graph
         # description (og:description meta element)!
         # If the PHP source leaks there:
         # (a) The script will be executed multiple times
         # (b) PHP may encounter a syntax error if it cuts too early,
         #     therefore completely breaking the page
         # Here, we just use the title.  The user should come up with
         # something better, but just using the title does the job.
         metadata['description'] = metadata['title']
     makedirs(os.path.dirname(path))
     if not content.endswith('\n'):
         content += '\n'
     with io.open(path, "w+", encoding="utf8") as fd:
         if onefile:
             fd.write(write_metadata(metadata, comment_wrap=True, site=self.site, compiler=self))
         fd.write(content)
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:27,代码来源:php.py


示例7: test_write_metadata_compiler

def test_write_metadata_compiler():
    data = {'title': 'Hello, world!', 'slug': 'hello-world'}
    assert write_metadata(data, 'rest_docinfo') == """\
=============
Hello, world!
=============

:slug: hello-world
"""
    assert write_metadata(data, 'markdown_meta') in ("""\
title: Hello, world!
slug: hello-world

""", """slug: hello-world
title: Hello, world!

""")
开发者ID:FelixSchwarz,项目名称:nikola,代码行数:17,代码来源:test_utils.py


示例8: write_metadata

    def write_metadata(filename, title, slug, post_date, description, tags, **kwargs):
        if not description:
            description = ""

        utils.makedirs(os.path.dirname(filename))
        with io.open(filename, "w+", encoding="utf8") as fd:
            data = {'title': title, 'slug': slug, 'date': post_date, 'tags': ','.join(tags), 'description': description}
            data.update(kwargs)
            fd.write(utils.write_metadata(data))
开发者ID:anweshknayak,项目名称:nikola,代码行数:9,代码来源:basic_import.py


示例9: write_metadata

    def write_metadata(filename, title, slug, post_date, description, tags, **kwargs):
        """Write metadata to meta file."""
        if not description:
            description = ""

        utils.makedirs(os.path.dirname(filename))
        with io.open(filename, "w+", encoding="utf8") as fd:
            data = {"title": title, "slug": slug, "date": post_date, "tags": ",".join(tags), "description": description}
            data.update(kwargs)
            fd.write(utils.write_metadata(data))
开发者ID:bspeice,项目名称:nikola,代码行数:10,代码来源:basic_import.py


示例10: write_metadata

    def write_metadata(self, filename, title, slug, post_date, description, tags, **kwargs):
        """Write metadata to meta file."""
        if not description:
            description = ""

        utils.makedirs(os.path.dirname(filename))
        with io.open(filename, "w+", encoding="utf8") as fd:
            data = {'title': title, 'slug': slug, 'date': post_date, 'tags': ','.join(tags), 'description': description}
            data.update(kwargs)
            fd.write(utils.write_metadata(data, site=self.site, comment_wrap=False))
开发者ID:uli-heller,项目名称:nikola,代码行数:10,代码来源:basic_import.py


示例11: create_post

 def create_post(self, path, content=None, onefile=False, is_page=False, **kw):
     """Create post file with optional metadata."""
     metadata = OrderedDict()
     metadata.update(self.default_metadata)
     metadata.update(kw)
     makedirs(os.path.dirname(path))
     if not content.endswith('\n'):
         content += '\n'
     with codecs.open(path, "wb+", "utf8") as fd:
         if onefile:
             fd.write("////\n")
             fd.write(write_metadata(metadata))
             fd.write("////\n")
         fd.write(content)
开发者ID:eclipse,项目名称:mosquitto,代码行数:14,代码来源:docbookmanpage.py


示例12: create_post

 def create_post(self, path, **kw):
     content = kw.pop('content', 'Write your post here.')
     one_file = kw.pop('onefile', False)  # NOQA
     is_page = kw.pop('is_page', False)  # NOQA
     metadata = OrderedDict()
     metadata.update(self.default_metadata)
     metadata.update(kw)
     makedirs(os.path.dirname(path))
     if not content.endswith('\n'):
         content += '\n'
     with codecs.open(path, "wb+", "utf8") as fd:
         if one_file:
             fd.write(write_metadata(metadata))
             fd.write('\n')
         fd.write(content)
开发者ID:getnikola,项目名称:plugins,代码行数:15,代码来源:__init__.py


示例13: create_post

 def create_post(self, path, **kw):
     content = kw.pop('content', None)
     onefile = kw.pop('onefile', False)
     # is_page is not used by create_post as of now.
     kw.pop('is_page', False)
     metadata = {}
     metadata.update(self.default_metadata)
     metadata.update(kw)
     makedirs(os.path.dirname(path))
     if not content.endswith('\n'):
         content += '\n'
     with io.open(path, "w+", encoding="utf8") as fd:
         if onefile:
             fd.write(write_metadata(metadata))
         fd.write('\n' + content)
开发者ID:anweshknayak,项目名称:nikola,代码行数:15,代码来源:__init__.py


示例14: create_post

 def create_post(self, path, content, onefile=False, is_page=False, **kw):
     content = kw.pop("content", "Write your post here.")
     onefile = kw.pop("onefile", False)
     kw.pop("is_page", False)
     metadata = OrderedDict()
     metadata.update(self.default_metadata)
     metadata.update(kw)
     makedirs(os.path.dirname(path))
     if not content.endswith("\n"):
         content += "\n"
     with codecs.open(path, "wb+", "utf8") as fd:
         if onefile:
             fd.write("<!-- \n")
             fd.write(write_metadata(metadata))
             fd.write("-->\n\n")
         fd.write(content)
开发者ID:bronsen,项目名称:plugins,代码行数:16,代码来源:misaka.py


示例15: create_post

 def create_post(self, path, **kw):
     content = kw.pop('content', None)
     onefile = kw.pop('onefile', False)
     kw.pop('is_page', False)
     metadata = OrderedDict()
     metadata.update(self.default_metadata)
     metadata.update(kw)
     makedirs(os.path.dirname(path))
     if not content.endswith('\n'):
         content += '\n'
     with codecs.open(path, "wb+", "utf8") as fd:
         if onefile:
             fd.write('<notextile>  <!--\n')
             fd.write(write_metadata(metadata))
             fd.write('--></notextile>\n\n')
         fd.write(content)
开发者ID:michaeljoseph,项目名称:nikola-plugins,代码行数:16,代码来源:textile.py


示例16: create_post

 def create_post(self, path, **kw):
     """Create a new post."""
     content = kw.pop('content', None)
     onefile = kw.pop('onefile', False)
     # is_page is not used by create_post as of now.
     kw.pop('is_page', False)
     metadata = {}
     metadata.update(self.default_metadata)
     metadata.update(kw)
     makedirs(os.path.dirname(path))
     if not content.endswith('\n'):
         content += '\n'
     with io.open(path, "w+", encoding="utf8") as fd:
         if onefile:
             fd.write(write_metadata(metadata, comment_wrap=('///', '///'), site=self.site, compiler=self))
         fd.write(content)
开发者ID:getnikola,项目名称:plugins,代码行数:16,代码来源:asciidoc.py


示例17: create_post

 def create_post(self, path, **kw):
     """Create a new post."""
     content = kw.pop("content", None)
     onefile = kw.pop("onefile", False)
     # is_page is not used by create_post as of now.
     kw.pop("is_page", False)
     metadata = {}
     metadata.update(self.default_metadata)
     metadata.update(kw)
     makedirs(os.path.dirname(path))
     if not content.endswith("\n"):
         content += "\n"
     with io.open(path, "w+", encoding="utf8") as fd:
         if onefile:
             fd.write(write_metadata(metadata))
             fd.write("\n")
         fd.write(content)
开发者ID:bspeice,项目名称:nikola,代码行数:17,代码来源:__init__.py


示例18: create_post

 def create_post(self, path, **kw):
     content = kw.pop('content', 'Write your post here.')
     onefile = kw.pop('onefile', False)
     # is_page is not used by create_post as of now.
     kw.pop('is_page', False)
     metadata = {}
     metadata.update(self.default_metadata)
     metadata.update(kw)
     makedirs(os.path.dirname(path))
     if not content.endswith('\n'):
         content += '\n'
     with codecs.open(path, "wb+", "utf8") as fd:
         if onefile:
             fd.write("\n'''\n<!--\n")
             fd.write(write_metadata(metadata))
             fd.write("-->\n'''\n")
         fd.write(content)
开发者ID:ChillarAnand,项目名称:plugins,代码行数:17,代码来源:txt2tags.py


示例19: create_post

    def create_post(self, path, content=None, onefile=False, is_page=False, **kw):
        """Create post file with optional metadata."""
        metadata = OrderedDict()
        metadata.update(self.default_metadata)
        metadata.update(kw)
        makedirs(os.path.dirname(path))

        with io.open(path, "w+", encoding="utf-8") as fd:
            if onefile:
                fd.write("#+BEGIN_COMMENT\n")
                if write_metadata:
                    fd.write(write_metadata(metadata))
                else:
                    for k, v in metadata.items():
                        fd.write('.. {0}: {1}\n'.format(k, v))
                fd.write("#+END_COMMENT\n")
                fd.write("\n\n")

            if content:
                fd.write(content)
            else:
                fd.write('Write your post here.')
开发者ID:necromuralist,项目名称:graeae,代码行数:22,代码来源:orgmode.py


示例20: _execute


#.........这里部分代码省略.........
            while not title:
                title = utils.ask('Title')

        if isinstance(title, utils.bytes_str):
            try:
                title = title.decode(sys.stdin.encoding)
            except (AttributeError, TypeError):  # for tests
                title = title.decode('utf-8')

        title = title.strip()
        if not path:
            slug = utils.slugify(title)
        else:
            if isinstance(path, utils.bytes_str):
                try:
                    path = path.decode(sys.stdin.encoding)
                except (AttributeError, TypeError):  # for tests
                    path = path.decode('utf-8')
            slug = utils.slugify(os.path.splitext(os.path.basename(path))[0])

        if isinstance(author, utils.bytes_str):
                try:
                    author = author.decode(sys.stdin.encoding)
                except (AttributeError, TypeError):  # for tests
                    author = author.decode('utf-8')

        # Calculate the date to use for the content
        schedule = options['schedule'] or self.site.config['SCHEDULE_ALL']
        rule = self.site.config['SCHEDULE_RULE']
        self.site.scan_posts()
        timeline = self.site.timeline
        last_date = None if not timeline else timeline[0].date
        date = get_date(schedule, rule, last_date, self.site.tzinfo, self.site.config['FORCE_ISO8601'])
        data = {
            'title': title,
            'slug': slug,
            'date': date,
            'tags': tags,
            'link': '',
            'description': '',
            'type': 'text',
        }
        output_path = os.path.dirname(entry[0])
        meta_path = os.path.join(output_path, slug + ".meta")
        pattern = os.path.basename(entry[0])
        suffix = pattern[1:]
        if not path:
            txt_path = os.path.join(output_path, slug + suffix)
        else:
            txt_path = path

        if (not onefile and os.path.isfile(meta_path)) or \
                os.path.isfile(txt_path):
            LOGGER.error("The title already exists!")
            exit(8)

        d_name = os.path.dirname(txt_path)
        utils.makedirs(d_name)
        metadata = {}
        if author:
            metadata['author'] = author
        metadata.update(self.site.config['ADDITIONAL_METADATA'])
        data.update(metadata)

        # Override onefile if not really supported.
        if not compiler_plugin.supports_onefile and onefile:
            onefile = False
            LOGGER.warn('This compiler does not support one-file posts.')

        if import_file:
            with io.open(import_file, 'r', encoding='utf-8') as fh:
                content = fh.read()
        else:
            # ipynb's create_post depends on this exact string, take care
            # if you're changing it
            content = "Write your {0} here.".format('page' if is_page else 'post')
        compiler_plugin.create_post(
            txt_path, content=content, onefile=onefile, title=title,
            slug=slug, date=date, tags=tags, is_page=is_page, **metadata)

        event = dict(path=txt_path)

        if not onefile:  # write metadata file
            with io.open(meta_path, "w+", encoding="utf8") as fd:
                fd.write(utils.write_metadata(data))
            LOGGER.info("Your {0}'s metadata is at: {1}".format(content_type, meta_path))
            event['meta_path'] = meta_path
        LOGGER.info("Your {0}'s text is at: {1}".format(content_type, txt_path))

        signal('new_' + content_type).send(self, **event)

        if options['edit']:
            editor = os.getenv('EDITOR', '').split()
            to_run = editor + [txt_path]
            if not onefile:
                to_run.append(meta_path)
            if editor:
                subprocess.call(to_run)
            else:
                LOGGER.error('$EDITOR not set, cannot edit the post.  Please do it manually.')
开发者ID:Nolski,项目名称:nikola,代码行数:101,代码来源:new_post.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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