Skip to content

Commit

Permalink
Harmonized color and font settings for social cards with Insiders
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed May 8, 2023
1 parent 2735c87 commit 09feabc
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
41 changes: 37 additions & 4 deletions material/plugins/social/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,17 @@ class SocialPluginConfig(Config):
# Options for social cards
cards = opt.Type(bool, default = True)
cards_dir = opt.Type(str, default = "assets/images/social")
cards_color = opt.Type(dict, default = dict())
cards_font = opt.Optional(opt.Type(str))
cards_layout_options = opt.Type(dict, default = {})

# Deprecated options
cards_color = opt.Deprecated(
message =
"Deprecated, use 'cards_layout_options.background_color' "
"and 'cards_layout_options.color' with 'default' layout"
)
cards_font = opt.Deprecated(
message = "Deprecated, use 'cards_layout_options.font_family'"
)

# -----------------------------------------------------------------------------

Expand All @@ -76,6 +85,24 @@ def on_config(self, config):
if not self.config.cards:
return

# Move color options
if "cards_color" in self.config:

# Move background color to new option
value = self.config.cards_color.get("fill")
if value:
self.config.cards_layout_options["background_color"] = value

# Move color to new option
value = self.config.cards_color.get("text")
if value:
self.config.cards_layout_options["color"] = value

# Move font family to new option
if "cards_font" in self.config:
value = self.config.cards_font
self.config.cards_layout_options["font_family"] = value

# Check if required dependencies are installed
if not dependencies:
log.error(
Expand Down Expand Up @@ -111,7 +138,13 @@ def on_config(self, config):
self.color = colors.get(primary, self.color)

# Retrieve color overrides
self.color = { **self.color, **self.config.cards_color }
self.color = {
**self.color,
**{
"fill": self.config.cards_layout_options.get("background_color"),
"text": self.config.cards_layout_options.get("color")
}
}

# Retrieve custom_dir path
for user_config in config.user_configs:
Expand Down Expand Up @@ -406,7 +439,7 @@ def _load_logo_svg(self, path, fill = None):

# Retrieve font
def _load_font(self, config):
name = self.config.cards_font
name = self.config.cards_layout_options.get("font_family")
if not name:

# Retrieve from theme (default: Roboto)
Expand Down
41 changes: 37 additions & 4 deletions src/plugins/social/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,17 @@ class SocialPluginConfig(Config):
# Options for social cards
cards = opt.Type(bool, default = True)
cards_dir = opt.Type(str, default = "assets/images/social")
cards_color = opt.Type(dict, default = dict())
cards_font = opt.Optional(opt.Type(str))
cards_layout_options = opt.Type(dict, default = {})

# Deprecated options
cards_color = opt.Deprecated(
message =
"Deprecated, use 'cards_layout_options.background_color' "
"and 'cards_layout_options.color' with 'default' layout"
)
cards_font = opt.Deprecated(
message = "Deprecated, use 'cards_layout_options.font_family'"
)

# -----------------------------------------------------------------------------

Expand All @@ -76,6 +85,24 @@ def on_config(self, config):
if not self.config.cards:
return

# Move color options
if "cards_color" in self.config:

# Move background color to new option
value = self.config.cards_color.get("fill")
if value:
self.config.cards_layout_options["background_color"] = value

# Move color to new option
value = self.config.cards_color.get("text")
if value:
self.config.cards_layout_options["color"] = value

# Move font family to new option
if "cards_font" in self.config:
value = self.config.cards_font
self.config.cards_layout_options["font_family"] = value

# Check if required dependencies are installed
if not dependencies:
log.error(
Expand Down Expand Up @@ -111,7 +138,13 @@ def on_config(self, config):
self.color = colors.get(primary, self.color)

# Retrieve color overrides
self.color = { **self.color, **self.config.cards_color }
self.color = {
**self.color,
**{
"fill": self.config.cards_layout_options.get("background_color"),
"text": self.config.cards_layout_options.get("color")
}
}

# Retrieve custom_dir path
for user_config in config.user_configs:
Expand Down Expand Up @@ -406,7 +439,7 @@ def _load_logo_svg(self, path, fill = None):

# Retrieve font
def _load_font(self, config):
name = self.config.cards_font
name = self.config.cards_layout_options.get("font_family")
if not name:

# Retrieve from theme (default: Roboto)
Expand Down

0 comments on commit 09feabc

Please sign in to comment.