当前位置: 首页>>代码示例>>Python>>正文


Python utils.write_metadata函数代码示例

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


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


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