Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Aug 23, 2023
1 parent 6a6d2d8 commit 92fc7f6
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 48 deletions.
4 changes: 2 additions & 2 deletions material/.overrides/hooks/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def on_page_markdown(markdown: str, *, page: Page, config: MkDocsConfig, files):
return

# Collect all existing languages
names: dict[str, str] = dict()
known: dict[str, dict[str, str]] = dict()
names: dict[str, str] = {}
known: dict[str, dict[str, str]] = {}
for path in glob("src/partials/languages/*.html"):
with open(path, "r", encoding = "utf-8") as f:
data = f.read()
Expand Down
4 changes: 2 additions & 2 deletions material/plugins/blog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def on_page_markdown(self, markdown, *, page, config, files):
# is not already present, so we can remove footnotes or other content
# from the excerpt without affecting the content of the excerpt
if separator not in page.markdown:
path = page.file.src_uri
path = page.file.src_path
if self.config.post_excerpt == "required":
raise PluginError(
f"Couldn't find '{separator}' separator in '{path}'"
Expand Down Expand Up @@ -415,7 +415,7 @@ def _resolve_authors(self, config: MkDocsConfig):
docs = os.path.relpath(config.docs_dir)
file = os.path.join(docs, path)
if not os.path.isfile(file):
authors: dict[str, Author] = dict()
authors: dict[str, Author] = {}
return authors

# Open file and parse as YAML
Expand Down
4 changes: 2 additions & 2 deletions material/plugins/blog/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def __init__(self, file: File, config: MkDocsConfig):

# Excerpts are subsets of posts that are used in pages like archive and
# category views. They are not rendered as standalone pages, but are
# included in the context of the parent post. Each post has a dedicated
# excerpt instance which is reused when rendering views.
# rendered in the context of a view. Each post has a dedicated excerpt
# instance which is reused when rendering views.
self.excerpt: Excerpt = None

# Initialize authors and actegories
Expand Down
5 changes: 2 additions & 3 deletions material/plugins/info/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def on_config(self, config):
# hack to detect whether the custom_dir setting was used without parsing
# mkdocs.yml again - we check at which position the directory provided
# by the theme resides, and if it's not the first one, abort.
path = get_theme_dir(config.theme.name)
if config.theme.dirs.index(path):
if config.theme.dirs.index(get_theme_dir(config.theme.name)):
log.error("Please remove 'custom_dir' setting.")
self._help_on_customizations_and_exit()

Expand Down Expand Up @@ -130,7 +129,7 @@ def on_config(self, config):
]))
)

# Add information in platform
# Add information on platform
f.writestr(
os.path.join(example, "platform.json"),
json.dumps(
Expand Down
2 changes: 1 addition & 1 deletion material/plugins/search/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class Element:
"""

# Initialize HTML element
def __init__(self, tag, attrs = dict()):
def __init__(self, tag, attrs = {}):
self.tag = tag
self.attrs = attrs

Expand Down
28 changes: 15 additions & 13 deletions material/plugins/social/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

# -----------------------------------------------------------------------------
# Disclaimer
# -----------------------------------------------------------------------------
# Please note: this version of the social plugin is not actively development
# anymore. Instead, Material for MkDocs Insiders ships a complete rewrite of
# the plugin which is much more powerful and addresses all shortcomings of
# this implementation. Additionally, the new social plugin allows to create
# entirely custom social cards. You can probably imagine, that this was a lot
# of work to pull off. If you run into problems, or want to have additional
# functionality, please consider sponsoring the project. You can then use the
# new version of the plugin immediately.
# -----------------------------------------------------------------------------

import concurrent.futures
import functools
import logging
Expand Down Expand Up @@ -159,7 +172,7 @@ def on_page_markdown(self, markdown, page, config, files):
)
sys.exit(1)

# Generate social card if not in cache - TODO: values from mkdocs.yml
# Generate social card if not in cache
hash = md5("".join([
site_name,
str(title),
Expand Down Expand Up @@ -267,17 +280,6 @@ def _render_text(self, size, font, text, lmax, spacing = 0):
lines.append(words)
words = [word]

# # Balance words on last line - TODO: overflows when broken word is too long
# if len(lines) > 0:
# prev = len(" ".join(lines[-1]))
# last = len(" ".join(words))#

# print(last, prev)

# # Heuristic: try to find a good ratio
# if last / prev < 0.6:
# words.insert(0, lines[-1].pop())

# Join words for each line and create image
lines.append(words)
lines = [" ".join(line) for line in lines]
Expand Down Expand Up @@ -424,7 +426,7 @@ def _load_font(self, config):
font_filename_base = name.replace(' ', '')
filename_regex = re.escape(font_filename_base)+r"-(\w+)\.[ot]tf$"

font = dict()
font = {}
# Check for cached files - note these may be in subfolders
for currentpath, folders, files in os.walk(self.cache):
for file in files:
Expand Down
2 changes: 1 addition & 1 deletion material/plugins/tags/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TagsConfig(Config):

# Options for tags
tags_file = Optional(Type(str))
tags_extra_files = Type(dict, default = dict())
tags_extra_files = Type(dict, default = {})
tags_slugify = Type((type(slugify), partial), default = slugify)
tags_slugify_separator = Type(str, default = "-")
tags_compare = Optional(Type(type(casefold)))
Expand Down
4 changes: 2 additions & 2 deletions src/.overrides/hooks/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def on_page_markdown(markdown: str, *, page: Page, config: MkDocsConfig, files):
return

# Collect all existing languages
names: dict[str, str] = dict()
known: dict[str, dict[str, str]] = dict()
names: dict[str, str] = {}
known: dict[str, dict[str, str]] = {}
for path in glob("src/partials/languages/*.html"):
with open(path, "r", encoding = "utf-8") as f:
data = f.read()
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/blog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def on_page_markdown(self, markdown, *, page, config, files):
# is not already present, so we can remove footnotes or other content
# from the excerpt without affecting the content of the excerpt
if separator not in page.markdown:
path = page.file.src_uri
path = page.file.src_path
if self.config.post_excerpt == "required":
raise PluginError(
f"Couldn't find '{separator}' separator in '{path}'"
Expand Down Expand Up @@ -415,7 +415,7 @@ def _resolve_authors(self, config: MkDocsConfig):
docs = os.path.relpath(config.docs_dir)
file = os.path.join(docs, path)
if not os.path.isfile(file):
authors: dict[str, Author] = dict()
authors: dict[str, Author] = {}
return authors

# Open file and parse as YAML
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/blog/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def __init__(self, file: File, config: MkDocsConfig):

# Excerpts are subsets of posts that are used in pages like archive and
# category views. They are not rendered as standalone pages, but are
# included in the context of the parent post. Each post has a dedicated
# excerpt instance which is reused when rendering views.
# rendered in the context of a view. Each post has a dedicated excerpt
# instance which is reused when rendering views.
self.excerpt: Excerpt = None

# Initialize authors and actegories
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/info/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def on_config(self, config):
# hack to detect whether the custom_dir setting was used without parsing
# mkdocs.yml again - we check at which position the directory provided
# by the theme resides, and if it's not the first one, abort.
path = get_theme_dir(config.theme.name)
if config.theme.dirs.index(path):
if config.theme.dirs.index(get_theme_dir(config.theme.name)):
log.error("Please remove 'custom_dir' setting.")
self._help_on_customizations_and_exit()

Expand Down Expand Up @@ -130,7 +129,7 @@ def on_config(self, config):
]))
)

# Add information in platform
# Add information on platform
f.writestr(
os.path.join(example, "platform.json"),
json.dumps(
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/search/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class Element:
"""

# Initialize HTML element
def __init__(self, tag, attrs = dict()):
def __init__(self, tag, attrs = {}):
self.tag = tag
self.attrs = attrs

Expand Down
28 changes: 15 additions & 13 deletions src/plugins/social/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

# -----------------------------------------------------------------------------
# Disclaimer
# -----------------------------------------------------------------------------
# Please note: this version of the social plugin is not actively development
# anymore. Instead, Material for MkDocs Insiders ships a complete rewrite of
# the plugin which is much more powerful and addresses all shortcomings of
# this implementation. Additionally, the new social plugin allows to create
# entirely custom social cards. You can probably imagine, that this was a lot
# of work to pull off. If you run into problems, or want to have additional
# functionality, please consider sponsoring the project. You can then use the
# new version of the plugin immediately.
# -----------------------------------------------------------------------------

import concurrent.futures
import functools
import logging
Expand Down Expand Up @@ -159,7 +172,7 @@ def on_page_markdown(self, markdown, page, config, files):
)
sys.exit(1)

# Generate social card if not in cache - TODO: values from mkdocs.yml
# Generate social card if not in cache
hash = md5("".join([
site_name,
str(title),
Expand Down Expand Up @@ -267,17 +280,6 @@ def _render_text(self, size, font, text, lmax, spacing = 0):
lines.append(words)
words = [word]

# # Balance words on last line - TODO: overflows when broken word is too long
# if len(lines) > 0:
# prev = len(" ".join(lines[-1]))
# last = len(" ".join(words))#

# print(last, prev)

# # Heuristic: try to find a good ratio
# if last / prev < 0.6:
# words.insert(0, lines[-1].pop())

# Join words for each line and create image
lines.append(words)
lines = [" ".join(line) for line in lines]
Expand Down Expand Up @@ -424,7 +426,7 @@ def _load_font(self, config):
font_filename_base = name.replace(' ', '')
filename_regex = re.escape(font_filename_base)+r"-(\w+)\.[ot]tf$"

font = dict()
font = {}
# Check for cached files - note these may be in subfolders
for currentpath, folders, files in os.walk(self.cache):
for file in files:
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tags/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TagsConfig(Config):

# Options for tags
tags_file = Optional(Type(str))
tags_extra_files = Type(dict, default = dict())
tags_extra_files = Type(dict, default = {})
tags_slugify = Type((type(slugify), partial), default = slugify)
tags_slugify_separator = Type(str, default = "-")
tags_compare = Optional(Type(type(casefold)))
Expand Down

0 comments on commit 92fc7f6

Please sign in to comment.