How to use the mkdocs.config function in mkdocs

To help you get started, we’ve selected a few mkdocs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rosscdh / mkdocs-markdownextradata-plugin / markdownextradata / plugin.py View on Github external
CONFIG_KEYS = ["site_name", "site_author", "site_url", "repo_url", "repo_name"]

if sys.version_info[0] >= 3:
    str_type = str
else:
    str_type = mkdocs.utils.string_types


class MarkdownExtraDataPlugin(BasePlugin):
    """
    Inject certain config variables into the markdown
    """

    config_scheme = (
        ("data", mkdocs.config.config_options.Type(str_type, default=None)),
    )

    def __add_data__(self, config, namespace, data):
        # creates the namespace and adds the data there
        namespace = ["extra"] + namespace.split(os.sep)
        holder = config
        while len(namespace) > 1:
            if not namespace[0] in holder:
                holder[namespace[0]] = {}
            holder = holder[namespace[0]]
            del namespace[0]
        holder[namespace[0]] = data

    def on_pre_build(self, config, **kwargs):
        # Loads all data from the supplied data directories
        # or, otherwise a _data directory next to mkdocs.yml and/or inside the docs_dir.
github zayd62 / mkdocs-versioning / mkversion / utils.py View on Github external
def deploy(args):
    """
    Deploy to Github Pages

    Args:
        args (argparse.Namespace): A Namespace object contaning all the command line arguments

    Raises:
        exceptions.ConfigurationError
    """

    try:
        cfg = config.load_config(config_file=args.config_file, remote_branch=args.remote_branch, remote_name=args.remote_name)
        gh_deploy.gh_deploy(cfg, message=args.message, force=args.force, ignore_version=args.ignore_version)

    except exceptions.ConfigurationError as e:
        raise SystemExit('\n' + str(e))
github apenwarr / mkdocs-exclude / mkdocs_exclude / plugin.py View on Github external
import fnmatch
import re
import os
import sys
import mkdocs
import mkdocs.plugins
import mkdocs.structure.files

class Exclude(mkdocs.plugins.BasePlugin):
    """A mkdocs plugin that removes all matching files from the input list."""

    config_scheme = (
        ('glob', mkdocs.config.config_options.Type((str, list), default=None)),
        ('regex', mkdocs.config.config_options.Type((str, list), default=None)),
    )

    def on_files(self, files, config):
        globs = self.config['glob'] or []
        if not isinstance(globs, list):
            globs = [globs]
        regexes = self.config['regex'] or []
        if not isinstance(regexes, list):
            regexes = [regexes]
        out = []
        def include(name):
            for g in globs:
                if fnmatch.fnmatchcase(name, g):
                    return False
            for r in regexes:
                if re.match(r, name):
github ClickHouse / ClickHouse / docs / tools / build.py View on Github external
}
        }

        site_names = {
            'en': 'ClickHouse %s Documentation',
            'ru': 'Документация ClickHouse %s',
            'zh': 'ClickHouse文档 %s',
            'fa': 'مستندات  %sClickHouse'
        }

        if args.version_prefix:
            site_dir = os.path.join(args.docs_output_dir, args.version_prefix, lang)
        else:
            site_dir = os.path.join(args.docs_output_dir, lang)
            
        cfg = config.load_config(
            config_file=config_path,
            site_name=site_names.get(lang, site_names['en']) % args.version_prefix,
            site_url='https://clickhouse.yandex/docs/%s/' % lang,
            docs_dir=os.path.join(args.docs_dir, lang),
            site_dir=site_dir,
            strict=not args.version_prefix,
            theme=theme_cfg,
            copyright='©2016–2019 Yandex LLC',
            use_directory_urls=True,
            repo_name='ClickHouse/ClickHouse',
            repo_url='https://github.com/ClickHouse/ClickHouse/',
            edit_uri='edit/master/docs/%s' % lang,
            extra_css=['assets/stylesheets/custom.css'],
            markdown_extensions=[
                'clickhouse',
                'admonition',
github greenape / mknotebooks / mknotebooks / plugin.py View on Github external
class Plugin(mkdocs.plugins.BasePlugin):
    config_scheme = (
        ("execute", mkdocs.config.config_options.Type(bool, default=False)),
        ("allow_errors", mkdocs.config.config_options.Type(bool, default=False)),
        ("preamble", mkdocs.config.config_options.FilesystemObject()),
        ("timeout", mkdocs.config.config_options.Type(int)),
        ("write_markdown", mkdocs.config.config_options.Type(bool, default=False)),
        (
            "enable_default_jupyter_cell_styling",
            mkdocs.config.config_options.Type(bool, default=True),
        ),
        (
            "enable_default_pandas_dataframe_styling",
            mkdocs.config.config_options.Type(bool, default=True),
        ),
    )

    def on_config(self, config: MkDocsConfig):
        exporter_config = Config()
        if self.config["execute"]:
            default_preprocessors = MarkdownExporter.default_preprocessors.default_args[
                0
            ]
            try:
                default_preprocessors[
                    default_preprocessors.index(
                        "nbconvert.preprocessors.ExecutePreprocessor"
                    )
                ] = ExtraArgsExecutePreprocessor
            except ValueError:
github byrnereese / mkdocs-minify-plugin / mkdocs_minify_plugin / plugin.py View on Github external
import fnmatch
from timeit import default_timer as timer
from datetime import datetime, timedelta

from mkdocs import utils as mkdocs_utils
from mkdocs.config import config_options, Config
from mkdocs.plugins import BasePlugin
import mkdocs.structure.files

from jsmin import jsmin
from htmlmin import minify

class MinifyPlugin(BasePlugin):

    config_scheme = (
        ('minify_html', mkdocs.config.config_options.Type(bool, default=False)),
        ('htmlmin_opts', mkdocs.config.config_options.Type((str, dict), default=None)),
        ('minify_js', mkdocs.config.config_options.Type(bool, default=False)),
        ('js_files', mkdocs.config.config_options.Type((str, list), default=None))
    )

    def __init__(self):
        self.enabled = True
        self.total_time = 0

    def on_post_page(self, output_content, page, config):
        if self.config['minify_html']:
            opts = self.config['htmlmin_opts'] or {}
            for key in opts:
                if key not in ['remove_comments','remove_empty_space','remove_all_empty_space','reduce_boolean_attributes','remove_optional_attribute_quotes','conver_charrefs','keep_pre','pre_tags','pre_attr']:
                    print("htmlmin option " + key + " not recognized")
            return minify(output_content, opts.get("remove_comments", False), opts.get("remove_empty_space", False), opts.get("remove_all_empty_space", False), opts.get("reduce_empty_attributes", True), opts.get("reduce_boolean_attributes", False), opts.get("remove_optional_attribute_quotes", True), opts.get("convert_charrefs", True), opts.get("keep_pre", False), opts.get("pre_tags", ('pre', 'textarea')), opts.get("pre_tags", 'pre'))
github apenwarr / mkdocs-exclude / mkdocs_exclude / plugin.py View on Github external
import fnmatch
import re
import os
import sys
import mkdocs
import mkdocs.plugins
import mkdocs.structure.files

class Exclude(mkdocs.plugins.BasePlugin):
    """A mkdocs plugin that removes all matching files from the input list."""

    config_scheme = (
        ('glob', mkdocs.config.config_options.Type((str, list), default=None)),
        ('regex', mkdocs.config.config_options.Type((str, list), default=None)),
    )

    def on_files(self, files, config):
        globs = self.config['glob'] or []
        if not isinstance(globs, list):
            globs = [globs]
        regexes = self.config['regex'] or []
        if not isinstance(regexes, list):
            regexes = [regexes]
        out = []
        def include(name):
            for g in globs:
                if fnmatch.fnmatchcase(name, g):
                    return False
            for r in regexes:
github zayd62 / mkdocs-versioning / mkversion / utils.py View on Github external
def sync(args):
    """
    Pulls the previously built pages from github pages

    Args:
        args (argparse.Namespace): A Namespace object contaning all the command line arguments

    Raises:
        exceptions.ConfigurationError
    """

    cfg = config.load_config(config_file=args.config_file)
    with tempfile.TemporaryDirectory() as tempdir:
        # clone gh-pages branch into a temp dir
        os.chdir(tempdir)
        subprocess.run(['git', 'clone', '-b', cfg['remote_branch'], cfg['repo_url']])
        # noinspection PyArgumentList
        os.chdir(os.listdir()[0])

        # remove old site folder
        try:
            shutil.rmtree(cfg['site_dir'])
            os.mkdir(cfg['site_dir'])  # rmtree deletes folder so you need to recreate folder
        except FileNotFoundError as identifier:
            print(identifier)
            print('no site directory')

        # copy files into site directory
github timothycrosley / portray / portray / render.py View on Github external
def _mkdocs_config(config: dict) -> mkdocs_config.Config:
    config_instance = mkdocs_config.Config(schema=mkdocs_config.DEFAULT_SCHEMA)
    config_instance.load_dict(config)

    errors, warnings = config_instance.validate()
    if errors:
        print(errors)
        raise _mkdocs_exceptions.ConfigurationError(
            f"Aborted with {len(errors)} Configuration Errors!"
        )
    elif config.get("strict", False) and warnings:  # pragma: no cover
        print(warnings)
        raise _mkdocs_exceptions.ConfigurationError(
            f"Aborted with {len(warnings)} Configuration Warnings in 'strict' mode!"
        )

    config_instance.config_file_path = config["config_file_path"]
    return config_instance