Skip to content

Commit

Permalink
Remove previously deprecated json command.
Browse files Browse the repository at this point in the history
Closes #481.
  • Loading branch information
waylan committed Mar 16, 2017
1 parent bcb9517 commit a00fe57
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 64 deletions.
1 change: 1 addition & 0 deletions docs/about/release-notes.md
Expand Up @@ -29,6 +29,7 @@ TODO...

### Other Changes and Additions to Version 1.0.0

* The deprecated `json` command has been removed (#481)
* Support for Python 2.6 has been dropped (#165)

## Version 0.16.2 (2017-03-13)
Expand Down
34 changes: 0 additions & 34 deletions mkdocs/__main__.py
Expand Up @@ -159,40 +159,6 @@ def build_command(clean, config_file, strict, theme, theme_dir, site_dir):
raise SystemExit('\n' + str(e))


@cli.command(name="json")
@click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)
@click.option('-f', '--config-file', type=click.File('rb'), help=config_help)
@click.option('-s', '--strict', is_flag=True, help=strict_help)
@click.option('-d', '--site-dir', type=click.Path(), help=site_dir_help)
@common_options
def json_command(clean, config_file, strict, site_dir):
"""Build the MkDocs documentation to JSON files
Rather than building your documentation to HTML pages, this
outputs each page in a simple JSON format. This command is
useful if you want to index your documentation in an external
search engine.
"""

log.warning("The json command is deprecated and will be removed in a "
"future MkDocs release. For details on updating: "
"http://www.mkdocs.org/about/release-notes/")

# Don't override config value if user did not specify --strict flag
# Conveniently, load_config drops None values
strict = strict or None

try:
build.build(config.load_config(
config_file=config_file,
strict=strict,
site_dir=site_dir
), dump_json=True, dirty=not clean)
except exceptions.ConfigurationError as e: # pragma: no cover
# Avoid ugly, unhelpful traceback
raise SystemExit('\n' + str(e))


@cli.command(name="gh-deploy")
@click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)
@click.option('-f', '--config-file', type=click.File('rb'), help=config_help)
Expand Down
26 changes: 5 additions & 21 deletions mkdocs/commands/build.py
Expand Up @@ -9,7 +9,6 @@

from jinja2.exceptions import TemplateNotFound
import jinja2
import json

from mkdocs import nav, search, utils
from mkdocs.utils import filters
Expand Down Expand Up @@ -170,7 +169,7 @@ def build_template(template_name, env, config, site_navigation=None):
return True


def _build_page(page, config, site_navigation, env, dump_json, dirty=False):
def _build_page(page, config, site_navigation, env, dirty=False):

# Get the input/output paths
input_path, output_path = get_complete_paths(config, page)
Expand Down Expand Up @@ -213,17 +212,7 @@ def _build_page(page, config, site_navigation, env, dump_json, dirty=False):
output_content = template.render(context)

# Write the output file.
if dump_json:
json_context = {
'content': context['content'],
'title': context['current_page'].title,
'url': context['current_page'].abs_url,
'language': 'en',
}
json_output = json.dumps(json_context, indent=4).encode('utf-8')
utils.write_file(json_output, output_path.replace('.html', '.json'))
else:
utils.write_file(output_content.encode('utf-8'), output_path)
utils.write_file(output_content.encode('utf-8'), output_path)

return html_content, table_of_contents, meta

Expand All @@ -248,7 +237,7 @@ def build_extra_templates(extra_templates, config, site_navigation=None):
utils.write_file(output_content.encode('utf-8'), output_path)


def build_pages(config, dump_json=False, dirty=False):
def build_pages(config, dirty=False):
"""
Builds all the pages and writes them into the build directory.
"""
Expand Down Expand Up @@ -329,8 +318,7 @@ def resolve(self, key):
continue

log.debug("Building page %s", page.input_path)
build_result = _build_page(page, config, site_navigation, env,
dump_json)
build_result = _build_page(page, config, site_navigation, env)
html_content, table_of_contents, _ = build_result
search_index.add_entry_from_context(
page, html_content, table_of_contents)
Expand All @@ -343,7 +331,7 @@ def resolve(self, key):
utils.write_file(search_index.encode('utf-8'), json_output_path)


def build(config, live_server=False, dump_json=False, dirty=False):
def build(config, live_server=False, dirty=False):
"""
Perform a full site build.
"""
Expand All @@ -360,10 +348,6 @@ def build(config, live_server=False, dump_json=False, dirty=False):
if dirty and site_directory_contains_stale_files(config['site_dir']):
log.info("The directory contains stale files. Use --clean to remove them.")

if dump_json:
build_pages(config, dump_json=True, dirty=dirty)
return

# Reversed as we want to take the media files from the builtin theme
# and then from the custom theme_dir so that the custom versions take
# precedence.
Expand Down
9 changes: 0 additions & 9 deletions mkdocs/tests/cli_tests.py
Expand Up @@ -318,15 +318,6 @@ def test_build_quiet(self, mock_build):
logger = logging.getLogger('mkdocs')
self.assertEqual(logger.level, logging.ERROR)

@mock.patch('mkdocs.commands.build.build', autospec=True)
def test_json(self, mock_build):

result = self.runner.invoke(
cli.cli, ["json", ], catch_exceptions=False)

self.assertEqual(result.exit_code, 0)
self.assertEqual(mock_build.call_count, 1)

@mock.patch('mkdocs.commands.new.new', autospec=True)
def test_new(self, mock_new):

Expand Down

0 comments on commit a00fe57

Please sign in to comment.