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

Python utils.create_media_urls函数代码示例

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

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



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

示例1: get_context

def get_context(nav, config, page=None):
    """
    Given the SiteNavigation and config, generate the context which is relevant
    to app pages.
    """

    if nav is None:
        return {'page', page}

    extra_javascript = utils.create_media_urls(nav, config['extra_javascript'])

    extra_css = utils.create_media_urls(nav, config['extra_css'])

    # Support SOURCE_DATE_EPOCH environment variable for "reproducible" builds.
    # See https://reproducible-builds.org/specs/source-date-epoch/
    timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', timegm(datetime.utcnow().utctimetuple())))

    return {
        'nav': nav,
        # base_url should never end with a slash.
        'base_url': nav.url_context.make_relative('/').rstrip('/'),

        'extra_css': extra_css,
        'extra_javascript': extra_javascript,

        'mkdocs_version': mkdocs.__version__,
        'build_date_utc': datetime.utcfromtimestamp(timestamp),

        'config': config,
        'page': page,
    }
开发者ID:jimporter,项目名称:mkdocs,代码行数:31,代码来源:build.py


示例2: get_context

def get_context(nav, files, config, page=None, base_url=''):
    """
    Return the template context for a given page or template.
    """

    if page is not None:
        base_url = utils.get_relative_url('.', page.url)

    extra_javascript = utils.create_media_urls(config['extra_javascript'], page, base_url)

    extra_css = utils.create_media_urls(config['extra_css'], page, base_url)

    # Support SOURCE_DATE_EPOCH environment variable for "reproducible" builds.
    # See https://reproducible-builds.org/specs/source-date-epoch/
    timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', timegm(datetime.utcnow().utctimetuple())))

    return {
        'nav': nav,
        'pages': files.documentation_pages(),

        'base_url': base_url,

        'extra_css': extra_css,
        'extra_javascript': extra_javascript,

        'mkdocs_version': mkdocs.__version__,
        'build_date_utc': datetime.utcfromtimestamp(timestamp),

        'config': config,
        'page': page,
    }
开发者ID:mkdocs,项目名称:mkdocs,代码行数:31,代码来源:build.py


示例3: get_global_context

def get_global_context(nav, config):
    """
    Given the SiteNavigation and config, generate the context which is relevant
    to app pages.
    """

    site_name = config['site_name']

    if config['site_favicon']:
        site_favicon = nav.url_context.make_relative('/' + config['site_favicon'])
    else:
        site_favicon = None

    page_description = config['site_description']

    extra_javascript = utils.create_media_urls(nav, config['extra_javascript'])

    extra_css = utils.create_media_urls(nav, config['extra_css'])

    # Support SOURCE_DATE_EPOCH environment variable for "reproducible" builds.
    # See https://reproducible-builds.org/specs/source-date-epoch/
    timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', timegm(datetime.utcnow().utctimetuple())))

    return {
        'site_name': site_name,
        'site_author': config['site_author'],
        'favicon': site_favicon,
        'page_description': page_description,

        # Note that there's intentionally repetition here. Rather than simply
        # provide the config dictionary we instead pass everything explicitly.
        #
        # This helps ensure that we can throughly document the context that
        # gets passed to themes.
        'repo_url': config['repo_url'],
        'repo_name': config['repo_name'],
        'nav': nav,
        'base_url': nav.url_context.make_relative('/'),
        'homepage_url': nav.homepage.url,
        'site_url': config['site_url'],

        'extra_css': extra_css,
        'extra_javascript': extra_javascript,

        'include_nav': config['include_nav'],
        'include_next_prev': config['include_next_prev'],

        'copyright': config['copyright'],
        'google_analytics': config['google_analytics'],

        'mkdocs_version': mkdocs.__version__,
        'build_date_utc': datetime.utcfromtimestamp(timestamp),

        'config': config
    }
开发者ID:CIS-rdbrown,项目名称:mkdocs,代码行数:55,代码来源:build.py


示例4: get_global_context

def get_global_context(nav, config):
    """
    Given the SiteNavigation and config, generate the context which is relevant
    to app pages.
    """

    site_name = config['site_name']

    if config['site_favicon']:
        site_favicon = nav.url_context.make_relative('/' + config['site_favicon'])
    else:
        site_favicon = None

    page_description = config['site_description']

    extra_javascript = utils.create_media_urls(nav, config['extra_javascript'])

    extra_css = utils.create_media_urls(nav, config['extra_css'])

    return {
        'site_name': site_name,
        'site_author': config['site_author'],
        'favicon': site_favicon,
        'page_description': page_description,

        # Note that there's intentionally repetition here. Rather than simply
        # provide the config dictionary we instead pass everything explicitly.
        #
        # This helps ensure that we can throughly document the context that
        # gets passed to themes.
        'repo_url': config['repo_url'],
        'repo_name': config['repo_name'],
        'repo_branch': config['repo_branch'],
        'repo_docs_dir': config['repo_docs_dir'],
        'docs_dir': config['docs_dir'],
        'nav': nav,
        'base_url': nav.url_context.make_relative('/'),
        'homepage_url': nav.homepage.url,
        'site_url': config['site_url'],

        'extra_css': extra_css,
        'extra_javascript': extra_javascript,

        'include_nav': config['include_nav'],
        'include_next_prev': config['include_next_prev'],

        'copyright': config['copyright'],
        'google_analytics': config['google_analytics'],

        'mkdocs_version': mkdocs.__version__,
        'build_date_utc': datetime.utcnow(),

        'config': config
    }
开发者ID:dmehra,项目名称:mkdocs,代码行数:54,代码来源:build.py


示例5: test_create_media_urls

    def test_create_media_urls(self):

        expected_results = {
            'https://media.cdn.org/jq.js': [
                'https://media.cdn.org/jq.js',
                'https://media.cdn.org/jq.js',
                'https://media.cdn.org/jq.js'
            ],
            'http://media.cdn.org/jquery.js': [
                'http://media.cdn.org/jquery.js',
                'http://media.cdn.org/jquery.js',
                'http://media.cdn.org/jquery.js'
            ],
            '//media.cdn.org/jquery.js': [
                '//media.cdn.org/jquery.js',
                '//media.cdn.org/jquery.js',
                '//media.cdn.org/jquery.js'
            ],
            'media.cdn.org/jquery.js': [
                'media.cdn.org/jquery.js',
                'media.cdn.org/jquery.js',
                '../media.cdn.org/jquery.js'
            ],
            'local/file/jquery.js': [
                'local/file/jquery.js',
                'local/file/jquery.js',
                '../local/file/jquery.js'
            ],
            'local\\windows\\file\\jquery.js': [
                'local/windows/file/jquery.js',
                'local/windows/file/jquery.js',
                '../local/windows/file/jquery.js'
            ],
            'image.png': [
                'image.png',
                'image.png',
                '../image.png'
            ],
            'style.css?v=20180308c': [
                'style.css?v=20180308c',
                'style.css?v=20180308c',
                '../style.css?v=20180308c'
            ],
            '#some_id': [
                '#some_id',
                '#some_id',
                '#some_id'
            ]
        }

        cfg = load_config(use_directory_urls=False)
        pages = [
            Page('Home', File('index.md',  cfg['docs_dir'], cfg['site_dir'], cfg['use_directory_urls']), cfg),
            Page('About', File('about.md',  cfg['docs_dir'], cfg['site_dir'], cfg['use_directory_urls']), cfg),
            Page('FooBar', File('foo/bar.md',  cfg['docs_dir'], cfg['site_dir'], cfg['use_directory_urls']), cfg)
        ]

        for i, page in enumerate(pages):
            urls = utils.create_media_urls(expected_results.keys(), page)
            self.assertEqual([v[i] for v in expected_results.values()], urls)
开发者ID:mkdocs,项目名称:mkdocs,代码行数:60,代码来源:utils_tests.py


示例6: __call__

    def __call__(self, match):
        url = match.groups()[0]
        scheme, netloc, path, query, query, fragment = urlparse(url)

        if scheme or netloc or not path:
            # Ignore URLs unless they are a relative link to a markdown file.
            return self.template % url

        if self.nav and not utils.is_markdown_file(path):
            path = utils.create_media_urls(self.nav, [path])[0]
        elif self.nav:
            # If the site navigation has been provided, then validate
            # the internal hyperlink, making sure the target actually exists.
            target_file = self.nav.file_context.make_absolute(path)
            if target_file not in self.nav.source_files:
                source_file = self.nav.file_context.current_file
                msg = 'The page "%s" contained a hyperlink to "%s" which ' 'is not listed in the "pages" configuration.'
                assert False, msg % (source_file, target_file)
            path = utils.get_url_path(target_file, self.nav.use_directory_urls)
            path = self.nav.url_context.make_relative(path)
        else:
            path = utils.get_url_path(path).lstrip("/")

        # Convert the .md hyperlink to a relative hyperlink to the HTML page.
        url = urlunparse((scheme, netloc, path, query, query, fragment))
        return self.template % url
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:26,代码来源:build.py


示例7: get_global_context

def get_global_context(nav, config):
    """
    Given the SiteNavigation and config, generate the context which is relevant
    to app pages.
    """

    extra_javascript = utils.create_media_urls(nav, config['extra_javascript'])

    extra_css = utils.create_media_urls(nav, config['extra_css'])

    # Support SOURCE_DATE_EPOCH environment variable for "reproducible" builds.
    # See https://reproducible-builds.org/specs/source-date-epoch/
    timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', timegm(datetime.utcnow().utctimetuple())))

    return {
        'nav': nav,
        # base_url should never end with a slash.
        'base_url': nav.url_context.make_relative('/').rstrip('/'),

        'extra_css': extra_css,
        'extra_javascript': extra_javascript,

        'mkdocs_version': mkdocs.__version__,
        'build_date_utc': datetime.utcfromtimestamp(timestamp),

        'config': config,

        # TODO: remove the rest in 1.0 as they are deprecated
        'site_name': config['site_name'],
        'site_url': config['site_url'],
        'site_author': config['site_author'],
        'homepage_url': nav.homepage.url,
        'page_description': config['site_description'],
        'favicon': config['site_favicon'],

        'repo_url': config['repo_url'],
        'repo_name': config['repo_name'],

        'include_nav': config['include_nav'],
        'include_next_prev': config['include_next_prev'],

        'copyright': config['copyright'],
        'google_analytics': config['google_analytics']
    }
开发者ID:Blue-Design,项目名称:mkdocs,代码行数:44,代码来源:build.py


示例8: get_global_context

def get_global_context(nav, config):
    """
    Given the SiteNavigation and config, generate the context which is relevant
    to app pages.
    """

    site_name = config["site_name"]

    if config["site_favicon"]:
        site_favicon = nav.url_context.make_relative("/" + config["site_favicon"])
    else:
        site_favicon = None

    page_description = config["site_description"]

    extra_javascript = utils.create_media_urls(nav=nav, url_list=config["extra_javascript"])

    extra_css = utils.create_media_urls(nav=nav, url_list=config["extra_css"])

    return {
        "site_name": site_name,
        "site_author": config["site_author"],
        "favicon": site_favicon,
        "page_description": page_description,
        # Note that there's intentionally repetition here. Rather than simply
        # provide the config dictionary we instead pass everything explicitly.
        #
        # This helps ensure that we can throughly document the context that
        # gets passed to themes.
        "repo_url": config["repo_url"],
        "repo_name": config["repo_name"],
        "nav": nav,
        "base_url": nav.url_context.make_relative("/"),
        "homepage_url": nav.homepage.url,
        "extra_css": extra_css,
        "extra_javascript": extra_javascript,
        "include_nav": config["include_nav"],
        "include_next_prev": config["include_next_prev"],
        "include_search": config["include_search"],
        "copyright": config["copyright"],
        "google_analytics": config["google_analytics"],
    }
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:42,代码来源:build.py


示例9: test_create_media_urls

 def test_create_media_urls(self):
     pages = [("index.md", "Home"), ("about.md", "About")]
     expected_results = {
         "https://media.cdn.org/jquery.js": "https://media.cdn.org/jquery.js",
         "http://media.cdn.org/jquery.js": "http://media.cdn.org/jquery.js",
         "//media.cdn.org/jquery.js": "//media.cdn.org/jquery.js",
         "media.cdn.org/jquery.js": "./media.cdn.org/jquery.js",
         "local/file/jquery.js": "./local/file/jquery.js",
     }
     site_navigation = nav.SiteNavigation(pages)
     for path, expected_result in expected_results.items():
         urls = utils.create_media_urls(site_navigation, [path])
         self.assertEqual(urls[0], expected_result)
开发者ID:jpush,项目名称:mkdocs,代码行数:13,代码来源:test.py


示例10: test_create_media_urls

 def test_create_media_urls(self):
     pages = [
         ('index.md', 'Home'),
         ('about.md', 'About')
     ]
     expected_results = {
         'https://media.cdn.org/jquery.js': 'https://media.cdn.org/jquery.js',
         'http://media.cdn.org/jquery.js': 'http://media.cdn.org/jquery.js',
         '//media.cdn.org/jquery.js': '//media.cdn.org/jquery.js',
         'media.cdn.org/jquery.js': './media.cdn.org/jquery.js',
         'local/file/jquery.js': './local/file/jquery.js',
     }
     site_navigation = nav.SiteNavigation(pages)
     for path, expected_result in expected_results.items():
         urls = utils.create_media_urls(site_navigation, [path])
         self.assertEqual(urls[0], expected_result)
开发者ID:Argoday,项目名称:mkdocs,代码行数:16,代码来源:utils_tests.py


示例11: test_create_media_urls

    def test_create_media_urls(self):
        pages = [
            {'Home': 'index.md'},
            {'About': 'about.md'},
            {'Sub': [
                {'Sub Home': 'index.md'},
                {'Sub About': 'about.md'},

            ]}
        ]
        expected_results = {
            'https://media.cdn.org/jq.js': 'https://media.cdn.org/jq.js',
            'http://media.cdn.org/jquery.js': 'http://media.cdn.org/jquery.js',
            '//media.cdn.org/jquery.js': '//media.cdn.org/jquery.js',
            'media.cdn.org/jquery.js': './media.cdn.org/jquery.js',
            'local/file/jquery.js': './local/file/jquery.js',
            'image.png': './image.png',
        }
        site_navigation = nav.SiteNavigation(load_config(pages=pages))
        for path, expected_result in expected_results.items():
            urls = utils.create_media_urls(site_navigation, [path])
            self.assertEqual(urls[0], expected_result)
开发者ID:marcelstoer,项目名称:mkdocs,代码行数:22,代码来源:utils_tests.py


示例12: get_context

def get_context(page, content, nav, toc, meta, config):
    site_name = config['site_name']

    if page.is_homepage or page.title is None:
        page_title = site_name
    else:
        page_title = page.title + ' - ' + site_name

    if page.is_homepage:
        page_description = config['site_description']
    else:
        page_description = None

    if config['site_url']:
        base = config['site_url']
        if not base.endswith('/'):
            base += '/'
        canonical_url = urljoin(base, page.abs_url.lstrip('/'))
    else:
        canonical_url = None

    if config['site_favicon']:
        site_favicon = nav.url_context.make_relative('/' + config['site_favicon'])
    else:
        site_favicon = None

    if config['extra_javascript']:
        config['extra_javascript'] = utils.create_media_urls(nav=nav, url_list=config['extra_javascript'])

    if config['extra_css']:
        config['extra_css'] = utils.create_media_urls(nav=nav, url_list=config['extra_css'])

    return {
        'site_name': site_name,
        'site_author': config['site_author'],
        'favicon': site_favicon,

        'page_title': page_title,
        'page_description': page_description,

        'content': content,
        'toc': toc,
        'nav': nav,
        'meta': meta,

        'base_url': nav.url_context.make_relative('/'),
        'homepage_url': nav.homepage.url,
        'canonical_url': canonical_url,

        'current_page': page,
        'previous_page': page.previous_page,
        'next_page': page.next_page,

        # Note that there's intentionally repetition here. Rather than simply
        # provide the config dictionary we instead pass everything explicitly.
        #
        # This helps ensure that we can throughly document the context that
        # gets passed to themes.
        'repo_url': config['repo_url'],
        'repo_name': config['repo_name'],

        'extra_css': config['extra_css'],
        'extra_javascript': config['extra_javascript'],

        'include_nav': config['include_nav'],
        'include_next_prev': config['include_next_prev'],
        'include_search': config['include_search'],

        'copyright': config['copyright'],
        'google-analytics': config['google-analytics']
    }
开发者ID:dnrce,项目名称:mkdocs,代码行数:71,代码来源:build.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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