Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- micromamba_root/Lib/site-packages/material/plugins/blog/__init__.py +33 -0
- micromamba_root/Lib/site-packages/material/plugins/blog/author.py +40 -0
- micromamba_root/Lib/site-packages/material/plugins/blog/config.py +102 -0
- micromamba_root/Lib/site-packages/material/plugins/blog/plugin.py +1083 -0
- micromamba_root/Lib/site-packages/material/plugins/group/__init__.py +19 -0
- micromamba_root/Lib/site-packages/material/plugins/group/config.py +31 -0
- micromamba_root/Lib/site-packages/material/plugins/group/plugin.py +161 -0
- micromamba_root/Lib/site-packages/material/plugins/info/__init__.py +19 -0
- micromamba_root/Lib/site-packages/material/plugins/info/config.py +35 -0
- micromamba_root/Lib/site-packages/material/plugins/info/patterns.py +27 -0
- micromamba_root/Lib/site-packages/material/plugins/info/plugin.py +563 -0
- micromamba_root/Lib/site-packages/material/plugins/meta/__init__.py +19 -0
- micromamba_root/Lib/site-packages/material/plugins/meta/config.py +33 -0
- micromamba_root/Lib/site-packages/material/plugins/meta/plugin.py +122 -0
- micromamba_root/Lib/site-packages/material/plugins/offline/__init__.py +19 -0
- micromamba_root/Lib/site-packages/material/plugins/offline/config.py +30 -0
- micromamba_root/Lib/site-packages/material/plugins/offline/plugin.py +69 -0
- micromamba_root/Lib/site-packages/material/plugins/optimize/config.py +52 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/journal-whills.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/jpy.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/jug-detergent.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/k.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kaaba.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/key.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/keyboard.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/khanda.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kip-sign.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kiss-beam.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kiss-wink-heart.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kiss.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kit-medical.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kitchen-set.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kiwi-bird.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/krw.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/l.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/ladder-water.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/land-mine-on.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/landmark-alt.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/landmark-dome.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/landmark-flag.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/landmark.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/language.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laptop-code.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laptop-file.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laptop-house.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laptop-medical.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laptop.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/lari-sign.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laugh-beam.svg +1 -0
- micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laugh-squint.svg +1 -0
micromamba_root/Lib/site-packages/material/plugins/blog/__init__.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
from .structure import View
|
| 22 |
+
|
| 23 |
+
# -----------------------------------------------------------------------------
|
| 24 |
+
# Functions
|
| 25 |
+
# -----------------------------------------------------------------------------
|
| 26 |
+
|
| 27 |
+
# Sort views by name
|
| 28 |
+
def view_name(view: View):
|
| 29 |
+
return view.name
|
| 30 |
+
|
| 31 |
+
# Sort views by post count
|
| 32 |
+
def view_post_count(view: View):
|
| 33 |
+
return len(view.posts)
|
micromamba_root/Lib/site-packages/material/plugins/blog/author.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
from mkdocs.config.base import Config
|
| 22 |
+
from mkdocs.config.config_options import DictOfItems, Optional, SubConfig, Type
|
| 23 |
+
|
| 24 |
+
# -----------------------------------------------------------------------------
|
| 25 |
+
# Classes
|
| 26 |
+
# -----------------------------------------------------------------------------
|
| 27 |
+
|
| 28 |
+
# Author
|
| 29 |
+
class Author(Config):
|
| 30 |
+
name = Type(str)
|
| 31 |
+
description = Type(str)
|
| 32 |
+
avatar = Type(str)
|
| 33 |
+
slug = Optional(Type(str))
|
| 34 |
+
url = Optional(Type(str))
|
| 35 |
+
|
| 36 |
+
# -----------------------------------------------------------------------------
|
| 37 |
+
|
| 38 |
+
# Authors
|
| 39 |
+
class Authors(Config):
|
| 40 |
+
authors = DictOfItems(SubConfig(Author), default = {})
|
micromamba_root/Lib/site-packages/material/plugins/blog/config.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
from collections.abc import Callable
|
| 22 |
+
from mkdocs.config.config_options import Choice, Deprecated, Optional, Type
|
| 23 |
+
from mkdocs.config.base import Config
|
| 24 |
+
from pymdownx.slugs import slugify
|
| 25 |
+
|
| 26 |
+
from . import view_name
|
| 27 |
+
|
| 28 |
+
# -----------------------------------------------------------------------------
|
| 29 |
+
# Classes
|
| 30 |
+
# -----------------------------------------------------------------------------
|
| 31 |
+
|
| 32 |
+
# Blog plugin configuration
|
| 33 |
+
class BlogConfig(Config):
|
| 34 |
+
enabled = Type(bool, default = True)
|
| 35 |
+
|
| 36 |
+
# Settings for blog
|
| 37 |
+
blog_dir = Type(str, default = "blog")
|
| 38 |
+
blog_toc = Type(bool, default = False)
|
| 39 |
+
|
| 40 |
+
# Settings for posts
|
| 41 |
+
post_dir = Type(str, default = "{blog}/posts")
|
| 42 |
+
post_date_format = Type(str, default = "long")
|
| 43 |
+
post_url_date_format = Type(str, default = "yyyy/MM/dd")
|
| 44 |
+
post_url_format = Type(str, default = "{date}/{slug}")
|
| 45 |
+
post_url_max_categories = Type(int, default = 1)
|
| 46 |
+
post_slugify = Type(Callable, default = slugify(case = "lower"))
|
| 47 |
+
post_slugify_separator = Type(str, default = "-")
|
| 48 |
+
post_excerpt = Choice(["optional", "required"], default = "optional")
|
| 49 |
+
post_excerpt_max_authors = Type(int, default = 1)
|
| 50 |
+
post_excerpt_max_categories = Type(int, default = 5)
|
| 51 |
+
post_excerpt_separator = Type(str, default = "<!-- more -->")
|
| 52 |
+
post_readtime = Type(bool, default = True)
|
| 53 |
+
post_readtime_words_per_minute = Type(int, default = 265)
|
| 54 |
+
|
| 55 |
+
# Settings for archive
|
| 56 |
+
archive = Type(bool, default = True)
|
| 57 |
+
archive_name = Type(str, default = "blog.archive")
|
| 58 |
+
archive_date_format = Type(str, default = "yyyy")
|
| 59 |
+
archive_url_date_format = Type(str, default = "yyyy")
|
| 60 |
+
archive_url_format = Type(str, default = "archive/{date}")
|
| 61 |
+
archive_pagination = Optional(Type(bool))
|
| 62 |
+
archive_pagination_per_page = Optional(Type(int))
|
| 63 |
+
archive_toc = Optional(Type(bool))
|
| 64 |
+
|
| 65 |
+
# Settings for categories
|
| 66 |
+
categories = Type(bool, default = True)
|
| 67 |
+
categories_name = Type(str, default = "blog.categories")
|
| 68 |
+
categories_url_format = Type(str, default = "category/{slug}")
|
| 69 |
+
categories_slugify = Type(Callable, default = slugify(case = "lower"))
|
| 70 |
+
categories_slugify_separator = Type(str, default = "-")
|
| 71 |
+
categories_sort_by = Type(Callable, default = view_name)
|
| 72 |
+
categories_sort_reverse = Type(bool, default = False)
|
| 73 |
+
categories_allowed = Type(list, default = [])
|
| 74 |
+
categories_pagination = Optional(Type(bool))
|
| 75 |
+
categories_pagination_per_page = Optional(Type(int))
|
| 76 |
+
categories_toc = Optional(Type(bool))
|
| 77 |
+
|
| 78 |
+
# Settings for authors
|
| 79 |
+
authors = Type(bool, default = True)
|
| 80 |
+
authors_file = Type(str, default = "{blog}/.authors.yml")
|
| 81 |
+
authors_profiles = Type(bool, default = False)
|
| 82 |
+
authors_profiles_name = Type(str, default = "blog.authors")
|
| 83 |
+
authors_profiles_url_format = Type(str, default = "author/{slug}")
|
| 84 |
+
authors_profiles_pagination = Optional(Type(bool))
|
| 85 |
+
authors_profiles_pagination_per_page = Optional(Type(int))
|
| 86 |
+
authors_profiles_toc = Optional(Type(bool))
|
| 87 |
+
|
| 88 |
+
# Settings for pagination
|
| 89 |
+
pagination = Type(bool, default = True)
|
| 90 |
+
pagination_per_page = Type(int, default = 10)
|
| 91 |
+
pagination_url_format = Type(str, default = "page/{page}")
|
| 92 |
+
pagination_format = Type(str, default = "~2~")
|
| 93 |
+
pagination_if_single_page = Type(bool, default = False)
|
| 94 |
+
pagination_keep_content = Type(bool, default = False)
|
| 95 |
+
|
| 96 |
+
# Settings for drafts
|
| 97 |
+
draft = Type(bool, default = False)
|
| 98 |
+
draft_on_serve = Type(bool, default = True)
|
| 99 |
+
draft_if_future_date = Type(bool, default = False)
|
| 100 |
+
|
| 101 |
+
# Deprecated settings
|
| 102 |
+
pagination_template = Deprecated(moved_to = "pagination_format")
|
micromamba_root/Lib/site-packages/material/plugins/blog/plugin.py
ADDED
|
@@ -0,0 +1,1083 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
from __future__ import annotations
|
| 22 |
+
|
| 23 |
+
import logging
|
| 24 |
+
import os
|
| 25 |
+
import posixpath
|
| 26 |
+
import yaml
|
| 27 |
+
|
| 28 |
+
from babel.dates import format_date, format_datetime
|
| 29 |
+
from copy import copy
|
| 30 |
+
from datetime import datetime, timezone
|
| 31 |
+
from jinja2 import pass_context
|
| 32 |
+
from jinja2.runtime import Context
|
| 33 |
+
from mkdocs.config.defaults import MkDocsConfig
|
| 34 |
+
from mkdocs.exceptions import PluginError
|
| 35 |
+
from mkdocs.plugins import BasePlugin, event_priority
|
| 36 |
+
from mkdocs.structure import StructureItem
|
| 37 |
+
from mkdocs.structure.files import File, Files, InclusionLevel
|
| 38 |
+
from mkdocs.structure.nav import Link, Navigation, Section
|
| 39 |
+
from mkdocs.structure.pages import Page
|
| 40 |
+
from mkdocs.structure.toc import AnchorLink, TableOfContents
|
| 41 |
+
from mkdocs.utils import copy_file, get_relative_url
|
| 42 |
+
from paginate import Page as Pagination
|
| 43 |
+
from shutil import rmtree
|
| 44 |
+
from tempfile import mkdtemp
|
| 45 |
+
from urllib.parse import urlparse
|
| 46 |
+
from yaml import SafeLoader
|
| 47 |
+
|
| 48 |
+
from . import view_name
|
| 49 |
+
from .author import Author, Authors
|
| 50 |
+
from .config import BlogConfig
|
| 51 |
+
from .readtime import readtime
|
| 52 |
+
from .structure import (
|
| 53 |
+
Archive, Category, Profile,
|
| 54 |
+
Excerpt, Post, View,
|
| 55 |
+
Reference
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# -----------------------------------------------------------------------------
|
| 59 |
+
# Classes
|
| 60 |
+
# -----------------------------------------------------------------------------
|
| 61 |
+
|
| 62 |
+
# Blog plugin
|
| 63 |
+
class BlogPlugin(BasePlugin[BlogConfig]):
|
| 64 |
+
supports_multiple_instances = True
|
| 65 |
+
|
| 66 |
+
# Initialize plugin
|
| 67 |
+
def __init__(self, *args, **kwargs):
|
| 68 |
+
super().__init__(*args, **kwargs)
|
| 69 |
+
|
| 70 |
+
# Initialize incremental builds
|
| 71 |
+
self.is_serve = False
|
| 72 |
+
self.is_dirty = False
|
| 73 |
+
|
| 74 |
+
# Initialize temporary directory
|
| 75 |
+
self.temp_dir = mkdtemp()
|
| 76 |
+
|
| 77 |
+
# Determine whether we're serving the site
|
| 78 |
+
def on_startup(self, *, command, dirty):
|
| 79 |
+
self.is_serve = command == "serve"
|
| 80 |
+
self.is_dirty = dirty
|
| 81 |
+
|
| 82 |
+
# Initialize authors and set defaults
|
| 83 |
+
def on_config(self, config):
|
| 84 |
+
if not self.config.enabled:
|
| 85 |
+
return
|
| 86 |
+
|
| 87 |
+
# Initialize entrypoint
|
| 88 |
+
self.blog: View
|
| 89 |
+
|
| 90 |
+
# Initialize and resolve authors, if enabled
|
| 91 |
+
if self.config.authors:
|
| 92 |
+
self.authors = self._resolve_authors(config)
|
| 93 |
+
|
| 94 |
+
# By default, drafts are rendered when the documentation is served,
|
| 95 |
+
# but not when it is built, for a better user experience
|
| 96 |
+
if self.is_serve and self.config.draft_on_serve:
|
| 97 |
+
self.config.draft = True
|
| 98 |
+
|
| 99 |
+
# Resolve and load posts and generate views (run later) - we want to allow
|
| 100 |
+
# other plugins to add generated posts or views, so we run this plugin as
|
| 101 |
+
# late as possible. We also need to remove the posts from the navigation
|
| 102 |
+
# before navigation is constructed, as the entrypoint should be considered
|
| 103 |
+
# to be the active page for each post. The URLs of posts are computed before
|
| 104 |
+
# Markdown processing, so that when linking to and from posts, behavior is
|
| 105 |
+
# exactly the same as with regular documentation pages. We create all pages
|
| 106 |
+
# related to posts as part of this plugin, so we control the entire process.
|
| 107 |
+
@event_priority(-50)
|
| 108 |
+
def on_files(self, files, *, config):
|
| 109 |
+
if not self.config.enabled:
|
| 110 |
+
return
|
| 111 |
+
|
| 112 |
+
# Resolve path to entrypoint and site directory
|
| 113 |
+
root = posixpath.normpath(self.config.blog_dir)
|
| 114 |
+
site = config.site_dir
|
| 115 |
+
|
| 116 |
+
# Compute and normalize path to posts directory
|
| 117 |
+
path = self.config.post_dir.format(blog = root)
|
| 118 |
+
path = posixpath.normpath(path)
|
| 119 |
+
|
| 120 |
+
# Adjust destination paths for media files
|
| 121 |
+
for file in files.media_files():
|
| 122 |
+
if not file.src_uri.startswith(path):
|
| 123 |
+
continue
|
| 124 |
+
|
| 125 |
+
# We need to adjust destination paths for assets to remove the
|
| 126 |
+
# purely functional posts directory prefix when building
|
| 127 |
+
file.dest_uri = file.dest_uri.replace(path, root)
|
| 128 |
+
file.abs_dest_path = os.path.join(site, file.dest_path)
|
| 129 |
+
file.url = file.url.replace(path, root)
|
| 130 |
+
|
| 131 |
+
# Resolve entrypoint and posts sorted by descending date - if the posts
|
| 132 |
+
# directory or entrypoint do not exist, they are automatically created
|
| 133 |
+
self.blog = self._resolve(files, config)
|
| 134 |
+
self.blog.posts = sorted(
|
| 135 |
+
self._resolve_posts(files, config),
|
| 136 |
+
key = lambda post: (
|
| 137 |
+
post.config.pin,
|
| 138 |
+
post.config.date.created
|
| 139 |
+
),
|
| 140 |
+
reverse = True
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
# Generate views for archive
|
| 144 |
+
if self.config.archive:
|
| 145 |
+
views = self._generate_archive(config, files)
|
| 146 |
+
self.blog.views.extend(views)
|
| 147 |
+
|
| 148 |
+
# Generate views for categories
|
| 149 |
+
if self.config.categories:
|
| 150 |
+
views = self._generate_categories(config, files)
|
| 151 |
+
|
| 152 |
+
# We always sort the list of categories by name first, so that any
|
| 153 |
+
# custom sorting function that returns the same value for two items
|
| 154 |
+
# returns them in a predictable and logical order, because sorting
|
| 155 |
+
# in Python is stable, i.e., order of equal items is preserved
|
| 156 |
+
self.blog.views.extend(sorted(
|
| 157 |
+
sorted(views, key = view_name),
|
| 158 |
+
key = self.config.categories_sort_by,
|
| 159 |
+
reverse = self.config.categories_sort_reverse
|
| 160 |
+
))
|
| 161 |
+
|
| 162 |
+
# Generate views for profiles
|
| 163 |
+
if self.config.authors_profiles:
|
| 164 |
+
views = self._generate_profiles(config, files)
|
| 165 |
+
self.blog.views.extend(views)
|
| 166 |
+
|
| 167 |
+
# Generate pages for views
|
| 168 |
+
for view in self._resolve_views(self.blog):
|
| 169 |
+
if self._config_pagination(view):
|
| 170 |
+
for page in self._generate_pages(view, config, files):
|
| 171 |
+
view.pages.append(page)
|
| 172 |
+
|
| 173 |
+
# Ensure that entrypoint is always included in navigation
|
| 174 |
+
self.blog.file.inclusion = InclusionLevel.INCLUDED
|
| 175 |
+
|
| 176 |
+
# Attach posts and views to navigation (run later) - again, we allow other
|
| 177 |
+
# plugins to alter the navigation before we start to attach posts and views
|
| 178 |
+
# generated by this plugin at the correct locations in the navigation. Also,
|
| 179 |
+
# we make sure to correct links to the parent and siblings of each page.
|
| 180 |
+
@event_priority(-50)
|
| 181 |
+
def on_nav(self, nav, *, config, files):
|
| 182 |
+
if not self.config.enabled:
|
| 183 |
+
return
|
| 184 |
+
|
| 185 |
+
# If we're not building a standalone blog, the entrypoint will always
|
| 186 |
+
# have a parent when it is included in the navigation. The parent is
|
| 187 |
+
# essential to correctly resolve the location where the archive and
|
| 188 |
+
# category views are attached. If the entrypoint doesn't have a parent,
|
| 189 |
+
# we know that the author did not include it in the navigation, so we
|
| 190 |
+
# explicitly mark it as not included.
|
| 191 |
+
if not self.blog.parent and self.config.blog_dir != ".":
|
| 192 |
+
self.blog.file.inclusion = InclusionLevel.NOT_IN_NAV
|
| 193 |
+
|
| 194 |
+
# Attach posts to entrypoint without adding them to the navigation, so
|
| 195 |
+
# that the entrypoint is considered to be the active page for each post
|
| 196 |
+
self._attach(self.blog, [None, *reversed(self.blog.posts), None])
|
| 197 |
+
for post in self.blog.posts:
|
| 198 |
+
post.file.inclusion = InclusionLevel.NOT_IN_NAV
|
| 199 |
+
|
| 200 |
+
# Revert temporary exclusion of views from navigation
|
| 201 |
+
for view in self._resolve_views(self.blog):
|
| 202 |
+
view.file.inclusion = self.blog.file.inclusion
|
| 203 |
+
for page in view.pages:
|
| 204 |
+
page.file.inclusion = self.blog.file.inclusion
|
| 205 |
+
|
| 206 |
+
# Attach views for archive
|
| 207 |
+
if self.config.archive:
|
| 208 |
+
title = self._translate(self.config.archive_name, config)
|
| 209 |
+
views = [_ for _ in self.blog.views if isinstance(_, Archive)]
|
| 210 |
+
|
| 211 |
+
# Attach and link views for archive
|
| 212 |
+
if self.blog.file.inclusion.is_in_nav():
|
| 213 |
+
self._attach_to(self.blog, Section(title, views), nav)
|
| 214 |
+
|
| 215 |
+
# Attach views for categories
|
| 216 |
+
if self.config.categories:
|
| 217 |
+
title = self._translate(self.config.categories_name, config)
|
| 218 |
+
views = [_ for _ in self.blog.views if isinstance(_, Category)]
|
| 219 |
+
|
| 220 |
+
# Attach and link views for categories, if any
|
| 221 |
+
if self.blog.file.inclusion.is_in_nav() and views:
|
| 222 |
+
self._attach_to(self.blog, Section(title, views), nav)
|
| 223 |
+
|
| 224 |
+
# Attach views for profiles
|
| 225 |
+
if self.config.authors_profiles:
|
| 226 |
+
title = self._translate(self.config.authors_profiles_name, config)
|
| 227 |
+
views = [_ for _ in self.blog.views if isinstance(_, Profile)]
|
| 228 |
+
|
| 229 |
+
# Attach and link views for categories, if any
|
| 230 |
+
if self.blog.file.inclusion.is_in_nav() and views:
|
| 231 |
+
self._attach_to(self.blog, Section(title, views), nav)
|
| 232 |
+
|
| 233 |
+
# Attach pages for views
|
| 234 |
+
for view in self._resolve_views(self.blog):
|
| 235 |
+
if self._config_pagination(view):
|
| 236 |
+
for at in range(1, len(view.pages)):
|
| 237 |
+
self._attach_at(view.parent, view, view.pages[at])
|
| 238 |
+
|
| 239 |
+
# Prepare post for rendering (run later) - allow other plugins to alter
|
| 240 |
+
# the contents or metadata of a post before it is rendered and make sure
|
| 241 |
+
# that the post includes a separator, which is essential for rendering
|
| 242 |
+
# excerpts that should be included in views
|
| 243 |
+
@event_priority(-50)
|
| 244 |
+
def on_page_markdown(self, markdown, *, page, config, files):
|
| 245 |
+
if not self.config.enabled:
|
| 246 |
+
return
|
| 247 |
+
|
| 248 |
+
# Skip if page is not a post managed by this instance - this plugin has
|
| 249 |
+
# support for multiple instances, which is why this check is necessary
|
| 250 |
+
if page not in self.blog.posts:
|
| 251 |
+
if not self._config_pagination(page):
|
| 252 |
+
return
|
| 253 |
+
|
| 254 |
+
# We set the contents of the view to its title if pagination should
|
| 255 |
+
# not keep the content of the original view on paginated views
|
| 256 |
+
if not self.config.pagination_keep_content:
|
| 257 |
+
view = self._resolve_original(page)
|
| 258 |
+
if view in self._resolve_views(self.blog):
|
| 259 |
+
|
| 260 |
+
# If the current view is paginated, use the rendered title
|
| 261 |
+
# of the original view in case the author set the title in
|
| 262 |
+
# the page's contents, or it would be overridden with the
|
| 263 |
+
# one set in mkdocs.yml, leading to inconsistent headings
|
| 264 |
+
assert isinstance(view, View)
|
| 265 |
+
if view != page:
|
| 266 |
+
name = view._title_from_render or view.title
|
| 267 |
+
return f"# {name}"
|
| 268 |
+
|
| 269 |
+
# Nothing more to be done for views
|
| 270 |
+
return
|
| 271 |
+
|
| 272 |
+
# Extract and assign authors to post, if enabled
|
| 273 |
+
if self.config.authors:
|
| 274 |
+
for id in page.config.authors:
|
| 275 |
+
if id not in self.authors:
|
| 276 |
+
raise PluginError(f"Couldn't find author '{id}'")
|
| 277 |
+
|
| 278 |
+
# Append to list of authors
|
| 279 |
+
page.authors.append(self.authors[id])
|
| 280 |
+
|
| 281 |
+
# Extract settings for excerpts
|
| 282 |
+
separator = self.config.post_excerpt_separator
|
| 283 |
+
max_authors = self.config.post_excerpt_max_authors
|
| 284 |
+
max_categories = self.config.post_excerpt_max_categories
|
| 285 |
+
|
| 286 |
+
# Ensure presence of separator and throw, if its absent and required -
|
| 287 |
+
# we append the separator to the end of the contents of the post, if it
|
| 288 |
+
# is not already present, so we can remove footnotes or other content
|
| 289 |
+
# from the excerpt without affecting the content of the excerpt
|
| 290 |
+
if separator not in page.markdown:
|
| 291 |
+
if self.config.post_excerpt == "required":
|
| 292 |
+
docs = os.path.relpath(config.docs_dir)
|
| 293 |
+
path = os.path.relpath(page.file.abs_src_path, docs)
|
| 294 |
+
raise PluginError(
|
| 295 |
+
f"Couldn't find '{separator}' in post '{path}' in '{docs}'"
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
# Create excerpt for post and inherit authors and categories - excerpts
|
| 299 |
+
# can contain a subset of the authors and categories of the post
|
| 300 |
+
page.excerpt = Excerpt(page, config, files)
|
| 301 |
+
page.excerpt.authors = page.authors[:max_authors]
|
| 302 |
+
page.excerpt.categories = page.categories[:max_categories]
|
| 303 |
+
|
| 304 |
+
# Process posts
|
| 305 |
+
def on_page_content(self, html, *, page, config, files):
|
| 306 |
+
if not self.config.enabled:
|
| 307 |
+
return
|
| 308 |
+
|
| 309 |
+
# Skip if page is not a post managed by this instance - this plugin has
|
| 310 |
+
# support for multiple instances, which is why this check is necessary
|
| 311 |
+
if page not in self.blog.posts:
|
| 312 |
+
return
|
| 313 |
+
|
| 314 |
+
# Compute readtime of post, if enabled and not explicitly set
|
| 315 |
+
if self.config.post_readtime:
|
| 316 |
+
words_per_minute = self.config.post_readtime_words_per_minute
|
| 317 |
+
if not page.config.readtime:
|
| 318 |
+
page.config.readtime = readtime(html, words_per_minute)
|
| 319 |
+
|
| 320 |
+
# Register template filters for plugin
|
| 321 |
+
def on_env(self, env, *, config, files):
|
| 322 |
+
if not self.config.enabled:
|
| 323 |
+
return
|
| 324 |
+
|
| 325 |
+
# Transform links to point to posts and pages
|
| 326 |
+
for post in self.blog.posts:
|
| 327 |
+
self._generate_links(post, config, files)
|
| 328 |
+
|
| 329 |
+
# Filter for formatting dates related to posts
|
| 330 |
+
def date_filter(date: datetime):
|
| 331 |
+
return self._format_date_for_post(date, config)
|
| 332 |
+
|
| 333 |
+
# Fetch URL template filter from environment - the filter might
|
| 334 |
+
# be overridden by other plugins, so we must retrieve and wrap it
|
| 335 |
+
url_filter = env.filters["url"]
|
| 336 |
+
|
| 337 |
+
# Patch URL template filter to add support for paginated views, i.e.,
|
| 338 |
+
# that paginated views never link to themselves but to the main vie
|
| 339 |
+
@pass_context
|
| 340 |
+
def url_filter_with_pagination(context: Context, url: str | None):
|
| 341 |
+
page = context["page"]
|
| 342 |
+
|
| 343 |
+
# If the current page is a view, check if the URL links to the page
|
| 344 |
+
# itself, and replace it with the URL of the main view
|
| 345 |
+
if isinstance(page, View):
|
| 346 |
+
view = self._resolve_original(page)
|
| 347 |
+
if page.url == url:
|
| 348 |
+
url = view.url
|
| 349 |
+
|
| 350 |
+
# Forward to original template filter
|
| 351 |
+
return url_filter(context, url)
|
| 352 |
+
|
| 353 |
+
# Register custom template filters
|
| 354 |
+
env.filters["date"] = date_filter
|
| 355 |
+
env.filters["url"] = url_filter_with_pagination
|
| 356 |
+
|
| 357 |
+
# Prepare view for rendering (run latest) - views are rendered last, as we
|
| 358 |
+
# need to mutate the navigation to account for pagination. The main problem
|
| 359 |
+
# is that we need to replace the view in the navigation, because otherwise
|
| 360 |
+
# the view would not be considered active.
|
| 361 |
+
@event_priority(-100)
|
| 362 |
+
def on_page_context(self, context, *, page, config, nav):
|
| 363 |
+
if not self.config.enabled:
|
| 364 |
+
return
|
| 365 |
+
|
| 366 |
+
# Skip if page is not a view managed by this instance - this plugin has
|
| 367 |
+
# support for multiple instances, which is why this check is necessary
|
| 368 |
+
view = self._resolve_original(page)
|
| 369 |
+
if view not in self._resolve_views(self.blog):
|
| 370 |
+
return
|
| 371 |
+
|
| 372 |
+
# Render excerpts and prepare pagination
|
| 373 |
+
posts, pagination = self._render(page)
|
| 374 |
+
|
| 375 |
+
# Render pagination links
|
| 376 |
+
def pager(args: object):
|
| 377 |
+
return pagination.pager(
|
| 378 |
+
format = self.config.pagination_format,
|
| 379 |
+
show_if_single_page = self.config.pagination_if_single_page,
|
| 380 |
+
**args
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
# Assign posts and pagination to context
|
| 384 |
+
context["posts"] = posts
|
| 385 |
+
context["pagination"] = pager if pagination else None
|
| 386 |
+
|
| 387 |
+
# Remove temporary directory on shutdown
|
| 388 |
+
def on_shutdown(self):
|
| 389 |
+
rmtree(self.temp_dir)
|
| 390 |
+
|
| 391 |
+
# -------------------------------------------------------------------------
|
| 392 |
+
|
| 393 |
+
# Check if the given post is excluded
|
| 394 |
+
def _is_excluded(self, post: Post):
|
| 395 |
+
if self.config.draft:
|
| 396 |
+
return False
|
| 397 |
+
|
| 398 |
+
# If a post was not explicitly marked or unmarked as draft, and the
|
| 399 |
+
# date should be taken into account, we automatically mark it as draft
|
| 400 |
+
# if the publishing date is in the future. This, of course, is opt-in
|
| 401 |
+
# and must be explicitly enabled by the author.
|
| 402 |
+
if not isinstance(post.config.draft, bool):
|
| 403 |
+
if self.config.draft_if_future_date:
|
| 404 |
+
return post.config.date.created > datetime.now(timezone.utc)
|
| 405 |
+
|
| 406 |
+
# Post might be a draft
|
| 407 |
+
return bool(post.config.draft)
|
| 408 |
+
|
| 409 |
+
# -------------------------------------------------------------------------
|
| 410 |
+
|
| 411 |
+
# Resolve entrypoint - the entrypoint of the blog must have been created
|
| 412 |
+
# if it did not exist before, and hosts all posts sorted by descending date
|
| 413 |
+
def _resolve(self, files: Files, config: MkDocsConfig):
|
| 414 |
+
path = os.path.join(self.config.blog_dir, "index.md")
|
| 415 |
+
path = os.path.normpath(path)
|
| 416 |
+
|
| 417 |
+
# Create entrypoint, if it does not exist - note that the entrypoint is
|
| 418 |
+
# created in the docs directory, not in the temporary directory
|
| 419 |
+
docs = os.path.relpath(config.docs_dir)
|
| 420 |
+
name = os.path.join(docs, path)
|
| 421 |
+
if not os.path.isfile(name):
|
| 422 |
+
file = self._path_to_file(path, config, temp = False)
|
| 423 |
+
files.append(file)
|
| 424 |
+
|
| 425 |
+
# Create file in docs directory
|
| 426 |
+
self._save_to_file(file.abs_src_path, "# Blog\n\n")
|
| 427 |
+
|
| 428 |
+
# Create and return entrypoint
|
| 429 |
+
file = files.get_file_from_path(path)
|
| 430 |
+
return View(None, file, config)
|
| 431 |
+
|
| 432 |
+
# Resolve post - the caller must make sure that the given file points to an
|
| 433 |
+
# actual post (and not a page), or behavior might be unpredictable
|
| 434 |
+
def _resolve_post(self, file: File, config: MkDocsConfig):
|
| 435 |
+
post = Post(file, config)
|
| 436 |
+
|
| 437 |
+
# Compute path and create a temporary file for path resolution
|
| 438 |
+
path = self._format_path_for_post(post, config)
|
| 439 |
+
temp = self._path_to_file(path, config, temp = False)
|
| 440 |
+
|
| 441 |
+
# Replace destination file system path and URL
|
| 442 |
+
file.dest_uri = temp.dest_uri
|
| 443 |
+
file.abs_dest_path = temp.abs_dest_path
|
| 444 |
+
file.url = temp.url
|
| 445 |
+
|
| 446 |
+
# Replace canonical URL and return post
|
| 447 |
+
post._set_canonical_url(config.site_url)
|
| 448 |
+
return post
|
| 449 |
+
|
| 450 |
+
# Resolve posts from directory - traverse all documentation pages and filter
|
| 451 |
+
# and yield those that are located in the posts directory
|
| 452 |
+
def _resolve_posts(self, files: Files, config: MkDocsConfig):
|
| 453 |
+
path = self.config.post_dir.format(blog = self.config.blog_dir)
|
| 454 |
+
path = os.path.normpath(path)
|
| 455 |
+
|
| 456 |
+
# Create posts directory, if it does not exist
|
| 457 |
+
docs = os.path.relpath(config.docs_dir)
|
| 458 |
+
name = os.path.join(docs, path)
|
| 459 |
+
if not os.path.isdir(name):
|
| 460 |
+
os.makedirs(name, exist_ok = True)
|
| 461 |
+
|
| 462 |
+
# Filter posts from pages
|
| 463 |
+
for file in files.documentation_pages():
|
| 464 |
+
if not file.src_path.startswith(path):
|
| 465 |
+
continue
|
| 466 |
+
|
| 467 |
+
# Temporarily remove post from navigation
|
| 468 |
+
file.inclusion = InclusionLevel.EXCLUDED
|
| 469 |
+
|
| 470 |
+
# Resolve post - in order to determine whether a post should be
|
| 471 |
+
# excluded, we must load it and analyze its metadata. All posts
|
| 472 |
+
# marked as drafts are excluded, except for when the author has
|
| 473 |
+
# configured drafts to be included in the navigation.
|
| 474 |
+
post = self._resolve_post(file, config)
|
| 475 |
+
if not self._is_excluded(post):
|
| 476 |
+
yield post
|
| 477 |
+
|
| 478 |
+
# Resolve authors - check if there's an authors file at the configured
|
| 479 |
+
# location, and if one was found, load and validate it
|
| 480 |
+
def _resolve_authors(self, config: MkDocsConfig):
|
| 481 |
+
path = self.config.authors_file.format(blog = self.config.blog_dir)
|
| 482 |
+
path = os.path.normpath(path)
|
| 483 |
+
|
| 484 |
+
# Resolve path relative to docs directory
|
| 485 |
+
docs = os.path.relpath(config.docs_dir)
|
| 486 |
+
file = os.path.join(docs, path)
|
| 487 |
+
|
| 488 |
+
# If the authors file does not exist, return here
|
| 489 |
+
config: Authors = Authors()
|
| 490 |
+
if not os.path.isfile(file):
|
| 491 |
+
return config.authors
|
| 492 |
+
|
| 493 |
+
# Open file and parse as YAML
|
| 494 |
+
with open(file, encoding = "utf-8-sig") as f:
|
| 495 |
+
config.config_file_path = os.path.abspath(file)
|
| 496 |
+
try:
|
| 497 |
+
config.load_dict(yaml.load(f, SafeLoader) or {})
|
| 498 |
+
|
| 499 |
+
# The authors file could not be loaded because of a syntax error,
|
| 500 |
+
# which we display to the author with a nice error message
|
| 501 |
+
except Exception as e:
|
| 502 |
+
raise PluginError(
|
| 503 |
+
f"Error reading authors file '{path}' in '{docs}':\n"
|
| 504 |
+
f"{e}"
|
| 505 |
+
)
|
| 506 |
+
|
| 507 |
+
# Validate authors and throw if errors occurred
|
| 508 |
+
errors, warnings = config.validate()
|
| 509 |
+
for _, w in warnings:
|
| 510 |
+
log.warning(w)
|
| 511 |
+
for _, e in errors:
|
| 512 |
+
raise PluginError(
|
| 513 |
+
f"Error reading authors file '{path}' in '{docs}':\n"
|
| 514 |
+
f"{e}"
|
| 515 |
+
)
|
| 516 |
+
|
| 517 |
+
# Return authors
|
| 518 |
+
return config.authors
|
| 519 |
+
|
| 520 |
+
# Resolve views of the given view in pre-order
|
| 521 |
+
def _resolve_views(self, view: View):
|
| 522 |
+
yield view
|
| 523 |
+
|
| 524 |
+
# Resolve views recursively
|
| 525 |
+
for page in view.views:
|
| 526 |
+
for next in self._resolve_views(page):
|
| 527 |
+
assert isinstance(next, View)
|
| 528 |
+
yield next
|
| 529 |
+
|
| 530 |
+
# Resolve siblings of a navigation item
|
| 531 |
+
def _resolve_siblings(self, item: StructureItem, nav: Navigation):
|
| 532 |
+
if isinstance(item.parent, Section):
|
| 533 |
+
return item.parent.children
|
| 534 |
+
else:
|
| 535 |
+
return nav.items
|
| 536 |
+
|
| 537 |
+
# Resolve original page or view (e.g. for paginated views)
|
| 538 |
+
def _resolve_original(self, page: Page):
|
| 539 |
+
if isinstance(page, View) and page.pages:
|
| 540 |
+
return page.pages[0]
|
| 541 |
+
else:
|
| 542 |
+
return page
|
| 543 |
+
|
| 544 |
+
# -------------------------------------------------------------------------
|
| 545 |
+
|
| 546 |
+
# Generate views for archive - analyze posts and generate the necessary
|
| 547 |
+
# views, taking the date format provided by the author into account
|
| 548 |
+
def _generate_archive(self, config: MkDocsConfig, files: Files):
|
| 549 |
+
for post in self.blog.posts:
|
| 550 |
+
date = post.config.date.created
|
| 551 |
+
|
| 552 |
+
# Compute name and path of archive view
|
| 553 |
+
name = self._format_date_for_archive(date, config)
|
| 554 |
+
path = self._format_path_for_archive(post, config)
|
| 555 |
+
|
| 556 |
+
# Create file for view, if it does not exist
|
| 557 |
+
file = files.get_file_from_path(path)
|
| 558 |
+
if not file:
|
| 559 |
+
file = self._path_to_file(path, config)
|
| 560 |
+
files.append(file)
|
| 561 |
+
|
| 562 |
+
# Create file in temporary directory
|
| 563 |
+
self._save_to_file(file.abs_src_path, f"# {name}")
|
| 564 |
+
|
| 565 |
+
# Temporarily remove view from navigation
|
| 566 |
+
file.inclusion = InclusionLevel.EXCLUDED
|
| 567 |
+
|
| 568 |
+
# Create and yield view
|
| 569 |
+
if not isinstance(file.page, Archive):
|
| 570 |
+
yield Archive(name, file, config)
|
| 571 |
+
|
| 572 |
+
# Assign post to archive
|
| 573 |
+
assert isinstance(file.page, Archive)
|
| 574 |
+
file.page.posts.append(post)
|
| 575 |
+
|
| 576 |
+
# Generate views for categories - analyze posts and generate the necessary
|
| 577 |
+
# views, taking the allowed categories as set by the author into account
|
| 578 |
+
def _generate_categories(self, config: MkDocsConfig, files: Files):
|
| 579 |
+
for post in self.blog.posts:
|
| 580 |
+
for name in post.config.categories:
|
| 581 |
+
path = self._format_path_for_category(name)
|
| 582 |
+
|
| 583 |
+
# Ensure category is in non-empty allow list
|
| 584 |
+
categories = self.config.categories_allowed or [name]
|
| 585 |
+
if name not in categories:
|
| 586 |
+
docs = os.path.relpath(config.docs_dir)
|
| 587 |
+
path = os.path.relpath(post.file.abs_src_path, docs)
|
| 588 |
+
raise PluginError(
|
| 589 |
+
f"Error reading categories of post '{path}' in "
|
| 590 |
+
f"'{docs}': category '{name}' not in allow list"
|
| 591 |
+
)
|
| 592 |
+
|
| 593 |
+
# Create file for view, if it does not exist
|
| 594 |
+
file = files.get_file_from_path(path)
|
| 595 |
+
if not file:
|
| 596 |
+
file = self._path_to_file(path, config)
|
| 597 |
+
files.append(file)
|
| 598 |
+
|
| 599 |
+
# Create file in temporary directory
|
| 600 |
+
self._save_to_file(file.abs_src_path, f"# {name}")
|
| 601 |
+
|
| 602 |
+
# Temporarily remove view from navigation
|
| 603 |
+
file.inclusion = InclusionLevel.EXCLUDED
|
| 604 |
+
|
| 605 |
+
# Create and yield view
|
| 606 |
+
if not isinstance(file.page, Category):
|
| 607 |
+
yield Category(name, file, config)
|
| 608 |
+
|
| 609 |
+
# Assign post to category and vice versa
|
| 610 |
+
assert isinstance(file.page, Category)
|
| 611 |
+
file.page.posts.append(post)
|
| 612 |
+
post.categories.append(file.page)
|
| 613 |
+
|
| 614 |
+
# Generate views for profiles - analyze posts and generate the necessary
|
| 615 |
+
# views to provide a profile page for each author listing all posts
|
| 616 |
+
def _generate_profiles(self, config: MkDocsConfig, files: Files):
|
| 617 |
+
for post in self.blog.posts:
|
| 618 |
+
for id in post.config.authors:
|
| 619 |
+
author = self.authors[id]
|
| 620 |
+
path = self._format_path_for_profile(id, author)
|
| 621 |
+
|
| 622 |
+
# Create file for view, if it does not exist
|
| 623 |
+
file = files.get_file_from_path(path)
|
| 624 |
+
if not file:
|
| 625 |
+
file = self._path_to_file(path, config)
|
| 626 |
+
files.append(file)
|
| 627 |
+
|
| 628 |
+
# Create file in temporary directory
|
| 629 |
+
self._save_to_file(file.abs_src_path, f"# {author.name}")
|
| 630 |
+
|
| 631 |
+
# Temporarily remove view from navigation and assign profile
|
| 632 |
+
# URL to author, if not explicitly set
|
| 633 |
+
file.inclusion = InclusionLevel.EXCLUDED
|
| 634 |
+
if not author.url:
|
| 635 |
+
author.url = file.url
|
| 636 |
+
|
| 637 |
+
# Create and yield view
|
| 638 |
+
if not isinstance(file.page, Profile):
|
| 639 |
+
yield Profile(author.name, file, config)
|
| 640 |
+
|
| 641 |
+
# Assign post to profile
|
| 642 |
+
assert isinstance(file.page, Profile)
|
| 643 |
+
file.page.posts.append(post)
|
| 644 |
+
|
| 645 |
+
# Generate pages for pagination - analyze view and generate the necessary
|
| 646 |
+
# pages, creating a chain of views for simple rendering and replacement
|
| 647 |
+
def _generate_pages(self, view: View, config: MkDocsConfig, files: Files):
|
| 648 |
+
yield view
|
| 649 |
+
|
| 650 |
+
# Compute pagination boundaries and create pages - pages are internally
|
| 651 |
+
# handled as copies of a view, as they map to the same source location
|
| 652 |
+
step = self._config_pagination_per_page(view)
|
| 653 |
+
for at in range(step, len(view.posts), step):
|
| 654 |
+
path = self._format_path_for_pagination(view, 1 + at // step)
|
| 655 |
+
|
| 656 |
+
# Create file for view, if it does not exist
|
| 657 |
+
file = files.get_file_from_path(path)
|
| 658 |
+
if not file:
|
| 659 |
+
file = self._path_to_file(path, config)
|
| 660 |
+
files.append(file)
|
| 661 |
+
|
| 662 |
+
# Copy file to temporary directory
|
| 663 |
+
copy_file(view.file.abs_src_path, file.abs_src_path)
|
| 664 |
+
|
| 665 |
+
# Temporarily remove view from navigation
|
| 666 |
+
file.inclusion = InclusionLevel.EXCLUDED
|
| 667 |
+
|
| 668 |
+
# Create and yield view
|
| 669 |
+
if not isinstance(file.page, View):
|
| 670 |
+
yield view.__class__(None, file, config)
|
| 671 |
+
|
| 672 |
+
# Assign pages and posts to view
|
| 673 |
+
assert isinstance(file.page, View)
|
| 674 |
+
file.page.pages = view.pages
|
| 675 |
+
file.page.posts = view.posts
|
| 676 |
+
|
| 677 |
+
# Generate links from the given post to other posts, pages, and sections -
|
| 678 |
+
# this can only be done once all posts and pages have been parsed
|
| 679 |
+
def _generate_links(self, post: Post, config: MkDocsConfig, files: Files):
|
| 680 |
+
if not post.config.links:
|
| 681 |
+
return
|
| 682 |
+
|
| 683 |
+
# Resolve path relative to docs directory for error reporting
|
| 684 |
+
docs = os.path.relpath(config.docs_dir)
|
| 685 |
+
path = os.path.relpath(post.file.abs_src_path, docs)
|
| 686 |
+
|
| 687 |
+
# Find all links to pages and replace them with references - while all
|
| 688 |
+
# internal links are processed, external links remain as they are
|
| 689 |
+
for link in _find_links(post.config.links.items):
|
| 690 |
+
url = urlparse(link.url)
|
| 691 |
+
if url.scheme:
|
| 692 |
+
continue
|
| 693 |
+
|
| 694 |
+
# Resolve file for link, and throw if the file could not be found -
|
| 695 |
+
# authors can link to other pages, as well as to assets or files of
|
| 696 |
+
# any kind, but it is essential that the file that is linked to is
|
| 697 |
+
# found, so errors are actually catched and reported
|
| 698 |
+
file = files.get_file_from_path(url.path)
|
| 699 |
+
if not file:
|
| 700 |
+
log.warning(
|
| 701 |
+
f"Error reading metadata of post '{path}' in '{docs}':\n"
|
| 702 |
+
f"Couldn't find file for link '{url.path}'"
|
| 703 |
+
)
|
| 704 |
+
continue
|
| 705 |
+
|
| 706 |
+
# If the file linked to is not a page, but an asset or any other
|
| 707 |
+
# file, we resolve the destination URL and continue
|
| 708 |
+
if not isinstance(file.page, Page):
|
| 709 |
+
link.url = file.url
|
| 710 |
+
continue
|
| 711 |
+
|
| 712 |
+
# Cast link to reference
|
| 713 |
+
link.__class__ = Reference
|
| 714 |
+
assert isinstance(link, Reference)
|
| 715 |
+
|
| 716 |
+
# Assign page title, URL and metadata to link
|
| 717 |
+
link.title = link.title or file.page.title
|
| 718 |
+
link.url = file.page.url
|
| 719 |
+
link.meta = copy(file.page.meta)
|
| 720 |
+
|
| 721 |
+
# If the link has no fragment, we can continue - if it does, we
|
| 722 |
+
# need to find the matching anchor in the table of contents
|
| 723 |
+
if not url.fragment:
|
| 724 |
+
continue
|
| 725 |
+
|
| 726 |
+
# If we're running under dirty reload, MkDocs will reset all pages,
|
| 727 |
+
# so it's not possible to resolve anchor links. Thus, the only way
|
| 728 |
+
# to make this work is to skip the entire process of anchor link
|
| 729 |
+
# resolution in case of a dirty reload.
|
| 730 |
+
if self.is_dirty:
|
| 731 |
+
continue
|
| 732 |
+
|
| 733 |
+
# Resolve anchor for fragment, and throw if the anchor could not be
|
| 734 |
+
# found - authors can link to any anchor in the table of contents
|
| 735 |
+
anchor = _find_anchor(file.page.toc, url.fragment)
|
| 736 |
+
if not anchor:
|
| 737 |
+
log.warning(
|
| 738 |
+
f"Error reading metadata of post '{path}' in '{docs}':\n"
|
| 739 |
+
f"Couldn't find anchor '{url.fragment}' in '{url.path}'"
|
| 740 |
+
)
|
| 741 |
+
|
| 742 |
+
# Restore link to original state
|
| 743 |
+
link.url = url.geturl()
|
| 744 |
+
continue
|
| 745 |
+
|
| 746 |
+
# Append anchor to URL and set subtitle
|
| 747 |
+
link.url += f"#{anchor.id}"
|
| 748 |
+
link.meta["subtitle"] = anchor.title
|
| 749 |
+
|
| 750 |
+
# -------------------------------------------------------------------------
|
| 751 |
+
|
| 752 |
+
# Attach a list of pages to each other and to the given parent item without
|
| 753 |
+
# explicitly adding them to the navigation, which can be done by the caller
|
| 754 |
+
def _attach(self, parent: StructureItem, pages: list[Page]):
|
| 755 |
+
for tail, page, head in zip(pages, pages[1:], pages[2:]):
|
| 756 |
+
|
| 757 |
+
# Link page to parent and siblings
|
| 758 |
+
page.parent = parent
|
| 759 |
+
page.previous_page = tail
|
| 760 |
+
page.next_page = head
|
| 761 |
+
|
| 762 |
+
# If the page is a view, we know that we generated it and need to
|
| 763 |
+
# link its siblings back to the view
|
| 764 |
+
if isinstance(page, View):
|
| 765 |
+
view = self._resolve_original(page)
|
| 766 |
+
if tail: tail.next_page = view
|
| 767 |
+
if head: head.previous_page = view
|
| 768 |
+
|
| 769 |
+
# Attach a page to the given parent and link it to the previous and next
|
| 770 |
+
# page of the given host - this is exclusively used for paginated views
|
| 771 |
+
def _attach_at(self, parent: StructureItem, host: Page, page: Page):
|
| 772 |
+
self._attach(parent, [host.previous_page, page, host.next_page])
|
| 773 |
+
|
| 774 |
+
# Attach a section as a sibling to the given view, make sure its pages are
|
| 775 |
+
# part of the navigation, and ensure all pages are linked correctly
|
| 776 |
+
def _attach_to(self, view: View, section: Section, nav: Navigation):
|
| 777 |
+
section.parent = view.parent
|
| 778 |
+
|
| 779 |
+
# Resolve siblings, which are the children of the parent section, or
|
| 780 |
+
# the top-level list of navigation items if the view is at the root of
|
| 781 |
+
# the project, and append the given section to it. It's currently not
|
| 782 |
+
# possible to chose the position of a section.
|
| 783 |
+
items = self._resolve_siblings(view, nav)
|
| 784 |
+
items.append(section)
|
| 785 |
+
|
| 786 |
+
# Find last sibling that is a page, skipping sections, as we need to
|
| 787 |
+
# append the given section after all other pages
|
| 788 |
+
tail = next(item for item in reversed(items) if isinstance(item, Page))
|
| 789 |
+
head = tail.next_page
|
| 790 |
+
|
| 791 |
+
# Attach section to navigation and pages to each other
|
| 792 |
+
nav.pages.extend(section.children)
|
| 793 |
+
self._attach(section, [tail, *section.children, head])
|
| 794 |
+
|
| 795 |
+
# -------------------------------------------------------------------------
|
| 796 |
+
|
| 797 |
+
# Render excerpts and pagination for the given view
|
| 798 |
+
def _render(self, view: View):
|
| 799 |
+
posts, pagination = view.posts, None
|
| 800 |
+
|
| 801 |
+
# Create pagination, if enabled
|
| 802 |
+
if self._config_pagination(view):
|
| 803 |
+
at = view.pages.index(view)
|
| 804 |
+
|
| 805 |
+
# Compute pagination boundaries
|
| 806 |
+
step = self._config_pagination_per_page(view)
|
| 807 |
+
p, q = at * step, at * step + step
|
| 808 |
+
|
| 809 |
+
# Extract posts in pagination boundaries
|
| 810 |
+
posts = view.posts[p:q]
|
| 811 |
+
pagination = self._render_pagination(view, (p, q))
|
| 812 |
+
|
| 813 |
+
# Render excerpts for selected posts
|
| 814 |
+
posts = [
|
| 815 |
+
self._render_post(post.excerpt, view)
|
| 816 |
+
for post in posts if post.excerpt
|
| 817 |
+
]
|
| 818 |
+
|
| 819 |
+
# Return posts and pagination
|
| 820 |
+
return posts, pagination
|
| 821 |
+
|
| 822 |
+
# Render excerpt in the context of the given view
|
| 823 |
+
def _render_post(self, excerpt: Excerpt, view: View):
|
| 824 |
+
excerpt.render(view, self.config.post_excerpt_separator)
|
| 825 |
+
|
| 826 |
+
# Attach top-level table of contents item to view if it should be added
|
| 827 |
+
# and both, the view and excerpt contain table of contents items
|
| 828 |
+
toc = self._config_toc(view)
|
| 829 |
+
if toc and excerpt.toc.items and view.toc.items:
|
| 830 |
+
view.toc.items[0].children.append(excerpt.toc.items[0])
|
| 831 |
+
|
| 832 |
+
# Return excerpt
|
| 833 |
+
return excerpt
|
| 834 |
+
|
| 835 |
+
# Create pagination for the given view and range
|
| 836 |
+
def _render_pagination(self, view: View, range: tuple[int, int]):
|
| 837 |
+
p, q = range
|
| 838 |
+
|
| 839 |
+
# Create URL from the given page to another page
|
| 840 |
+
def url_maker(n: int):
|
| 841 |
+
return get_relative_url(view.pages[n - 1].url, view.url)
|
| 842 |
+
|
| 843 |
+
# Return pagination
|
| 844 |
+
return Pagination(
|
| 845 |
+
view.posts, page = q // (q - p),
|
| 846 |
+
items_per_page = q - p,
|
| 847 |
+
url_maker = url_maker
|
| 848 |
+
)
|
| 849 |
+
|
| 850 |
+
# -------------------------------------------------------------------------
|
| 851 |
+
|
| 852 |
+
# Retrieve configuration value or return default
|
| 853 |
+
def _config(self, key: str, default: any):
|
| 854 |
+
return default if self.config[key] is None else self.config[key]
|
| 855 |
+
|
| 856 |
+
# Retrieve configuration value for table of contents
|
| 857 |
+
def _config_toc(self, view: View):
|
| 858 |
+
default = self.config.blog_toc
|
| 859 |
+
if isinstance(view, Archive):
|
| 860 |
+
return self._config("archive_toc", default)
|
| 861 |
+
if isinstance(view, Category):
|
| 862 |
+
return self._config("categories_toc", default)
|
| 863 |
+
if isinstance(view, Profile):
|
| 864 |
+
return self._config("authors_profiles_toc", default)
|
| 865 |
+
else:
|
| 866 |
+
return default
|
| 867 |
+
|
| 868 |
+
# Retrieve configuration value for pagination
|
| 869 |
+
def _config_pagination(self, view: View):
|
| 870 |
+
default = self.config.pagination
|
| 871 |
+
if isinstance(view, Archive):
|
| 872 |
+
return self._config("archive_pagination", default)
|
| 873 |
+
if isinstance(view, Category):
|
| 874 |
+
return self._config("categories_pagination", default)
|
| 875 |
+
if isinstance(view, Profile):
|
| 876 |
+
return self._config("authors_profiles_pagination", default)
|
| 877 |
+
else:
|
| 878 |
+
return default
|
| 879 |
+
|
| 880 |
+
# Retrieve configuration value for pagination per page
|
| 881 |
+
def _config_pagination_per_page(self, view: View):
|
| 882 |
+
default = self.config.pagination_per_page
|
| 883 |
+
if isinstance(view, Archive):
|
| 884 |
+
return self._config("archive_pagination_per_page", default)
|
| 885 |
+
if isinstance(view, Category):
|
| 886 |
+
return self._config("categories_pagination_per_page", default)
|
| 887 |
+
if isinstance(view, Profile):
|
| 888 |
+
return self._config("authors_profiles_pagination_per_page", default)
|
| 889 |
+
else:
|
| 890 |
+
return default
|
| 891 |
+
|
| 892 |
+
# -------------------------------------------------------------------------
|
| 893 |
+
|
| 894 |
+
# Format path for post
|
| 895 |
+
def _format_path_for_post(self, post: Post, config: MkDocsConfig):
|
| 896 |
+
categories = post.config.categories[:self.config.post_url_max_categories]
|
| 897 |
+
categories = [self._slugify_category(name) for name in categories]
|
| 898 |
+
|
| 899 |
+
# Replace placeholders in format string
|
| 900 |
+
date = post.config.date.created
|
| 901 |
+
path = self.config.post_url_format.format(
|
| 902 |
+
categories = "/".join(categories),
|
| 903 |
+
date = self._format_date_for_post_url(date, config),
|
| 904 |
+
file = post.file.name,
|
| 905 |
+
slug = post.config.slug or self._slugify_post(post)
|
| 906 |
+
)
|
| 907 |
+
|
| 908 |
+
# Normalize path and strip slashes at the beginning and end
|
| 909 |
+
path = posixpath.normpath(path.strip("/"))
|
| 910 |
+
return posixpath.join(self.config.blog_dir, f"{path}.md")
|
| 911 |
+
|
| 912 |
+
# Format path for archive
|
| 913 |
+
def _format_path_for_archive(self, post: Post, config: MkDocsConfig):
|
| 914 |
+
date = post.config.date.created
|
| 915 |
+
path = self.config.archive_url_format.format(
|
| 916 |
+
date = self._format_date_for_archive_url(date, config)
|
| 917 |
+
)
|
| 918 |
+
|
| 919 |
+
# Normalize path and strip slashes at the beginning and end
|
| 920 |
+
path = posixpath.normpath(path.strip("/"))
|
| 921 |
+
return posixpath.join(self.config.blog_dir, f"{path}.md")
|
| 922 |
+
|
| 923 |
+
# Format path for category
|
| 924 |
+
def _format_path_for_category(self, name: str):
|
| 925 |
+
path = self.config.categories_url_format.format(
|
| 926 |
+
slug = self._slugify_category(name)
|
| 927 |
+
)
|
| 928 |
+
|
| 929 |
+
# Normalize path and strip slashes at the beginning and end
|
| 930 |
+
path = posixpath.normpath(path.strip("/"))
|
| 931 |
+
return posixpath.join(self.config.blog_dir, f"{path}.md")
|
| 932 |
+
|
| 933 |
+
# Format path for profile
|
| 934 |
+
def _format_path_for_profile(self, id: str, author: Author):
|
| 935 |
+
path = self.config.authors_profiles_url_format.format(
|
| 936 |
+
slug = author.slug or id,
|
| 937 |
+
name = author.name
|
| 938 |
+
)
|
| 939 |
+
|
| 940 |
+
# Normalize path and strip slashes at the beginning and end
|
| 941 |
+
path = posixpath.normpath(path.strip("/"))
|
| 942 |
+
return posixpath.join(self.config.blog_dir, f"{path}.md")
|
| 943 |
+
|
| 944 |
+
# Format path for pagination
|
| 945 |
+
def _format_path_for_pagination(self, view: View, page: int):
|
| 946 |
+
path = self.config.pagination_url_format.format(
|
| 947 |
+
page = page
|
| 948 |
+
)
|
| 949 |
+
|
| 950 |
+
# Compute base path for pagination - if the given view is an index file,
|
| 951 |
+
# we need to pop the file name from the base so it's not part of the URL
|
| 952 |
+
# and we need to append `index` to the path, so the paginated view is
|
| 953 |
+
# also an index page - see https://t.ly/71MKF
|
| 954 |
+
base, _ = posixpath.splitext(view.file.src_uri)
|
| 955 |
+
if view.is_index:
|
| 956 |
+
base = posixpath.dirname(base)
|
| 957 |
+
path = posixpath.join(path, "index")
|
| 958 |
+
|
| 959 |
+
# Normalize path and strip slashes at the beginning and end
|
| 960 |
+
path = posixpath.normpath(path.strip("/"))
|
| 961 |
+
return posixpath.join(base, f"{path}.md")
|
| 962 |
+
|
| 963 |
+
# -------------------------------------------------------------------------
|
| 964 |
+
|
| 965 |
+
# Format date - if the given format string refers to a predefined format,
|
| 966 |
+
# we format the date without a time component in order to keep sane default
|
| 967 |
+
# behavior, since authors will not expect time to be relevant for most posts
|
| 968 |
+
# as by our assumptions - see https://t.ly/Yi7ZC
|
| 969 |
+
def _format_date(self, date: datetime, format: str, config: MkDocsConfig):
|
| 970 |
+
locale: str = config.theme["language"].replace("-", "_")
|
| 971 |
+
if format in ["full", "long", "medium", "short"]:
|
| 972 |
+
return format_date(date, format = format, locale = locale)
|
| 973 |
+
else:
|
| 974 |
+
return format_datetime(date, format = format, locale = locale)
|
| 975 |
+
|
| 976 |
+
# Format date for post
|
| 977 |
+
def _format_date_for_post(self, date: datetime, config: MkDocsConfig):
|
| 978 |
+
format = self.config.post_date_format
|
| 979 |
+
return self._format_date(date, format, config)
|
| 980 |
+
|
| 981 |
+
# Format date for post URL
|
| 982 |
+
def _format_date_for_post_url(self, date: datetime, config: MkDocsConfig):
|
| 983 |
+
format = self.config.post_url_date_format
|
| 984 |
+
return self._format_date(date, format, config)
|
| 985 |
+
|
| 986 |
+
# Format date for archive
|
| 987 |
+
def _format_date_for_archive(self, date: datetime, config: MkDocsConfig):
|
| 988 |
+
format = self.config.archive_date_format
|
| 989 |
+
return self._format_date(date, format, config)
|
| 990 |
+
|
| 991 |
+
# Format date for archive URL
|
| 992 |
+
def _format_date_for_archive_url(self, date: datetime, config: MkDocsConfig):
|
| 993 |
+
format = self.config.archive_url_date_format
|
| 994 |
+
return self._format_date(date, format, config)
|
| 995 |
+
|
| 996 |
+
# -------------------------------------------------------------------------
|
| 997 |
+
|
| 998 |
+
# Slugify post title
|
| 999 |
+
def _slugify_post(self, post: Post):
|
| 1000 |
+
separator = self.config.post_slugify_separator
|
| 1001 |
+
return self.config.post_slugify(post.title, separator)
|
| 1002 |
+
|
| 1003 |
+
# Slugify category
|
| 1004 |
+
def _slugify_category(self, name: str):
|
| 1005 |
+
separator = self.config.categories_slugify_separator
|
| 1006 |
+
return self.config.categories_slugify(name, separator)
|
| 1007 |
+
|
| 1008 |
+
# -------------------------------------------------------------------------
|
| 1009 |
+
|
| 1010 |
+
# Create a file for the given path, which must point to a valid source file,
|
| 1011 |
+
# either inside the temporary directory or the docs directory
|
| 1012 |
+
def _path_to_file(self, path: str, config: MkDocsConfig, *, temp = True):
|
| 1013 |
+
assert path.endswith(".md")
|
| 1014 |
+
file = File(
|
| 1015 |
+
path,
|
| 1016 |
+
config.docs_dir if not temp else self.temp_dir,
|
| 1017 |
+
config.site_dir,
|
| 1018 |
+
config.use_directory_urls
|
| 1019 |
+
)
|
| 1020 |
+
|
| 1021 |
+
# Hack: mark file as generated, so other plugins don't think it's part
|
| 1022 |
+
# of the file system. This is more or less a new quasi-standard that
|
| 1023 |
+
# still needs to be adopted by MkDocs, and was introduced by the
|
| 1024 |
+
# git-revision-date-localized-plugin - see https://bit.ly/3ZUmdBx
|
| 1025 |
+
if temp:
|
| 1026 |
+
file.generated_by = "material/blog"
|
| 1027 |
+
|
| 1028 |
+
# Return file
|
| 1029 |
+
return file
|
| 1030 |
+
|
| 1031 |
+
# Create a file with the given content on disk
|
| 1032 |
+
def _save_to_file(self, path: str, content: str):
|
| 1033 |
+
os.makedirs(os.path.dirname(path), exist_ok = True)
|
| 1034 |
+
with open(path, "w", encoding = "utf-8") as f:
|
| 1035 |
+
f.write(content)
|
| 1036 |
+
|
| 1037 |
+
# -------------------------------------------------------------------------
|
| 1038 |
+
|
| 1039 |
+
# Translate the placeholder referenced by the given key
|
| 1040 |
+
def _translate(self, key: str, config: MkDocsConfig) -> str:
|
| 1041 |
+
env = config.theme.get_env()
|
| 1042 |
+
template = env.get_template(
|
| 1043 |
+
"partials/language.html", globals = { "config": config }
|
| 1044 |
+
)
|
| 1045 |
+
|
| 1046 |
+
# Translate placeholder
|
| 1047 |
+
return template.module.t(key)
|
| 1048 |
+
|
| 1049 |
+
# -----------------------------------------------------------------------------
|
| 1050 |
+
# Helper functions
|
| 1051 |
+
# -----------------------------------------------------------------------------
|
| 1052 |
+
|
| 1053 |
+
# Find all links in the given list of items
|
| 1054 |
+
def _find_links(items: list[StructureItem]):
|
| 1055 |
+
for item in items:
|
| 1056 |
+
|
| 1057 |
+
# Resolve link
|
| 1058 |
+
if isinstance(item, Link):
|
| 1059 |
+
yield item
|
| 1060 |
+
|
| 1061 |
+
# Resolve sections recursively
|
| 1062 |
+
if isinstance(item, Section):
|
| 1063 |
+
for item in _find_links(item.children):
|
| 1064 |
+
assert isinstance(item, Link)
|
| 1065 |
+
yield item
|
| 1066 |
+
|
| 1067 |
+
# Find anchor in table of contents for the given id
|
| 1068 |
+
def _find_anchor(toc: TableOfContents, id: str):
|
| 1069 |
+
for anchor in toc:
|
| 1070 |
+
if anchor.id == id:
|
| 1071 |
+
return anchor
|
| 1072 |
+
|
| 1073 |
+
# Resolve anchors recursively
|
| 1074 |
+
anchor = _find_anchor(anchor.children, id)
|
| 1075 |
+
if isinstance(anchor, AnchorLink):
|
| 1076 |
+
return anchor
|
| 1077 |
+
|
| 1078 |
+
# -----------------------------------------------------------------------------
|
| 1079 |
+
# Data
|
| 1080 |
+
# -----------------------------------------------------------------------------
|
| 1081 |
+
|
| 1082 |
+
# Set up logging
|
| 1083 |
+
log = logging.getLogger("mkdocs.material.blog")
|
micromamba_root/Lib/site-packages/material/plugins/group/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
micromamba_root/Lib/site-packages/material/plugins/group/config.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
from mkdocs.config.config_options import Type
|
| 22 |
+
from mkdocs.config.base import Config
|
| 23 |
+
|
| 24 |
+
# -----------------------------------------------------------------------------
|
| 25 |
+
# Classes
|
| 26 |
+
# -----------------------------------------------------------------------------
|
| 27 |
+
|
| 28 |
+
# Group plugin configuration
|
| 29 |
+
class GroupConfig(Config):
|
| 30 |
+
enabled = Type(bool, default = False)
|
| 31 |
+
plugins = Type((list, dict))
|
micromamba_root/Lib/site-packages/material/plugins/group/plugin.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
from __future__ import annotations
|
| 22 |
+
|
| 23 |
+
import logging
|
| 24 |
+
|
| 25 |
+
from collections.abc import Callable
|
| 26 |
+
from mkdocs.config.config_options import Plugins
|
| 27 |
+
from mkdocs.config.defaults import MkDocsConfig
|
| 28 |
+
from mkdocs.exceptions import PluginError
|
| 29 |
+
from mkdocs.plugins import BasePlugin, event_priority
|
| 30 |
+
|
| 31 |
+
from .config import GroupConfig
|
| 32 |
+
|
| 33 |
+
# -----------------------------------------------------------------------------
|
| 34 |
+
# Classes
|
| 35 |
+
# -----------------------------------------------------------------------------
|
| 36 |
+
|
| 37 |
+
# Group plugin
|
| 38 |
+
class GroupPlugin(BasePlugin[GroupConfig]):
|
| 39 |
+
supports_multiple_instances = True
|
| 40 |
+
|
| 41 |
+
# Initialize plugin
|
| 42 |
+
def __init__(self, *args, **kwargs):
|
| 43 |
+
super().__init__(*args, **kwargs)
|
| 44 |
+
|
| 45 |
+
# Initialize object attributes
|
| 46 |
+
self.is_serve = False
|
| 47 |
+
self.is_dirty = False
|
| 48 |
+
|
| 49 |
+
# Determine whether we're serving the site
|
| 50 |
+
def on_startup(self, *, command, dirty):
|
| 51 |
+
self.is_serve = command == "serve"
|
| 52 |
+
self.is_dirty = dirty
|
| 53 |
+
|
| 54 |
+
# If the group is enabled, conditionally load plugins - at first, this might
|
| 55 |
+
# sound easier than it actually is, as we need to jump through some hoops to
|
| 56 |
+
# ensure correct ordering among plugins. We're effectively initializing the
|
| 57 |
+
# plugins that are part of the group after all MkDocs finished initializing
|
| 58 |
+
# all other plugins, so we need to patch the order of the methods. Moreover,
|
| 59 |
+
# we must use MkDocs existing plugin collection, or we might have collisions
|
| 60 |
+
# with other plugins that are not part of the group. As so often, this is a
|
| 61 |
+
# little hacky, but has huge potential making plugin configuration easier.
|
| 62 |
+
# There's one little caveat: the `__init__` and `on_startup` methods of the
|
| 63 |
+
# plugins that are part of the group are called after all other plugins, so
|
| 64 |
+
# the `event_priority` decorator for `on_startup` methods is effectively
|
| 65 |
+
# useless. However, the `on_startup` method is only intended to set up the
|
| 66 |
+
# plugin and doesn't receive anything else than the invoked command and
|
| 67 |
+
# whether we're running a dirty build, so there should be no problems.
|
| 68 |
+
@event_priority(150)
|
| 69 |
+
def on_config(self, config):
|
| 70 |
+
if not self.config.enabled:
|
| 71 |
+
return
|
| 72 |
+
|
| 73 |
+
# Retrieve plugin collection from configuration
|
| 74 |
+
option: Plugins = dict(config._schema)["plugins"]
|
| 75 |
+
assert isinstance(option, Plugins)
|
| 76 |
+
|
| 77 |
+
# Load all plugins in group
|
| 78 |
+
self.plugins: dict[str, BasePlugin] = {}
|
| 79 |
+
try:
|
| 80 |
+
for name, plugin in self._load(option):
|
| 81 |
+
self.plugins[name] = plugin
|
| 82 |
+
|
| 83 |
+
# The plugin could not be loaded, likely because it's not installed or
|
| 84 |
+
# misconfigured, so we raise a plugin error for a nicer error message
|
| 85 |
+
except Exception as e:
|
| 86 |
+
raise PluginError(str(e))
|
| 87 |
+
|
| 88 |
+
# Patch order of plugin methods
|
| 89 |
+
for events in option.plugins.events.values():
|
| 90 |
+
self._patch(events, config)
|
| 91 |
+
|
| 92 |
+
# Invoke `on_startup` event for plugins in group
|
| 93 |
+
command = "serve" if self.is_serve else "build"
|
| 94 |
+
for method in option.plugins.events["startup"]:
|
| 95 |
+
plugin = self._get_plugin(method)
|
| 96 |
+
|
| 97 |
+
# Ensure that we have a method bound to a plugin (and not a hook)
|
| 98 |
+
if plugin and plugin in self.plugins.values():
|
| 99 |
+
method(command = command, dirty = self.is_dirty)
|
| 100 |
+
|
| 101 |
+
# -------------------------------------------------------------------------
|
| 102 |
+
|
| 103 |
+
# Retrieve plugin instance for bound method or nothing
|
| 104 |
+
def _get_plugin(self, method: Callable):
|
| 105 |
+
return getattr(method, "__self__", None)
|
| 106 |
+
|
| 107 |
+
# Retrieve priority of plugin method
|
| 108 |
+
def _get_priority(self, method: Callable):
|
| 109 |
+
return getattr(method, "mkdocs_priority", 0)
|
| 110 |
+
|
| 111 |
+
# Retrieve position of plugin
|
| 112 |
+
def _get_position(self, plugin: BasePlugin, config: MkDocsConfig) -> int:
|
| 113 |
+
for at, (_, candidate) in enumerate(config.plugins.items()):
|
| 114 |
+
if plugin == candidate:
|
| 115 |
+
return at
|
| 116 |
+
|
| 117 |
+
# -------------------------------------------------------------------------
|
| 118 |
+
|
| 119 |
+
# Load plugins that are part of the group
|
| 120 |
+
def _load(self, option: Plugins):
|
| 121 |
+
for name, data in option._parse_configs(self.config.plugins):
|
| 122 |
+
yield option.load_plugin_with_namespace(name, data)
|
| 123 |
+
|
| 124 |
+
# -------------------------------------------------------------------------
|
| 125 |
+
|
| 126 |
+
# Patch order of plugin methods - all other plugin methods are already in
|
| 127 |
+
# the right order, so we only need to check those that are part of the group
|
| 128 |
+
# and bubble them up into the right location. Some plugin methods may define
|
| 129 |
+
# priorities, so we need to make sure to order correctly within those.
|
| 130 |
+
def _patch(self, methods: list[Callable], config: MkDocsConfig):
|
| 131 |
+
position = self._get_position(self, config)
|
| 132 |
+
for at in reversed(range(1, len(methods))):
|
| 133 |
+
tail = methods[at - 1]
|
| 134 |
+
head = methods[at]
|
| 135 |
+
|
| 136 |
+
# Skip if the plugin is not part of the group
|
| 137 |
+
plugin = self._get_plugin(head)
|
| 138 |
+
if not plugin or plugin not in self.plugins.values():
|
| 139 |
+
continue
|
| 140 |
+
|
| 141 |
+
# Skip if the previous method has a higher priority than the current
|
| 142 |
+
# one, because we know we can't swap them anyway
|
| 143 |
+
if self._get_priority(tail) > self._get_priority(head):
|
| 144 |
+
continue
|
| 145 |
+
|
| 146 |
+
# Ensure that we have a method bound to a plugin (and not a hook)
|
| 147 |
+
plugin = self._get_plugin(tail)
|
| 148 |
+
if not plugin:
|
| 149 |
+
continue
|
| 150 |
+
|
| 151 |
+
# Both methods have the same priority, so we check if the ordering
|
| 152 |
+
# of both methods is violated, and if it is, swap them
|
| 153 |
+
if (position < self._get_position(plugin, config)):
|
| 154 |
+
methods[at], methods[at - 1] = tail, head
|
| 155 |
+
|
| 156 |
+
# -----------------------------------------------------------------------------
|
| 157 |
+
# Data
|
| 158 |
+
# -----------------------------------------------------------------------------
|
| 159 |
+
|
| 160 |
+
# Set up logging
|
| 161 |
+
log = logging.getLogger("mkdocs.material.group")
|
micromamba_root/Lib/site-packages/material/plugins/info/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
micromamba_root/Lib/site-packages/material/plugins/info/config.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
from mkdocs.config.config_options import Type
|
| 22 |
+
from mkdocs.config.base import Config
|
| 23 |
+
|
| 24 |
+
# -----------------------------------------------------------------------------
|
| 25 |
+
# Classes
|
| 26 |
+
# -----------------------------------------------------------------------------
|
| 27 |
+
|
| 28 |
+
# Info plugin configuration
|
| 29 |
+
class InfoConfig(Config):
|
| 30 |
+
enabled = Type(bool, default = True)
|
| 31 |
+
enabled_on_serve = Type(bool, default = False)
|
| 32 |
+
|
| 33 |
+
# Settings for archive
|
| 34 |
+
archive = Type(bool, default = True)
|
| 35 |
+
archive_stop_on_violation = Type(bool, default = True)
|
micromamba_root/Lib/site-packages/material/plugins/info/patterns.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def get_exclusion_patterns():
|
| 2 |
+
"""
|
| 3 |
+
Regex patterns, which will be compared against directory and file names
|
| 4 |
+
case-sensitively. https://docs.python.org/3/library/re.html#re.search is the
|
| 5 |
+
matching function and scans the whole string to find any pattern match. Used
|
| 6 |
+
with the https://pypi.org/project/regex/ module.
|
| 7 |
+
|
| 8 |
+
Additional remarks for pattern creation:
|
| 9 |
+
- The compared paths will be always in POSIX format.
|
| 10 |
+
- Each directory path will have a / at the end to allow to distinguish them
|
| 11 |
+
from files.
|
| 12 |
+
- Patterns for dynamic or custom paths like Virtual Environments (venv) or
|
| 13 |
+
build site directories are created during plugin runtime.
|
| 14 |
+
"""
|
| 15 |
+
return [
|
| 16 |
+
r"/__pycache__/", # Python cache directory
|
| 17 |
+
|
| 18 |
+
r"/\.DS_Store$", # macOS
|
| 19 |
+
|
| 20 |
+
r"/[^/]+\.zip$", # Generated files and folders
|
| 21 |
+
|
| 22 |
+
r"/[^/]*\.cache($|/)", # .cache files and folders
|
| 23 |
+
|
| 24 |
+
r"/\.vscode/", # Common autogenerated IDE directories
|
| 25 |
+
r"/\.vs/",
|
| 26 |
+
r"/\.idea/",
|
| 27 |
+
]
|
micromamba_root/Lib/site-packages/material/plugins/info/plugin.py
ADDED
|
@@ -0,0 +1,563 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
import getpass
|
| 22 |
+
import glob
|
| 23 |
+
import json
|
| 24 |
+
import logging
|
| 25 |
+
import os
|
| 26 |
+
import platform
|
| 27 |
+
import re
|
| 28 |
+
import requests
|
| 29 |
+
import site
|
| 30 |
+
import sys
|
| 31 |
+
import yaml
|
| 32 |
+
|
| 33 |
+
from colorama import Fore, Style
|
| 34 |
+
from importlib.metadata import distributions, version
|
| 35 |
+
from io import BytesIO
|
| 36 |
+
from markdown.extensions.toc import slugify
|
| 37 |
+
from mkdocs.config.defaults import MkDocsConfig
|
| 38 |
+
from mkdocs.plugins import BasePlugin, event_priority
|
| 39 |
+
from mkdocs.utils.yaml import get_yaml_loader
|
| 40 |
+
from zipfile import ZipFile, ZIP_DEFLATED
|
| 41 |
+
|
| 42 |
+
from .config import InfoConfig
|
| 43 |
+
from .patterns import get_exclusion_patterns
|
| 44 |
+
|
| 45 |
+
# -----------------------------------------------------------------------------
|
| 46 |
+
# Classes
|
| 47 |
+
# -----------------------------------------------------------------------------
|
| 48 |
+
|
| 49 |
+
# Info plugin
|
| 50 |
+
class InfoPlugin(BasePlugin[InfoConfig]):
|
| 51 |
+
|
| 52 |
+
# Initialize plugin
|
| 53 |
+
def __init__(self, *args, **kwargs):
|
| 54 |
+
super().__init__(*args, **kwargs)
|
| 55 |
+
|
| 56 |
+
# Initialize incremental builds
|
| 57 |
+
self.is_serve = False
|
| 58 |
+
|
| 59 |
+
# Initialize empty members
|
| 60 |
+
self.exclusion_patterns = []
|
| 61 |
+
self.excluded_entries = []
|
| 62 |
+
|
| 63 |
+
# Determine whether we're serving the site
|
| 64 |
+
def on_startup(self, *, command, dirty):
|
| 65 |
+
self.is_serve = command == "serve"
|
| 66 |
+
|
| 67 |
+
# Create a self-contained example (run earliest) - determine all files that
|
| 68 |
+
# are visible to MkDocs and are used to build the site, create an archive
|
| 69 |
+
# that contains all of them, and print a summary of the archive contents.
|
| 70 |
+
# The author must attach this archive to the bug report.
|
| 71 |
+
@event_priority(100)
|
| 72 |
+
def on_config(self, config):
|
| 73 |
+
if not self.config.enabled:
|
| 74 |
+
return
|
| 75 |
+
|
| 76 |
+
# By default, the plugin is disabled when the documentation is served,
|
| 77 |
+
# but not when it is built. This should nicely align with the expected
|
| 78 |
+
# user experience when creating reproductions.
|
| 79 |
+
if not self.config.enabled_on_serve and self.is_serve:
|
| 80 |
+
return
|
| 81 |
+
|
| 82 |
+
# Resolve latest version
|
| 83 |
+
url = "https://github.com/squidfunk/mkdocs-material/releases/latest"
|
| 84 |
+
res = requests.get(url, allow_redirects = False)
|
| 85 |
+
|
| 86 |
+
# Check if we're running the latest version
|
| 87 |
+
_, current = res.headers.get("location").rsplit("/", 1)
|
| 88 |
+
present = version("mkdocs-material")
|
| 89 |
+
if not present.startswith(current):
|
| 90 |
+
log.error("Please upgrade to the latest version.")
|
| 91 |
+
self._help_on_versions_and_exit(present, current)
|
| 92 |
+
|
| 93 |
+
# Exit if archive creation is disabled
|
| 94 |
+
if not self.config.archive:
|
| 95 |
+
sys.exit(1)
|
| 96 |
+
|
| 97 |
+
# Print message that we're creating a bug report
|
| 98 |
+
log.info("Started archive creation for bug report")
|
| 99 |
+
|
| 100 |
+
# Check that there are no overrides in place - we need to use a little
|
| 101 |
+
# hack to detect whether the custom_dir setting was used without parsing
|
| 102 |
+
# mkdocs.yml again - we check at which position the directory provided
|
| 103 |
+
# by the theme resides, and if it's not the first one, abort.
|
| 104 |
+
if config.theme.custom_dir:
|
| 105 |
+
log.error("Please remove 'custom_dir' setting.")
|
| 106 |
+
self._help_on_customizations_and_exit()
|
| 107 |
+
|
| 108 |
+
# Check that there are no hooks in place - hooks can alter the behavior
|
| 109 |
+
# of MkDocs in unpredictable ways, which is why they must be considered
|
| 110 |
+
# being customizations. Thus, we can't offer support for debugging and
|
| 111 |
+
# must abort here.
|
| 112 |
+
if config.hooks:
|
| 113 |
+
log.error("Please remove 'hooks' setting.")
|
| 114 |
+
self._help_on_customizations_and_exit()
|
| 115 |
+
|
| 116 |
+
# Assure all paths that will be validated are absolute. Convert possible
|
| 117 |
+
# relative config_file_path to absolute. Its absolute directory path is
|
| 118 |
+
# being later used to resolve other paths.
|
| 119 |
+
config.config_file_path = _convert_to_abs(config.config_file_path)
|
| 120 |
+
config_file_parent = os.path.dirname(config.config_file_path)
|
| 121 |
+
|
| 122 |
+
# Convert relative custom_dir path to absolute. The Theme.custom_dir
|
| 123 |
+
# property cannot be set, therefore a helper variable is used.
|
| 124 |
+
if config.theme.custom_dir:
|
| 125 |
+
abs_custom_dir = _convert_to_abs(
|
| 126 |
+
config.theme.custom_dir,
|
| 127 |
+
abs_prefix = config_file_parent
|
| 128 |
+
)
|
| 129 |
+
else:
|
| 130 |
+
abs_custom_dir = ""
|
| 131 |
+
|
| 132 |
+
# Extract the absolute path to projects plugin's directory to explicitly
|
| 133 |
+
# support path validation and dynamic exclusion for the plugin
|
| 134 |
+
projects_plugin = config.plugins.get("material/projects")
|
| 135 |
+
if projects_plugin:
|
| 136 |
+
abs_projects_dir = _convert_to_abs(
|
| 137 |
+
projects_plugin.config.projects_dir,
|
| 138 |
+
abs_prefix = config_file_parent
|
| 139 |
+
)
|
| 140 |
+
else:
|
| 141 |
+
abs_projects_dir = ""
|
| 142 |
+
|
| 143 |
+
# MkDocs removes the INHERIT configuration key during load, and doesn't
|
| 144 |
+
# expose the information in any way, as the parent configuration is
|
| 145 |
+
# merged into one. To validate that the INHERIT config file will be
|
| 146 |
+
# included in the ZIP file the current config file must be loaded again
|
| 147 |
+
# without parsing. Each file can have their own INHERIT key, so a list
|
| 148 |
+
# of configurations is supported. The INHERIT path is converted during
|
| 149 |
+
# load to absolute.
|
| 150 |
+
loaded_configs = _load_yaml(config.config_file_path)
|
| 151 |
+
if not isinstance(loaded_configs, list):
|
| 152 |
+
loaded_configs = [loaded_configs]
|
| 153 |
+
|
| 154 |
+
# It can happen that the drive letter case is inconsistent on Windows.
|
| 155 |
+
# Therefore, assure first character to be uppercase for the following
|
| 156 |
+
# checks. See: https://t.ly/9t1SU
|
| 157 |
+
site_prefixes = list(map(capitalize, site.PREFIXES))
|
| 158 |
+
cwd = capitalize(os.getcwd())
|
| 159 |
+
|
| 160 |
+
# We need to make sure the user put every file in the current working
|
| 161 |
+
# directory. To assure the reproduction inside the ZIP file can be run,
|
| 162 |
+
# validate that the MkDocs paths are children of the current root.
|
| 163 |
+
paths_to_validate = list(map(capitalize, [
|
| 164 |
+
config.config_file_path,
|
| 165 |
+
config.docs_dir,
|
| 166 |
+
abs_custom_dir,
|
| 167 |
+
abs_projects_dir,
|
| 168 |
+
*[cfg.get("INHERIT", "") for cfg in loaded_configs]
|
| 169 |
+
]))
|
| 170 |
+
|
| 171 |
+
# Convert relative hook paths to absolute path
|
| 172 |
+
for hook in config.hooks:
|
| 173 |
+
path = _convert_to_abs(hook, abs_prefix = config_file_parent)
|
| 174 |
+
paths_to_validate.append(path)
|
| 175 |
+
|
| 176 |
+
# Remove valid paths from the list
|
| 177 |
+
for path in list(paths_to_validate):
|
| 178 |
+
if not path or path.startswith(cwd):
|
| 179 |
+
paths_to_validate.remove(path)
|
| 180 |
+
|
| 181 |
+
# Report the invalid paths to the user
|
| 182 |
+
if paths_to_validate:
|
| 183 |
+
log.error("One or more paths aren't children of root")
|
| 184 |
+
self._help_on_not_in_cwd(paths_to_validate)
|
| 185 |
+
|
| 186 |
+
# Create in-memory archive and prompt author for a short descriptive
|
| 187 |
+
# name for the archive, which is also used as the directory name. Note
|
| 188 |
+
# that the name is slugified for better readability and stripped of any
|
| 189 |
+
# file extension that the author might have entered.
|
| 190 |
+
archive = BytesIO()
|
| 191 |
+
example = input("\nPlease name your bug report (2-4 words): ")
|
| 192 |
+
example, _ = os.path.splitext(example)
|
| 193 |
+
example = "-".join([present, slugify(example, "-")])
|
| 194 |
+
|
| 195 |
+
# Get local copy of the exclusion patterns
|
| 196 |
+
self.exclusion_patterns = get_exclusion_patterns()
|
| 197 |
+
self.excluded_entries = []
|
| 198 |
+
|
| 199 |
+
# Exclude the site_dir at project root
|
| 200 |
+
if capitalize(config.site_dir).startswith(cwd):
|
| 201 |
+
self.exclusion_patterns.append(_resolve_pattern(config.site_dir))
|
| 202 |
+
|
| 203 |
+
# Exclude the Virtual Environment directory. site.getsitepackages() has
|
| 204 |
+
# inconsistent results across operating systems, and relies on the
|
| 205 |
+
# PREFIXES that will contain the absolute path to the activated venv.
|
| 206 |
+
for path in site_prefixes:
|
| 207 |
+
if path.startswith(cwd):
|
| 208 |
+
self.exclusion_patterns.append(_resolve_pattern(path))
|
| 209 |
+
|
| 210 |
+
# Guess other Virtual Environment paths in case we forget to activate
|
| 211 |
+
# them or in case we have multiple. Making sure which venv is activated
|
| 212 |
+
# is not necessary, as it is an optional step in the guidelines.
|
| 213 |
+
for abs_root, dirnames, filenames in os.walk(os.getcwd()):
|
| 214 |
+
for filename in filenames:
|
| 215 |
+
if filename.lower() != "pyvenv.cfg":
|
| 216 |
+
continue
|
| 217 |
+
|
| 218 |
+
path = capitalize(abs_root)
|
| 219 |
+
|
| 220 |
+
if path not in site_prefixes:
|
| 221 |
+
print(f"Possible inactive venv: {path}")
|
| 222 |
+
self.exclusion_patterns.append(_resolve_pattern(path))
|
| 223 |
+
|
| 224 |
+
# Exclude site_dir for projects
|
| 225 |
+
if projects_plugin:
|
| 226 |
+
for path in glob.iglob(
|
| 227 |
+
pathname = projects_plugin.config.projects_config_files,
|
| 228 |
+
root_dir = abs_projects_dir,
|
| 229 |
+
recursive = True
|
| 230 |
+
):
|
| 231 |
+
current_config_file = os.path.join(abs_projects_dir, path)
|
| 232 |
+
project_config = _get_project_config(current_config_file)
|
| 233 |
+
pattern = _resolve_pattern(project_config.site_dir)
|
| 234 |
+
self.exclusion_patterns.append(pattern)
|
| 235 |
+
|
| 236 |
+
# Track dotpath inclusion to inform about it later
|
| 237 |
+
contains_dotpath: bool = False
|
| 238 |
+
|
| 239 |
+
# Create self-contained example from project
|
| 240 |
+
files: list[str] = []
|
| 241 |
+
with ZipFile(archive, "a", ZIP_DEFLATED, False) as f:
|
| 242 |
+
for abs_root, dirnames, filenames in os.walk(os.getcwd()):
|
| 243 |
+
# Set and print progress indicator
|
| 244 |
+
indicator = f"Processing: {abs_root}"
|
| 245 |
+
print(indicator, end="\r", flush=True)
|
| 246 |
+
|
| 247 |
+
# Prune the folders in-place to prevent their processing
|
| 248 |
+
for name in list(dirnames):
|
| 249 |
+
# Resolve the absolute directory path
|
| 250 |
+
path = os.path.join(abs_root, name)
|
| 251 |
+
|
| 252 |
+
# Exclude the directory and all subdirectories
|
| 253 |
+
if self._is_excluded(path):
|
| 254 |
+
dirnames.remove(name)
|
| 255 |
+
continue
|
| 256 |
+
|
| 257 |
+
# Warn about .dotdirectories
|
| 258 |
+
if _is_dotpath(path, log_warning = True):
|
| 259 |
+
contains_dotpath = True
|
| 260 |
+
|
| 261 |
+
# Write files to the in-memory archive
|
| 262 |
+
for name in filenames:
|
| 263 |
+
# Resolve the absolute file path
|
| 264 |
+
path = os.path.join(abs_root, name)
|
| 265 |
+
|
| 266 |
+
# Exclude the file
|
| 267 |
+
if self._is_excluded(path):
|
| 268 |
+
continue
|
| 269 |
+
|
| 270 |
+
# Warn about .dotfiles
|
| 271 |
+
if _is_dotpath(path, log_warning = True):
|
| 272 |
+
contains_dotpath = True
|
| 273 |
+
|
| 274 |
+
# Resolve the relative path to create a matching structure
|
| 275 |
+
path = os.path.relpath(path, os.path.curdir)
|
| 276 |
+
f.write(path, os.path.join(example, path))
|
| 277 |
+
|
| 278 |
+
# Clear the line for the next indicator
|
| 279 |
+
print(" " * len(indicator), end="\r", flush=True)
|
| 280 |
+
|
| 281 |
+
# Add information on installed packages
|
| 282 |
+
f.writestr(
|
| 283 |
+
os.path.join(example, "requirements.lock.txt"),
|
| 284 |
+
"\n".join(sorted([
|
| 285 |
+
"==".join([package.name, package.version])
|
| 286 |
+
for package in distributions()
|
| 287 |
+
]))
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
# Try to get login to replace it with USERNAME placeholder
|
| 291 |
+
try:
|
| 292 |
+
username = getpass.getuser()
|
| 293 |
+
except Exception:
|
| 294 |
+
username = "USERNAME"
|
| 295 |
+
|
| 296 |
+
# Add information on platform
|
| 297 |
+
f.writestr(
|
| 298 |
+
os.path.join(example, "platform.json"),
|
| 299 |
+
json.dumps(
|
| 300 |
+
{
|
| 301 |
+
"system": platform.platform(),
|
| 302 |
+
"architecture": platform.architecture(),
|
| 303 |
+
"python": platform.python_version(),
|
| 304 |
+
"cwd": os.getcwd(),
|
| 305 |
+
"command": " ".join([
|
| 306 |
+
sys.argv[0].rsplit(os.sep, 1)[-1],
|
| 307 |
+
*sys.argv[1:]
|
| 308 |
+
]),
|
| 309 |
+
"env:$PYTHONPATH": os.getenv("PYTHONPATH", ""),
|
| 310 |
+
"env:$VIRTUAL_ENV": os.getenv("VIRTUAL_ENV", ""),
|
| 311 |
+
"sys.path": sys.path,
|
| 312 |
+
"excluded_entries": self.excluded_entries
|
| 313 |
+
},
|
| 314 |
+
default = str,
|
| 315 |
+
indent = 2
|
| 316 |
+
).replace(username, "USERNAME")
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
# Retrieve list of processed files
|
| 320 |
+
for a in f.filelist:
|
| 321 |
+
# Highlight .dotpaths in a more explicit manner
|
| 322 |
+
color = (Fore.LIGHTYELLOW_EX if "/." in a.filename
|
| 323 |
+
else Fore.LIGHTBLACK_EX)
|
| 324 |
+
files.append("".join([
|
| 325 |
+
color, a.filename, " ",
|
| 326 |
+
_size(a.compress_size)
|
| 327 |
+
]))
|
| 328 |
+
|
| 329 |
+
# Finally, write archive to disk
|
| 330 |
+
buffer = archive.getbuffer()
|
| 331 |
+
with open(f"{example}.zip", "wb") as f:
|
| 332 |
+
f.write(archive.getvalue())
|
| 333 |
+
|
| 334 |
+
# Print summary
|
| 335 |
+
log.info("Archive successfully created:")
|
| 336 |
+
print(Style.NORMAL)
|
| 337 |
+
|
| 338 |
+
# Print archive file names
|
| 339 |
+
files.sort()
|
| 340 |
+
for file in files:
|
| 341 |
+
print(f" {file}")
|
| 342 |
+
|
| 343 |
+
# Print archive name
|
| 344 |
+
print(Style.RESET_ALL)
|
| 345 |
+
print("".join([
|
| 346 |
+
" ", f.name, " ",
|
| 347 |
+
_size(buffer.nbytes, 10)
|
| 348 |
+
]))
|
| 349 |
+
|
| 350 |
+
# Print warning when file size is excessively large
|
| 351 |
+
print(Style.RESET_ALL)
|
| 352 |
+
if buffer.nbytes > 1000000:
|
| 353 |
+
log.warning("Archive exceeds recommended maximum size of 1 MB")
|
| 354 |
+
|
| 355 |
+
# Print warning when file contains hidden .dotpaths
|
| 356 |
+
if contains_dotpath:
|
| 357 |
+
log.warning(
|
| 358 |
+
"Archive contains dotpaths, which could contain sensitive "
|
| 359 |
+
"information.\nPlease review them at the bottom of the list "
|
| 360 |
+
"and share only necessary data to reproduce the issue."
|
| 361 |
+
)
|
| 362 |
+
|
| 363 |
+
# Aaaaaand done
|
| 364 |
+
sys.exit(1)
|
| 365 |
+
|
| 366 |
+
# -------------------------------------------------------------------------
|
| 367 |
+
|
| 368 |
+
# Print help on versions and exit
|
| 369 |
+
def _help_on_versions_and_exit(self, have, need):
|
| 370 |
+
print(Fore.RED)
|
| 371 |
+
print(" When reporting issues, please first upgrade to the latest")
|
| 372 |
+
print(" version of Material for MkDocs, as the problem might already")
|
| 373 |
+
print(" be fixed in the latest version. This helps reduce duplicate")
|
| 374 |
+
print(" efforts and saves us maintainers time.")
|
| 375 |
+
print(Style.NORMAL)
|
| 376 |
+
print(f" Please update from {have} to {need}.")
|
| 377 |
+
print(Style.RESET_ALL)
|
| 378 |
+
print(f" pip install --upgrade --force-reinstall mkdocs-material")
|
| 379 |
+
print(Style.NORMAL)
|
| 380 |
+
|
| 381 |
+
# Exit, unless explicitly told not to
|
| 382 |
+
if self.config.archive_stop_on_violation:
|
| 383 |
+
sys.exit(1)
|
| 384 |
+
|
| 385 |
+
# Print help on customizations and exit
|
| 386 |
+
def _help_on_customizations_and_exit(self):
|
| 387 |
+
print(Fore.RED)
|
| 388 |
+
print(" When reporting issues, you must remove all customizations")
|
| 389 |
+
print(" and check if the problem persists. If not, the problem is")
|
| 390 |
+
print(" caused by your overrides. Please understand that we can't")
|
| 391 |
+
print(" help you debug your customizations. Please remove:")
|
| 392 |
+
print(Style.NORMAL)
|
| 393 |
+
print(" - theme.custom_dir")
|
| 394 |
+
print(" - hooks")
|
| 395 |
+
print(Fore.YELLOW)
|
| 396 |
+
print(" Additionally, please remove all third-party JavaScript or")
|
| 397 |
+
print(" CSS not explicitly mentioned in our documentation:")
|
| 398 |
+
print(Style.NORMAL)
|
| 399 |
+
print(" - extra_css")
|
| 400 |
+
print(" - extra_javascript")
|
| 401 |
+
print(Fore.YELLOW)
|
| 402 |
+
print(" If you're using customizations from the theme's documentation")
|
| 403 |
+
print(" and you want to report a bug specific to those customizations")
|
| 404 |
+
print(" then set the 'archive_stop_on_violation: false' option in the")
|
| 405 |
+
print(" info plugin config.")
|
| 406 |
+
print(Style.RESET_ALL)
|
| 407 |
+
|
| 408 |
+
# Exit, unless explicitly told not to
|
| 409 |
+
if self.config.archive_stop_on_violation:
|
| 410 |
+
sys.exit(1)
|
| 411 |
+
|
| 412 |
+
# Print help on not in current working directory and exit
|
| 413 |
+
def _help_on_not_in_cwd(self, outside_root):
|
| 414 |
+
print(Fore.RED)
|
| 415 |
+
print(" The current working (root) directory:\n")
|
| 416 |
+
print(f" {os.getcwd()}\n")
|
| 417 |
+
print(" is not a parent of the following paths:")
|
| 418 |
+
print(Style.NORMAL)
|
| 419 |
+
for path in outside_root:
|
| 420 |
+
print(f" {path}")
|
| 421 |
+
print("\n To assure that all project files are found please adjust")
|
| 422 |
+
print(" your config or file structure and put everything within the")
|
| 423 |
+
print(" root directory of the project.")
|
| 424 |
+
print("\n Please also make sure `mkdocs build` is run in the actual")
|
| 425 |
+
print(" root directory of the project.")
|
| 426 |
+
print(Style.RESET_ALL)
|
| 427 |
+
|
| 428 |
+
# Exit, unless explicitly told not to
|
| 429 |
+
if self.config.archive_stop_on_violation:
|
| 430 |
+
sys.exit(1)
|
| 431 |
+
|
| 432 |
+
# Check if path is excluded and should be omitted from the zip. Use pattern
|
| 433 |
+
# matching for files and folders, and lookahead specific files in folders to
|
| 434 |
+
# skip them. Side effect: Save excluded paths to save them in the zip file.
|
| 435 |
+
def _is_excluded(self, abspath: str) -> bool:
|
| 436 |
+
|
| 437 |
+
# Resolve the path into POSIX format to match the patterns
|
| 438 |
+
pattern_path = _resolve_pattern(abspath, return_path = True)
|
| 439 |
+
for pattern in self.exclusion_patterns:
|
| 440 |
+
if re.search(pattern, pattern_path):
|
| 441 |
+
log.debug(f"Excluded pattern '{pattern}': {abspath}")
|
| 442 |
+
self.excluded_entries.append(f"{pattern} - {pattern_path}")
|
| 443 |
+
return True
|
| 444 |
+
|
| 445 |
+
# File exclusion should be limited to pattern matching
|
| 446 |
+
if os.path.isfile(abspath):
|
| 447 |
+
return False
|
| 448 |
+
|
| 449 |
+
# Projects, which don't use the projects plugin for multi-language
|
| 450 |
+
# support could have separate build folders for each config file or
|
| 451 |
+
# language. Therefore, we exclude them with the assumption a site_dir
|
| 452 |
+
# contains the sitemap file. Example of such a setup: https://t.ly/DLQcy
|
| 453 |
+
sitemap_gz = os.path.join(abspath, "sitemap.xml.gz")
|
| 454 |
+
if os.path.exists(sitemap_gz):
|
| 455 |
+
log.debug(f"Excluded site_dir: {abspath}")
|
| 456 |
+
self.excluded_entries.append(f"sitemap.xml.gz - {pattern_path}")
|
| 457 |
+
return True
|
| 458 |
+
|
| 459 |
+
return False
|
| 460 |
+
|
| 461 |
+
# -----------------------------------------------------------------------------
|
| 462 |
+
# Helper functions
|
| 463 |
+
# -----------------------------------------------------------------------------
|
| 464 |
+
|
| 465 |
+
# Print human-readable size
|
| 466 |
+
def _size(value, factor = 1):
|
| 467 |
+
color = Fore.GREEN
|
| 468 |
+
if value > 100000 * factor: color = Fore.RED
|
| 469 |
+
elif value > 25000 * factor: color = Fore.YELLOW
|
| 470 |
+
for unit in ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB"]:
|
| 471 |
+
if abs(value) < 1000.0:
|
| 472 |
+
return f"{color}{value:3.1f} {unit}"
|
| 473 |
+
value /= 1000.0
|
| 474 |
+
|
| 475 |
+
# Get the absolute path with set prefix. To validate if a file is inside the
|
| 476 |
+
# current working directory it needs to be absolute, so that it is possible to
|
| 477 |
+
# check the prefix.
|
| 478 |
+
def _convert_to_abs(path: str, abs_prefix: str = None) -> str:
|
| 479 |
+
if os.path.isabs(path): return path
|
| 480 |
+
if abs_prefix is None: abs_prefix = os.getcwd()
|
| 481 |
+
return os.path.normpath(os.path.join(abs_prefix, path))
|
| 482 |
+
|
| 483 |
+
# Get the loaded config, or a list with all loaded configs. MkDocs removes the
|
| 484 |
+
# INHERIT configuration key during load, and doesn't expose the information in
|
| 485 |
+
# any way, as the parent configuration is merged into one. The INHERIT path is
|
| 486 |
+
# needed for validation. This custom YAML loader replicates MkDocs' loading
|
| 487 |
+
# logic. Side effect: It converts the INHERIT path to absolute.
|
| 488 |
+
def _load_yaml(abs_src_path: str):
|
| 489 |
+
|
| 490 |
+
with open(abs_src_path, encoding ="utf-8-sig") as file:
|
| 491 |
+
source = file.read()
|
| 492 |
+
|
| 493 |
+
try:
|
| 494 |
+
result = yaml.load(source, Loader = get_yaml_loader()) or {}
|
| 495 |
+
except yaml.YAMLError:
|
| 496 |
+
result = {}
|
| 497 |
+
|
| 498 |
+
if "INHERIT" in result:
|
| 499 |
+
relpath = result.get('INHERIT')
|
| 500 |
+
parent_path = os.path.dirname(abs_src_path)
|
| 501 |
+
abspath = _convert_to_abs(relpath, abs_prefix = parent_path)
|
| 502 |
+
if os.path.exists(abspath):
|
| 503 |
+
result["INHERIT"] = abspath
|
| 504 |
+
log.debug(f"Loading inherited configuration file: {abspath}")
|
| 505 |
+
parent = _load_yaml(abspath)
|
| 506 |
+
if isinstance(parent, list):
|
| 507 |
+
result = [result, *parent]
|
| 508 |
+
elif isinstance(parent, dict):
|
| 509 |
+
result = [result, parent]
|
| 510 |
+
|
| 511 |
+
return result
|
| 512 |
+
|
| 513 |
+
# Get a normalized POSIX path for the pattern matching with removed current
|
| 514 |
+
# working directory prefix. Directory paths end with a '/' to allow more control
|
| 515 |
+
# in the pattern creation for files and directories. The patterns are matched
|
| 516 |
+
# using the search function, so they are prefixed with ^ for specificity.
|
| 517 |
+
def _resolve_pattern(abspath: str, return_path: bool = False):
|
| 518 |
+
path = capitalize(abspath).replace(capitalize(os.getcwd()), "", 1)
|
| 519 |
+
path = path.replace(os.sep, "/").rstrip("/")
|
| 520 |
+
|
| 521 |
+
if not path:
|
| 522 |
+
return "/"
|
| 523 |
+
|
| 524 |
+
# Check abspath, as the file needs to exist
|
| 525 |
+
if not os.path.isfile(abspath):
|
| 526 |
+
path = path + "/"
|
| 527 |
+
|
| 528 |
+
return path if return_path else f"^{path}"
|
| 529 |
+
|
| 530 |
+
# Get project configuration with resolved absolute paths for validation
|
| 531 |
+
def _get_project_config(project_config_file: str):
|
| 532 |
+
with open(project_config_file, encoding="utf-8-sig") as file:
|
| 533 |
+
config = MkDocsConfig(config_file_path = project_config_file)
|
| 534 |
+
config.load_file(file)
|
| 535 |
+
|
| 536 |
+
# MkDocs transforms site_dir to absolute path during validation
|
| 537 |
+
config.validate()
|
| 538 |
+
|
| 539 |
+
return config
|
| 540 |
+
|
| 541 |
+
# Check if the path is a .dotpath. A warning can also be issued when the param
|
| 542 |
+
# is set. The function also returns a boolean to track results outside it.
|
| 543 |
+
def _is_dotpath(path: str, log_warning: bool = False) -> bool:
|
| 544 |
+
posix_path = _resolve_pattern(path, return_path = True)
|
| 545 |
+
name = posix_path.rstrip("/").rsplit("/", 1)[-1]
|
| 546 |
+
if name.startswith("."):
|
| 547 |
+
if log_warning:
|
| 548 |
+
log.warning(f"The following .dotpath will be included: {path}")
|
| 549 |
+
return True
|
| 550 |
+
return False
|
| 551 |
+
|
| 552 |
+
# It can happen that the drive letter case is inconsistent on Windows.
|
| 553 |
+
# Capitalize the first character keeping the rest the same for comparison.
|
| 554 |
+
# See: https://t.ly/9t1SU
|
| 555 |
+
def capitalize(path: str):
|
| 556 |
+
return path[0].upper() + path[1:] if path else path
|
| 557 |
+
|
| 558 |
+
# -----------------------------------------------------------------------------
|
| 559 |
+
# Data
|
| 560 |
+
# -----------------------------------------------------------------------------
|
| 561 |
+
|
| 562 |
+
# Set up logging
|
| 563 |
+
log = logging.getLogger("mkdocs.material.info")
|
micromamba_root/Lib/site-packages/material/plugins/meta/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
micromamba_root/Lib/site-packages/material/plugins/meta/config.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
from mkdocs.config.config_options import Type
|
| 22 |
+
from mkdocs.config.base import Config
|
| 23 |
+
|
| 24 |
+
# -----------------------------------------------------------------------------
|
| 25 |
+
# Classes
|
| 26 |
+
# -----------------------------------------------------------------------------
|
| 27 |
+
|
| 28 |
+
# Meta plugin configuration
|
| 29 |
+
class MetaConfig(Config):
|
| 30 |
+
enabled = Type(bool, default = True)
|
| 31 |
+
|
| 32 |
+
# Settings for meta files
|
| 33 |
+
meta_file = Type(str, default = ".meta.yml")
|
micromamba_root/Lib/site-packages/material/plugins/meta/plugin.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
import logging
|
| 22 |
+
import os
|
| 23 |
+
import posixpath
|
| 24 |
+
|
| 25 |
+
from mergedeep import Strategy, merge
|
| 26 |
+
from mkdocs.exceptions import PluginError
|
| 27 |
+
from mkdocs.structure.files import InclusionLevel
|
| 28 |
+
from mkdocs.plugins import BasePlugin, event_priority
|
| 29 |
+
from yaml import SafeLoader, load
|
| 30 |
+
|
| 31 |
+
from .config import MetaConfig
|
| 32 |
+
|
| 33 |
+
# -----------------------------------------------------------------------------
|
| 34 |
+
# Classes
|
| 35 |
+
# -----------------------------------------------------------------------------
|
| 36 |
+
|
| 37 |
+
# Meta plugin
|
| 38 |
+
class MetaPlugin(BasePlugin[MetaConfig]):
|
| 39 |
+
|
| 40 |
+
# Construct metadata mapping
|
| 41 |
+
def on_files(self, files, *, config):
|
| 42 |
+
if not self.config.enabled:
|
| 43 |
+
return
|
| 44 |
+
|
| 45 |
+
# Initialize mapping
|
| 46 |
+
self.meta = {}
|
| 47 |
+
|
| 48 |
+
# Resolve and load meta files in docs directory
|
| 49 |
+
docs = os.path.relpath(config.docs_dir)
|
| 50 |
+
for file in files:
|
| 51 |
+
name = posixpath.basename(file.src_uri)
|
| 52 |
+
if not name == self.config.meta_file:
|
| 53 |
+
continue
|
| 54 |
+
|
| 55 |
+
# Exclude meta file from site directory - explicitly excluding the
|
| 56 |
+
# meta file allows the author to use a file name without '.' prefix
|
| 57 |
+
file.inclusion = InclusionLevel.EXCLUDED
|
| 58 |
+
|
| 59 |
+
# Open file and parse as YAML
|
| 60 |
+
with open(file.abs_src_path, encoding = "utf-8-sig") as f:
|
| 61 |
+
path = file.src_path
|
| 62 |
+
try:
|
| 63 |
+
self.meta[path] = load(f, SafeLoader)
|
| 64 |
+
|
| 65 |
+
# The meta file could not be loaded because of a syntax error,
|
| 66 |
+
# which we display to the author with a nice error message
|
| 67 |
+
except Exception as e:
|
| 68 |
+
raise PluginError(
|
| 69 |
+
f"Error reading meta file '{path}' in '{docs}':\n"
|
| 70 |
+
f"{e}"
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
# Set metadata for page, if applicable (run earlier)
|
| 74 |
+
@event_priority(50)
|
| 75 |
+
def on_page_markdown(self, markdown, *, page, config, files):
|
| 76 |
+
if not self.config.enabled:
|
| 77 |
+
return
|
| 78 |
+
|
| 79 |
+
# Start with a clean state, as we first need to apply all meta files
|
| 80 |
+
# that are relevant to the current page, and then merge the page meta
|
| 81 |
+
# on top of that to ensure that the page meta always takes precedence
|
| 82 |
+
# over meta files - see https://t.ly/kvCRn
|
| 83 |
+
meta = {}
|
| 84 |
+
|
| 85 |
+
# Merge matching meta files in level-order
|
| 86 |
+
strategy = Strategy.TYPESAFE_ADDITIVE
|
| 87 |
+
for path, defaults in self.meta.items():
|
| 88 |
+
if not page.file.src_path.startswith(os.path.dirname(path)):
|
| 89 |
+
continue
|
| 90 |
+
|
| 91 |
+
# Skip if meta file was already merged - this happens in case of
|
| 92 |
+
# blog posts, as they need to be merged when posts are constructed,
|
| 93 |
+
# which is why we need to keep track of which meta files are applied
|
| 94 |
+
# to what pages using the `__extends` key.
|
| 95 |
+
page.meta.setdefault("__extends", [])
|
| 96 |
+
if path in page.meta["__extends"]:
|
| 97 |
+
continue
|
| 98 |
+
|
| 99 |
+
# Try to merge metadata
|
| 100 |
+
try:
|
| 101 |
+
merge(meta, defaults, strategy = strategy)
|
| 102 |
+
page.meta["__extends"].append(path)
|
| 103 |
+
|
| 104 |
+
# Merging the metadata with the given strategy resulted in an error,
|
| 105 |
+
# which we display to the author with a nice error message
|
| 106 |
+
except Exception as e:
|
| 107 |
+
docs = os.path.relpath(config.docs_dir)
|
| 108 |
+
raise PluginError(
|
| 109 |
+
f"Error merging meta file '{path}' in '{docs}':\n"
|
| 110 |
+
f"{e}"
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# Ensure page metadata is merged last, so the author can override any
|
| 114 |
+
# defaults from the meta files, or even remove them entirely
|
| 115 |
+
page.meta = merge(meta, page.meta, strategy = strategy)
|
| 116 |
+
|
| 117 |
+
# -----------------------------------------------------------------------------
|
| 118 |
+
# Data
|
| 119 |
+
# -----------------------------------------------------------------------------
|
| 120 |
+
|
| 121 |
+
# Set up logging
|
| 122 |
+
log = logging.getLogger("mkdocs.material.meta")
|
micromamba_root/Lib/site-packages/material/plugins/offline/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
micromamba_root/Lib/site-packages/material/plugins/offline/config.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
from mkdocs.config.config_options import Type
|
| 22 |
+
from mkdocs.config.base import Config
|
| 23 |
+
|
| 24 |
+
# -----------------------------------------------------------------------------
|
| 25 |
+
# Classes
|
| 26 |
+
# -----------------------------------------------------------------------------
|
| 27 |
+
|
| 28 |
+
# Offline plugin configuration
|
| 29 |
+
class OfflineConfig(Config):
|
| 30 |
+
enabled = Type(bool, default = True)
|
micromamba_root/Lib/site-packages/material/plugins/offline/plugin.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
import os
|
| 22 |
+
|
| 23 |
+
from mkdocs.plugins import BasePlugin, event_priority
|
| 24 |
+
|
| 25 |
+
from .config import OfflineConfig
|
| 26 |
+
|
| 27 |
+
# -----------------------------------------------------------------------------
|
| 28 |
+
# Classes
|
| 29 |
+
# -----------------------------------------------------------------------------
|
| 30 |
+
|
| 31 |
+
# Offline plugin
|
| 32 |
+
class OfflinePlugin(BasePlugin[OfflineConfig]):
|
| 33 |
+
|
| 34 |
+
# Set configuration for offline build
|
| 35 |
+
def on_config(self, config):
|
| 36 |
+
if not self.config.enabled:
|
| 37 |
+
return
|
| 38 |
+
|
| 39 |
+
# Ensure correct resolution of links when viewing the site from the
|
| 40 |
+
# file system by disabling directory URLs
|
| 41 |
+
config.use_directory_urls = False
|
| 42 |
+
|
| 43 |
+
# Append iframe-worker to polyfills/shims
|
| 44 |
+
config.extra["polyfills"] = config.extra.get("polyfills", [])
|
| 45 |
+
if not any("iframe-worker" in url for url in config.extra["polyfills"]):
|
| 46 |
+
script = "https://unpkg.com/iframe-worker/shim"
|
| 47 |
+
config.extra["polyfills"].append(script)
|
| 48 |
+
|
| 49 |
+
# Add support for offline search (run latest) - the search index is copied
|
| 50 |
+
# and inlined into a script, so that it can be used without a server
|
| 51 |
+
@event_priority(-100)
|
| 52 |
+
def on_post_build(self, *, config):
|
| 53 |
+
if not self.config.enabled:
|
| 54 |
+
return
|
| 55 |
+
|
| 56 |
+
# Ensure presence of search index
|
| 57 |
+
path = os.path.join(config.site_dir, "search")
|
| 58 |
+
file = os.path.join(path, "search_index.json")
|
| 59 |
+
if not os.path.isfile(file):
|
| 60 |
+
return
|
| 61 |
+
|
| 62 |
+
# Obtain search index contents
|
| 63 |
+
with open(file, encoding = "utf-8") as f:
|
| 64 |
+
data = f.read()
|
| 65 |
+
|
| 66 |
+
# Inline search index contents into script
|
| 67 |
+
file = os.path.join(path, "search_index.js")
|
| 68 |
+
with open(file, "w", encoding = "utf-8") as f:
|
| 69 |
+
f.write(f"var __index = {data}")
|
micromamba_root/Lib/site-packages/material/plugins/optimize/config.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2016-2025 Martin Donath <martin.donath@squidfunk.com>
|
| 2 |
+
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to
|
| 5 |
+
# deal in the Software without restriction, including without limitation the
|
| 6 |
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
| 7 |
+
# sell copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in
|
| 11 |
+
# all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 18 |
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
# IN THE SOFTWARE.
|
| 20 |
+
|
| 21 |
+
import os
|
| 22 |
+
|
| 23 |
+
from mkdocs.config.base import Config
|
| 24 |
+
from mkdocs.config.config_options import ListOfItems, Type
|
| 25 |
+
|
| 26 |
+
# -----------------------------------------------------------------------------
|
| 27 |
+
# Classes
|
| 28 |
+
# -----------------------------------------------------------------------------
|
| 29 |
+
|
| 30 |
+
# Optimize plugin configuration
|
| 31 |
+
class OptimizeConfig(Config):
|
| 32 |
+
enabled = Type(bool, default = True)
|
| 33 |
+
concurrency = Type(int, default = max(1, os.cpu_count() - 1))
|
| 34 |
+
|
| 35 |
+
# Settings for caching
|
| 36 |
+
cache = Type(bool, default = True)
|
| 37 |
+
cache_dir = Type(str, default = ".cache/plugin/optimize")
|
| 38 |
+
|
| 39 |
+
# Settings for optimization
|
| 40 |
+
optimize = Type(bool, default = True)
|
| 41 |
+
optimize_png = Type(bool, default = True)
|
| 42 |
+
optimize_png_speed = Type(int, default = 3)
|
| 43 |
+
optimize_png_strip = Type(bool, default = True)
|
| 44 |
+
optimize_jpg = Type(bool, default = True)
|
| 45 |
+
optimize_jpg_quality = Type(int, default = 60)
|
| 46 |
+
optimize_jpg_progressive = Type(bool, default = True)
|
| 47 |
+
optimize_include = ListOfItems(Type(str), default = [])
|
| 48 |
+
optimize_exclude = ListOfItems(Type(str), default = [])
|
| 49 |
+
|
| 50 |
+
# Settings for reporting
|
| 51 |
+
print_gain = Type(bool, default = True)
|
| 52 |
+
print_gain_summary = Type(bool, default = True)
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/journal-whills.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/jpy.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/jug-detergent.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/k.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kaaba.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/key.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/keyboard.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/khanda.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kip-sign.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kiss-beam.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kiss-wink-heart.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kiss.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kit-medical.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kitchen-set.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/kiwi-bird.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/krw.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/l.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/ladder-water.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/land-mine-on.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/landmark-alt.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/landmark-dome.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/landmark-flag.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/landmark.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/language.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laptop-code.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laptop-file.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laptop-house.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laptop-medical.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laptop.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/lari-sign.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laugh-beam.svg
ADDED
|
|
micromamba_root/Lib/site-packages/material/templates/.icons/fontawesome/solid/laugh-squint.svg
ADDED
|
|