mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 09:58:31 +07:00
Add ability to include third party URLs in extra_*
This commit is contained in:
@@ -103,6 +103,12 @@ def get_context(page, content, nav, toc, meta, config):
|
||||
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'],
|
||||
|
||||
@@ -105,6 +105,23 @@ class UtilsTests(unittest.TestCase):
|
||||
is_html = utils.is_html_file(path)
|
||||
self.assertEqual(is_html, expected_result)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
class TableOfContentsTests(unittest.TestCase):
|
||||
def markdown_to_toc(self, markdown_source):
|
||||
|
||||
@@ -7,6 +7,7 @@ Nothing in this module should have an knowledge of config or the layout
|
||||
and structure of the site and pages in the site.
|
||||
"""
|
||||
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
@@ -128,3 +129,17 @@ def is_html_file(path):
|
||||
'.html',
|
||||
'.htm',
|
||||
]
|
||||
|
||||
def create_media_urls(nav, url_list):
|
||||
"""
|
||||
Return a list of URLs that have been processed correctly for inclusion in a page.
|
||||
"""
|
||||
final_urls = []
|
||||
for url in url_list:
|
||||
# Allow links to fully qualified URL's
|
||||
if '//' in url:
|
||||
final_urls.append(url)
|
||||
else:
|
||||
relative_url = '%s/%s' % (nav.url_context.make_relative('/'), url)
|
||||
final_urls.append(relative_url)
|
||||
return final_urls
|
||||
|
||||
Reference in New Issue
Block a user