def _build_template(name, template, files, config, nav): """ Return rendered output for given template as a string. """ # Run `pre_template` plugin events. template = config['plugins'].run_event( 'pre_template', template, template_name=name, config=config ) if utils.is_error_template(name): # 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. # However, if site_url is not set, assume the docs root and server root # are the same. See https://github.com/mkdocs/mkdocs/issues/1598. base_url = urlparse(config['site_url'] or '/').path else: base_url = utils.get_relative_url('.', name) context = get_context(nav, files, config, base_url=base_url) # Run `template_context` plugin events. context = config['plugins'].run_event( 'template_context', context, template_name=name, config=config ) output = template.render(context) # Run `post_template` plugin events. output = config['plugins'].run_event( 'post_template', output, template_name=name, config=config ) return output
def _build_template(name, template, files, config, nav): """ Return rendered output for given template as a string. """ # Run `pre_template` plugin events. template = config['plugins'].run_event( 'pre_template', template, template_name=name, config=config ) if utils.is_error_template(name): # 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. # However, if site_url is not set, assume the docs root and server root # are the same. See https://github.com/mkdocs/mkdocs/issues/1598. base_url = utils.urlparse(config['site_url'] or '/').path else: base_url = utils.get_relative_url('.', name) context = get_context(nav, files, config, base_url=base_url) # Run `template_context` plugin events. context = config['plugins'].run_event( 'template_context', context, template_name=name, config=config ) output = template.render(context) # Run `post_template` plugin events. output = config['plugins'].run_event( 'post_template', output, template_name=name, config=config ) return output
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
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