Ejemplo n.º 1
0
def build_pages(config, dirty=False):
    """ Build all pages and write them into the build directory. """

    site_navigation = nav.SiteNavigation(config)

    # Run `nav` plugin events.
    site_navigation = config['plugins'].run_event('nav',
                                                  site_navigation,
                                                  config=config)

    env = config['theme'].get_env()

    # Run `env` plugin events.
    env = config['plugins'].run_event('env',
                                      env,
                                      config=config,
                                      site_navigation=site_navigation)

    for template in config['theme'].static_templates:
        if utils.is_error_template(template):
            build_error_template(template, env, config, site_navigation)
        else:
            build_template(template, env, config, site_navigation)

    build_extra_templates(config['extra_templates'], config, site_navigation)

    log.debug("Building markdown pages.")
    for page in site_navigation.walk_pages():
        try:
            # When --dirty is used, only build the page if the markdown has been modified since the
            # previous build of the output.
            if dirty and (utils.modified_time(page.abs_input_path) <
                          utils.modified_time(page.abs_output_path)):
                continue

            log.debug("Building page %s", page.input_path)
            _build_page(page, config, site_navigation, env)
        except Exception:
            log.error("Error building page %s", page.input_path)
            raise
Ejemplo n.º 2
0
def build_pages(config, dirty=False):
    """ Build all pages and write them into the build directory. """

    site_navigation = nav.SiteNavigation(config)

    # Run `nav` plugin events.
    site_navigation = config['plugins'].run_event('nav', site_navigation, config=config)

    env = config['theme'].get_env()

    # Run `env` plugin events.
    env = config['plugins'].run_event(
        'env', env, config=config, site_navigation=site_navigation
    )

    for template in config['theme'].static_templates:
        if utils.is_error_template(template):
            build_error_template(template, env, config, site_navigation)
        else:
            build_template(template, env, config, site_navigation)

    build_extra_templates(config['extra_templates'], config, site_navigation)

    log.debug("Building markdown pages.")
    for page in site_navigation.walk_pages():
        try:
            # When --dirty is used, only build the page if the markdown has been modified since the
            # previous build of the output.
            if dirty and (utils.modified_time(page.abs_input_path) < utils.modified_time(page.abs_output_path)):
                continue

            log.debug("Building page %s", page.input_path)
            _build_page(page, config, site_navigation, env)
        except Exception:
            log.error("Error building page %s", page.input_path)
            raise
Ejemplo n.º 3
0
def build_pages(config, dump_json=False, dirty=False):
    """
    Builds all the pages and writes them into the build directory.
    """
    site_navigation = nav.SiteNavigation(config['pages'], config['use_directory_urls'])
    loader = jinja2.FileSystemLoader(config['theme_dir'] + [config['mkdocs_templates'], ])
    env = jinja2.Environment(loader=loader)

    # TODO: remove DeprecationContext in v1.0 when all deprecated vars have been removed
    from jinja2.runtime import Context
    deprecated_vars = [
        'page_title',
        'content',
        'toc',
        'meta',
        'current_page',
        'canonical_url',
        'previous_page',
        'next_page'
    ]

    class DeprecationContext(Context):
        def resolve(self, key):
            """ Log a warning when acessing any deprecated variable name. """
            if key in deprecated_vars:
                replacement = "page" if key == 'current_page' else "page.{0}".format(key)
                log.warn(
                    "Template variable warning: '{0}' is being deprecated and will not be "
                    "available in a future version. Use '{1}' instead.".format(key, replacement)
                )
            return super(DeprecationContext, self).resolve(key)

    env.context_class = DeprecationContext
    # TODO: end remove DeprecationContext

    env.filters['tojson'] = filters.tojson
    search_index = search.SearchIndex()

    # Force absolute URLs in the nav of error pages and account for the
    # possability that the docs root might be different than the server root.
    # See https://github.com/mkdocs/mkdocs/issues/77
    site_navigation.url_context.force_abs_urls = True
    default_base = site_navigation.url_context.base_path
    site_navigation.url_context.base_path = utils.urlparse(config['site_url']).path
    build_template('404.html', env, config, site_navigation)
    # Reset nav behavior to the default
    site_navigation.url_context.force_abs_urls = False
    site_navigation.url_context.base_path = default_base

    if not build_template('search.html', env, config, site_navigation):
        log.debug("Search is enabled but the theme doesn't contain a "
                  "search.html file. Assuming the theme implements search "
                  "within a modal.")

    build_template('sitemap.xml', env, config, site_navigation)

    build_extra_templates(config['extra_templates'], config, site_navigation)

    # append extra pages not including in [email protected]
    append_extra_pages(config, env, dump_json, site_navigation)

    for page in site_navigation.walk_pages():

        try:

            # When --dirty is used, only build the page if the markdown has been modified since the
            # previous build of the output.
            input_path, output_path = get_complete_paths(config, page)
            if dirty and (utils.modified_time(input_path) < utils.modified_time(output_path)):
                continue

            log.debug("Building page %s", page.input_path)
            build_result = _build_page(page, config, site_navigation, env,
                                       dump_json)
            html_content, table_of_contents, _ = build_result
            search_index.add_entry_from_context(
                page, html_content, table_of_contents)
        except Exception:
            log.error("Error building page %s", page.input_path)
            raise

    search_index = search_index.generate_search_index()
    json_output_path = os.path.join(config['site_dir'], 'mkdocs', 'search_index.json')
    utils.write_file(search_index.encode('utf-8'), json_output_path)
Ejemplo n.º 4
0
def build_pages(config, dump_json=False, dirty=False):
    """
    Builds all the pages and writes them into the build directory.
    """
    site_navigation = nav.SiteNavigation(config['pages'], config['use_directory_urls'])
    loader = jinja2.FileSystemLoader(config['theme_dir'] + [config['mkdocs_templates'], ])
    env = jinja2.Environment(loader=loader)

    # TODO: remove DeprecationContext in v1.0 when all deprecated vars have been removed
    from jinja2.runtime import Context
    deprecated_vars = [
        'page_title',
        'content',
        'toc',
        'meta',
        'current_page',
        'canonical_url',
        'previous_page',
        'next_page'
    ]

    class DeprecationContext(Context):
        def resolve(self, key):
            """ Log a warning when acessing any deprecated variable name. """
            if key in deprecated_vars:
                replacement = "page" if key == 'current_page' else "page.{0}".format(key)
                log.warn(
                    "Template variable warning: '{0}' is being deprecated and will not be "
                    "available in a future version. Use '{1}' instead.".format(key, replacement)
                )
            return super(DeprecationContext, self).resolve(key)

    env.context_class = DeprecationContext
    # TODO: end remove DeprecationContext

    env.filters['tojson'] = filters.tojson
    search_index = search.SearchIndex()

    build_template('404.html', env, config, site_navigation)

    if not build_template('search.html', env, config, site_navigation):
        log.debug("Search is enabled but the theme doesn't contain a "
                  "search.html file. Assuming the theme implements search "
                  "within a modal.")

    build_template('sitemap.xml', env, config, site_navigation)

    build_extra_templates(config['extra_templates'], config, site_navigation)

    for page in site_navigation.walk_pages():

        try:

            # When --dirty is used, only build the page if the markdown has been modified since the
            # previous build of the output.
            input_path, output_path = get_complete_paths(config, page)
            if dirty and (utils.modified_time(input_path) < utils.modified_time(output_path)):
                continue

            log.debug("Building page %s", page.input_path)
            build_result = _build_page(page, config, site_navigation, env,
                                       dump_json)
            html_content, table_of_contents, _ = build_result
            search_index.add_entry_from_context(
                page, html_content, table_of_contents)
        except Exception:
            log.error("Error building page %s", page.input_path)
            raise

    search_index = search_index.generate_search_index()
    json_output_path = os.path.join(config['site_dir'], 'mkdocs', 'search_index.json')
    utils.write_file(search_index.encode('utf-8'), json_output_path)
Ejemplo n.º 5
0
def build_pages(config, dump_json=False, dirty=False):
    """
    Builds all the pages and writes them into the build directory.
    """
    site_navigation = nav.SiteNavigation(config['pages'], config['use_directory_urls'])
    loader = jinja2.FileSystemLoader(config['theme_dir'] + [config['mkdocs_templates'], ])
    env = jinja2.Environment(loader=loader)

    # TODO: remove DeprecationContext in v1.0 when all deprecated vars have been removed
    from jinja2.runtime import Context
    deprecated_vars = {
        'page_title': 'page.title',
        'content': 'page.content',
        'toc': 'page.toc',
        'meta': 'page.meta',
        'canonical_url': 'page.canonical_url',
        'previous_page': 'page.previous_page',
        'next_page': 'page.next_page',
        'current_page': 'page',
        'include_nav': 'nav|length>1',
        'include_next_prev': '(page.next_page or page.previous_page)',
        'site_name': 'config.site_name',
        'site_author': 'config.site_author',
        'page_description': 'config.site_description',
        'repo_url': 'config.repo_url',
        'repo_name': 'config.repo_name',
        'site_url': 'config.site_url',
        'copyright': 'config.copyright',
        'google_analytics': 'config.google_analytics',
        'homepage_url': 'nav.homepage.url',
        'favicon': '{{ base_url }}/img/favicon.ico',
    }

    class DeprecationContext(Context):
        def resolve(self, key):
            """ Log a warning when accessing any deprecated variable name. """
            if key in deprecated_vars:
                log.warn(
                    "Template variable warning: '{0}' is being deprecated "
                    "and will not be available in a future version. Use "
                    "'{1}' instead.".format(key, deprecated_vars[key])
                )
            return super(DeprecationContext, self).resolve(key)

    env.context_class = DeprecationContext
    # TODO: end remove DeprecationContext

    env.filters['tojson'] = filters.tojson
    search_index = search.SearchIndex()

    # Force absolute URLs in the nav of error pages and account for the
    # possability that the docs root might be different than the server root.
    # See https://github.com/mkdocs/mkdocs/issues/77
    site_navigation.url_context.force_abs_urls = True
    default_base = site_navigation.url_context.base_path
    site_navigation.url_context.base_path = utils.urlparse(config['site_url']).path
    build_template('404.html', env, config, site_navigation)
    # Reset nav behavior to the default
    site_navigation.url_context.force_abs_urls = False
    site_navigation.url_context.base_path = default_base

    if not build_template('search.html', env, config, site_navigation):
        log.debug("Search is enabled but the theme doesn't contain a "
                  "search.html file. Assuming the theme implements search "
                  "within a modal.")

    build_template('sitemap.xml', env, config, site_navigation)

    build_extra_templates(config['extra_templates'], config, site_navigation)

    for page in site_navigation.walk_pages():

        try:

            # When --dirty is used, only build the page if the markdown has been modified since the
            # previous build of the output.
            input_path, output_path = get_complete_paths(config, page)
            if dirty and (utils.modified_time(input_path) < utils.modified_time(output_path)):
                continue

            log.debug("Building page %s", page.input_path)
            build_result = _build_page(page, config, site_navigation, env,
                                       dump_json)
            html_content, table_of_contents, _ = build_result
            search_index.add_entry_from_context(
                page, html_content, table_of_contents)
        except Exception:
            log.error("Error building page %s", page.input_path)
            raise

    search_index = search_index.generate_search_index()
    json_output_path = os.path.join(config['site_dir'], 'mkdocs', 'search_index.json')
    utils.write_file(search_index.encode('utf-8'), json_output_path)