Skip to content

Commit

Permalink
Revert "Ensure site_url and use_directory_urls do not conflict." (#2490)
Browse files Browse the repository at this point in the history
This reverts commit b89ec57.

That commit claims to fix some bugs in interactions with `use_directory_urls`, but in fact there are currently no known unfixed bugs.
So there is no need to have that breaking change.
  • Loading branch information
oprypin committed Jul 12, 2021
1 parent 47d7571 commit ae55657
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 217 deletions.
10 changes: 3 additions & 7 deletions docs/user-guide/configuration.md
Expand Up @@ -28,11 +28,8 @@ variable.

### site_url

Set the canonical URL of the site. This is a **required setting**. If the
'root' of the MkDocs site will be within a subdirectory of a domain, be sure to
include that subdirectory in the setting (`https://example.com/foo/`). If the
domain is yet to be determined, you may use a placeholder domain, which will
need to be updated prior to deployment.
Set the canonical URL of the site. This will add a link tag with the canonical
URL to the generated HTML header.

If the built site will not be behind a server, then you may set the value to an
empty string (`''`). When set to an empty string, some features of MkDocs may
Expand Down Expand Up @@ -373,8 +370,7 @@ and is usually what you'll want to use.
The alternate style can be useful if you want your documentation to remain
properly linked when opening pages directly from the file system, because it
creates links that point directly to the target *file* rather than the target
*directory*. In fact, this setting **must be** `false` if [site_url](#site_url)
is set to an emtpy string.
*directory*.

**default**: `true`

Expand Down
4 changes: 1 addition & 3 deletions mkdocs/commands/new.py
@@ -1,9 +1,7 @@
import logging
import os

config_text = """site_name: My Docs
site_url: https://example.com/
"""
config_text = 'site_name: My Docs\n'
index_text = """# Welcome to MkDocs
For full documentation visit [mkdocs.org](https://www.mkdocs.org).
Expand Down
19 changes: 0 additions & 19 deletions mkdocs/config/config_options.py
Expand Up @@ -292,15 +292,6 @@ def __init__(self, default='', required=False, is_dir=False):
self.is_dir = is_dir
super().__init__(default, required)

def pre_validation(self, config, key_name):
# TODO: replace this with an error in a future release (1.3?)
user_defined_keys = sum([list(x.keys()) for x in config.user_configs], [])
if key_name == 'site_url' and key_name not in user_defined_keys:
self.warnings.append(
'This option is now required. Set to a valid URL or '
'an empty string to avoid an error in a future release.'
)

def run_validation(self, value):
if value == '':
return value
Expand All @@ -318,16 +309,6 @@ def run_validation(self, value):
raise ValidationError(
"The URL isn't valid, it should include the http:// (scheme)")

def post_validation(self, config, key_name):
if key_name == 'site_url':
if config[key_name] in ['', None] and config['use_directory_urls']:
config['use_directory_urls'] = False
self.warnings.append(
"The 'use_directory_urls' option has been disabled because "
"'site_url' contains an empty value. Either define a valid "
"URL for 'site_url' or set 'use_directory_urls' to False."
)


class RepoURL(URL):
"""
Expand Down
2 changes: 1 addition & 1 deletion mkdocs/config/defaults.py
Expand Up @@ -24,7 +24,7 @@ def get_schema():
('pages', config_options.Nav()),

# The full URL to where the documentation will be hosted
('site_url', config_options.URL(is_dir=True, required=True)),
('site_url', config_options.URL(is_dir=True)),

# A description for the documentation project that will be added to the
# HTML meta tags.
Expand Down
5 changes: 1 addition & 4 deletions mkdocs/tests/base.py
Expand Up @@ -5,7 +5,6 @@
from tempfile import TemporaryDirectory

from mkdocs import config
from mkdocs.config.defaults import get_schema
from mkdocs import utils


Expand All @@ -28,14 +27,12 @@ def load_config(**cfg):
cfg = cfg or {}
if 'site_name' not in cfg:
cfg['site_name'] = 'Example'
if 'site_url' not in cfg:
cfg['site_url'] = 'https://example.com'
if 'config_file_path' not in cfg:
cfg['config_file_path'] = os.path.join(path_base, 'mkdocs.yml')
if 'docs_dir' not in cfg:
# Point to an actual dir to avoid a 'does not exist' error on validation.
cfg['docs_dir'] = os.path.join(path_base, 'docs')
conf = config.Config(schema=get_schema(), config_file_path=cfg['config_file_path'])
conf = config.Config(schema=config.defaults.get_schema(), config_file_path=cfg['config_file_path'])
conf.load_dict(cfg)

errors_warnings = conf.validate()
Expand Down
9 changes: 4 additions & 5 deletions mkdocs/tests/config/base_tests.py
Expand Up @@ -19,11 +19,10 @@ def test_unrecognised_keys(self):

failed, warnings = c.validate()

self.assertIn(
self.assertEqual(warnings, [
('not_a_valid_config_option',
'Unrecognised configuration name: not_a_valid_config_option'),
warnings
)
'Unrecognised configuration name: not_a_valid_config_option')
])

def test_missing_required(self):

Expand All @@ -35,7 +34,7 @@ def test_missing_required(self):
self.assertEqual(errors[0][0], 'site_name')
self.assertEqual(str(errors[0][1]), 'Required configuration not provided.')

self.assertEqual(len(warnings), 1)
self.assertEqual(len(warnings), 0)

def test_load_from_file(self):
"""
Expand Down
122 changes: 1 addition & 121 deletions mkdocs/tests/config/config_tests.py
Expand Up @@ -23,7 +23,7 @@ def load_missing_config():

def test_missing_site_name(self):
c = config.Config(schema=defaults.get_schema())
c.load_dict({'site_url': 'https://example.com'})
c.load_dict({})
errors, warnings = c.validate()
self.assertEqual(len(errors), 1)
self.assertEqual(errors[0][0], 'site_name')
Expand Down Expand Up @@ -295,123 +295,3 @@ def testConfigInstancesUnique(self):
conf.load_dict({'site_name': 'foo'})
conf.validate()
self.assertIsNone(conf['mdx_configs'].get('toc'))

def test_site_url_and_use_directory_urls_undefined(self):
conf = config.Config(schema=defaults.get_schema())
conf.load_dict({
'site_name': 'Example',
'config_file_path': os.path.join(os.path.abspath('.'), 'mkdocs.yml')
})
errors, warnings = conf.validate()
self.assertEqual(conf['site_url'], '')
self.assertFalse(conf['use_directory_urls'])
self.assertEqual(len(warnings), 2)
self.assertEqual(len(errors), 0)

def test_site_url_undefined_and_use_directory_urls_false(self):
conf = config.Config(schema=defaults.get_schema())
conf.load_dict({
'site_name': 'Example',
'use_directory_urls': False,
'config_file_path': os.path.join(os.path.abspath('.'), 'mkdocs.yml')
})
errors, warnings = conf.validate()
self.assertEqual(conf['site_url'], '')
self.assertFalse(conf['use_directory_urls'])
self.assertEqual(len(warnings), 1)
self.assertEqual(len(errors), 0)

def test_site_url_undefined_and_use_directory_urls_true(self):
conf = config.Config(schema=defaults.get_schema())
conf.load_dict({
'site_name': 'Example',
'use_directory_urls': True,
'config_file_path': os.path.join(os.path.abspath('.'), 'mkdocs.yml')
})
errors, warnings = conf.validate()
self.assertEqual(conf['site_url'], '')
self.assertFalse(conf['use_directory_urls'])
self.assertEqual(len(warnings), 2)
self.assertEqual(len(errors), 0)

def test_site_url_empty_and_use_directory_urls_undefined(self):
conf = config.Config(schema=defaults.get_schema())
conf.load_dict({
'site_name': 'Example',
'site_url': '',
'config_file_path': os.path.join(os.path.abspath('.'), 'mkdocs.yml')
})
errors, warnings = conf.validate()
self.assertEqual(conf['site_url'], '')
self.assertFalse(conf['use_directory_urls'])
self.assertEqual(len(warnings), 1)
self.assertEqual(len(errors), 0)

def test_site_url_empty_and_use_directory_urls_false(self):
conf = config.Config(schema=defaults.get_schema())
conf.load_dict({
'site_name': 'Example',
'site_url': '',
'use_directory_urls': False,
'config_file_path': os.path.join(os.path.abspath('.'), 'mkdocs.yml')
})
errors, warnings = conf.validate()
self.assertEqual(conf['site_url'], '')
self.assertFalse(conf['use_directory_urls'])
self.assertEqual(len(warnings), 0)
self.assertEqual(len(errors), 0)

def test_site_url_empty_and_use_directory_urls_true(self):
conf = config.Config(schema=defaults.get_schema())
conf.load_dict({
'site_name': 'Example',
'site_url': '',
'use_directory_urls': True,
'config_file_path': os.path.join(os.path.abspath('.'), 'mkdocs.yml')
})
errors, warnings = conf.validate()
self.assertEqual(conf['site_url'], '')
self.assertFalse(conf['use_directory_urls'])
self.assertEqual(len(warnings), 1)
self.assertEqual(len(errors), 0)

def test_site_url_defined_and_use_directory_urls_undefined(self):
conf = config.Config(schema=defaults.get_schema())
conf.load_dict({
'site_name': 'Example',
'site_url': 'http://example.com/',
'config_file_path': os.path.join(os.path.abspath('.'), 'mkdocs.yml')
})
errors, warnings = conf.validate()
self.assertEqual(conf['site_url'], 'http://example.com/')
self.assertTrue(conf['use_directory_urls'])
self.assertEqual(len(warnings), 0)
self.assertEqual(len(errors), 0)

def test_site_url_defined_and_use_directory_urls_false(self):
conf = config.Config(schema=defaults.get_schema())
conf.load_dict({
'site_name': 'Example',
'site_url': 'http://example.com/',
'use_directory_urls': False,
'config_file_path': os.path.join(os.path.abspath('.'), 'mkdocs.yml')
})
errors, warnings = conf.validate()
self.assertEqual(conf['site_url'], 'http://example.com/')
self.assertFalse(conf['use_directory_urls'])
self.assertEqual(len(warnings), 0)
self.assertEqual(len(errors), 0)

def test_site_url_defined_and_use_directory_urls_true(self):
conf = config.Config(schema=defaults.get_schema())
conf.load_dict({
'site_name': 'Example',
'site_url': 'http://example.com/',
'use_directory_urls': True,
'config_file_path': os.path.join(os.path.abspath('.'), 'mkdocs.yml')
})
errors, warnings = conf.validate()
self.assertEqual(conf['site_url'], 'http://example.com/')
self.assertTrue(conf['use_directory_urls'])
self.assertEqual(len(warnings), 0)
self.assertEqual(len(errors), 0)
1 change: 0 additions & 1 deletion mkdocs/tests/integration/minimal/mkdocs.yml
@@ -1,5 +1,4 @@
site_name: MyTest
site_url: 'https://example.com'

nav:
- 'testing.md'
Expand Down
1 change: 0 additions & 1 deletion mkdocs/tests/integration/subpages/mkdocs.yml
@@ -1,2 +1 @@
site_name: My Docs
site_url: 'https://example.com'
1 change: 0 additions & 1 deletion mkdocs/tests/integration/unicode/mkdocs.yml
@@ -1,2 +1 @@
site_name: My Docs
site_url: 'https://example.com'

0 comments on commit ae55657

Please sign in to comment.