mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2025-01-31 03:43:46 +01:00
MkDocs upgrade: migrate to class-based config schemas
This commit is contained in:
parent
593a3464c5
commit
b6d2eb19fd
@ -28,7 +28,8 @@ from collections import defaultdict
|
|||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from mkdocs.commands.build import DuplicateFilter
|
from mkdocs.commands.build import DuplicateFilter
|
||||||
from mkdocs.config.config_options import Type
|
from mkdocs.config.base import Config
|
||||||
|
from mkdocs.config import config_options as opt
|
||||||
from mkdocs.plugins import BasePlugin
|
from mkdocs.plugins import BasePlugin
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from tempfile import TemporaryFile
|
from tempfile import TemporaryFile
|
||||||
@ -45,20 +46,19 @@ except ImportError:
|
|||||||
# Class
|
# Class
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Configuration scheme
|
||||||
|
class SocialPluginConfig(Config):
|
||||||
|
enabled = opt.Type(bool, default = True)
|
||||||
|
cache_dir = opt.Type(str, default = ".cache/plugin/social")
|
||||||
|
|
||||||
|
# Options for social cards
|
||||||
|
cards = opt.Type(bool, default = True)
|
||||||
|
cards_dir = opt.Type(str, default = "assets/images/social")
|
||||||
|
cards_color = opt.Type(dict, default = {})
|
||||||
|
cards_font = opt.Optional(opt.Type(str))
|
||||||
|
|
||||||
# Social plugin
|
# Social plugin
|
||||||
class SocialPlugin(BasePlugin):
|
class SocialPlugin(BasePlugin[SocialPluginConfig]):
|
||||||
|
|
||||||
# Configuration scheme
|
|
||||||
config_scheme = (
|
|
||||||
("enabled", Type(bool, default = True)),
|
|
||||||
("cache_dir", Type(str, default = ".cache/plugin/social")),
|
|
||||||
|
|
||||||
# Options for social cards
|
|
||||||
("cards", Type(bool, default = True)),
|
|
||||||
("cards_dir", Type(str, default = "assets/images/social")),
|
|
||||||
("cards_color", Type(dict, default = {})),
|
|
||||||
("cards_font", Type(str, default = None)),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Retrieve configuration
|
# Retrieve configuration
|
||||||
def on_config(self, config):
|
def on_config(self, config):
|
||||||
|
@ -26,20 +26,21 @@ from collections import defaultdict
|
|||||||
from markdown.extensions.toc import slugify
|
from markdown.extensions.toc import slugify
|
||||||
from mkdocs import utils
|
from mkdocs import utils
|
||||||
from mkdocs.commands.build import DuplicateFilter
|
from mkdocs.commands.build import DuplicateFilter
|
||||||
from mkdocs.config.config_options import Type
|
from mkdocs.config.base import Config
|
||||||
|
from mkdocs.config import config_options as opt
|
||||||
from mkdocs.plugins import BasePlugin
|
from mkdocs.plugins import BasePlugin
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Class
|
# Class
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
# Tags plugin
|
# Configuration scheme
|
||||||
class TagsPlugin(BasePlugin):
|
class TagsPluginConfig(Config):
|
||||||
|
tags_file = opt.Optional(opt.Type(str))
|
||||||
|
|
||||||
# Configuration scheme
|
|
||||||
config_scheme = (
|
# Tags plugin
|
||||||
("tags_file", Type(str, required = False)),
|
class TagsPlugin(BasePlugin[TagsPluginConfig]):
|
||||||
)
|
|
||||||
|
|
||||||
# Initialize plugin
|
# Initialize plugin
|
||||||
def on_config(self, config):
|
def on_config(self, config):
|
||||||
|
@ -28,7 +28,8 @@ from collections import defaultdict
|
|||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from mkdocs.commands.build import DuplicateFilter
|
from mkdocs.commands.build import DuplicateFilter
|
||||||
from mkdocs.config.config_options import Type
|
from mkdocs.config.base import Config
|
||||||
|
from mkdocs.config import config_options as opt
|
||||||
from mkdocs.plugins import BasePlugin
|
from mkdocs.plugins import BasePlugin
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from tempfile import TemporaryFile
|
from tempfile import TemporaryFile
|
||||||
@ -45,20 +46,19 @@ except ImportError:
|
|||||||
# Class
|
# Class
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Configuration scheme
|
||||||
|
class SocialPluginConfig(Config):
|
||||||
|
enabled = opt.Type(bool, default = True)
|
||||||
|
cache_dir = opt.Type(str, default = ".cache/plugin/social")
|
||||||
|
|
||||||
|
# Options for social cards
|
||||||
|
cards = opt.Type(bool, default = True)
|
||||||
|
cards_dir = opt.Type(str, default = "assets/images/social")
|
||||||
|
cards_color = opt.Type(dict, default = {})
|
||||||
|
cards_font = opt.Optional(opt.Type(str))
|
||||||
|
|
||||||
# Social plugin
|
# Social plugin
|
||||||
class SocialPlugin(BasePlugin):
|
class SocialPlugin(BasePlugin[SocialPluginConfig]):
|
||||||
|
|
||||||
# Configuration scheme
|
|
||||||
config_scheme = (
|
|
||||||
("enabled", Type(bool, default = True)),
|
|
||||||
("cache_dir", Type(str, default = ".cache/plugin/social")),
|
|
||||||
|
|
||||||
# Options for social cards
|
|
||||||
("cards", Type(bool, default = True)),
|
|
||||||
("cards_dir", Type(str, default = "assets/images/social")),
|
|
||||||
("cards_color", Type(dict, default = {})),
|
|
||||||
("cards_font", Type(str, default = None)),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Retrieve configuration
|
# Retrieve configuration
|
||||||
def on_config(self, config):
|
def on_config(self, config):
|
||||||
|
@ -26,20 +26,21 @@ from collections import defaultdict
|
|||||||
from markdown.extensions.toc import slugify
|
from markdown.extensions.toc import slugify
|
||||||
from mkdocs import utils
|
from mkdocs import utils
|
||||||
from mkdocs.commands.build import DuplicateFilter
|
from mkdocs.commands.build import DuplicateFilter
|
||||||
from mkdocs.config.config_options import Type
|
from mkdocs.config.base import Config
|
||||||
|
from mkdocs.config import config_options as opt
|
||||||
from mkdocs.plugins import BasePlugin
|
from mkdocs.plugins import BasePlugin
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Class
|
# Class
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
# Tags plugin
|
# Configuration scheme
|
||||||
class TagsPlugin(BasePlugin):
|
class TagsPluginConfig(Config):
|
||||||
|
tags_file = opt.Optional(opt.Type(str))
|
||||||
|
|
||||||
# Configuration scheme
|
|
||||||
config_scheme = (
|
# Tags plugin
|
||||||
("tags_file", Type(str, required = False)),
|
class TagsPlugin(BasePlugin[TagsPluginConfig]):
|
||||||
)
|
|
||||||
|
|
||||||
# Initialize plugin
|
# Initialize plugin
|
||||||
def on_config(self, config):
|
def on_config(self, config):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user