Skip to content

Commit

Permalink
Adjusted transform to new projects plugin API
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Dec 10, 2023
1 parent 02e8211 commit fe93eb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
31 changes: 15 additions & 16 deletions examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,38 @@
import posixpath

from mergedeep import merge
from mkdocs.config.defaults import MkDocsConfig
from material.plugins.projects.structure import Project

# -----------------------------------------------------------------------------
# Functions
# -----------------------------------------------------------------------------

# Transform project configuration
def transform(project: MkDocsConfig, config: MkDocsConfig):
base = os.path.dirname(project.config_file_path)
def transform(project: Project, root: Project):
config = root.config

base = os.path.dirname(project.config.config_file_path)
name = os.path.basename(base)

# Determine path of examples relative to root
root = os.path.dirname(config.config_file_path)
path = os.path.relpath(base, root)

# Inherit settings for repository
project.repo_name = config.repo_name
project.repo_url = f"{config.repo_url}/tree/master/{path}"
project.config.repo_name = config.repo_name
project.config.repo_url = f"{config.repo_url}/tree/master/{path}"

# Inherit settings for site URL and edit URI
project.site_url = posixpath.join(config.site_url, name, "")
project.edit_uri = f"edit/master/examples/{name}/docs/"

# Inherit settings for copyright
project.copyright = config.copyright
project.config.site_url = posixpath.join(config.site_url, name, "")
project.config.edit_uri = f"edit/master/examples/{name}/docs/"

# Inherit settings for theme
if "features" in project.theme:
project.theme["features"].extend(config.theme["features"])
if "features" in project.config.theme:
project.config.theme["features"].extend(config.theme["features"])
else:
project.theme["features"] = config.theme["features"]
project.config.theme["features"] = config.theme["features"]

if "icon" in project.theme:
merge(project.theme["icon"], config.theme["icon"])
if "icon" in project.config.theme:
merge(project.config.theme["icon"], config.theme["icon"])
else:
project.theme["icon"] = config.theme["icon"]
project.config.theme["icon"] = config.theme["icon"]
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ plugins:
cache: false
projects_dir: examples
projects_config_transform: !!python/name:examples.transform
log_level: warn
log_level: info

# Hooks
hooks:
Expand Down

0 comments on commit fe93eb8

Please sign in to comment.