コード例 #1
0
ファイル: __init__.py プロジェクト: zsc-worldify/mkdocs
 def run_validation(self, value):
     if isinstance(value, str):
         value = [value]
     elif not isinstance(value, (list, tuple)):
         raise config_options.ValidationError(
             'Expected a list of language codes.')
     for lang in value:
         if lang != 'en' and not self.lang_file_exists(lang):
             raise config_options.ValidationError(
                 '"{}" is not a supported language code.'.format(lang))
     return value
コード例 #2
0
    def validate_config(self, config):
        """ Given a config with values for site_dir and doc_dir, run site_dir post_validation. """
        site_dir = config_options.SiteDir()
        docs_dir = config_options.Dir()

        fname = os.path.join(os.path.abspath('..'), 'mkdocs.yml')

        config['docs_dir'] = docs_dir.validate(config['docs_dir'])
        config['site_dir'] = site_dir.validate(config['site_dir'])

        schema = [
            ('site_dir', site_dir),
            ('docs_dir', docs_dir),
        ]
        cfg = Config(schema, fname)
        cfg.load_dict(config)
        failed, warned = cfg.validate()

        if failed:
            raise config_options.ValidationError(failed)

        return True
コード例 #3
0
ファイル: __init__.py プロジェクト: palikhov/mkdocs
 def run_validation(self, value):
     if isinstance(value, str):
         value = [value]
     elif not isinstance(value, (list, tuple)):
         raise config_options.ValidationError(
             'Expected a list of language codes.')
     for lang in list(value):
         if lang != 'en':
             lang_detected = self.get_lunr_supported_lang(lang)
             if not lang_detected:
                 log.info(
                     f"Option search.lang '{lang}' is not supported, falling back to 'en'"
                 )
                 value.remove(lang)
                 if 'en' not in value:
                     value.append('en')
             elif lang_detected != lang:
                 value.remove(lang)
                 value.append(lang_detected)
                 log.info(
                     f"Option search.lang '{lang}' switched to '{lang_detected}'"
                 )
     return value