Skip to content

Commit 09feabc

Browse files
committed
Harmonized color and font settings for social cards with Insiders
1 parent 2735c87 commit 09feabc

File tree

2 files changed

+74
-8
lines changed

2 files changed

+74
-8
lines changed

material/plugins/social/plugin.py

+37-4
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,17 @@ class SocialPluginConfig(Config):
5858
# Options for social cards
5959
cards = opt.Type(bool, default = True)
6060
cards_dir = opt.Type(str, default = "assets/images/social")
61-
cards_color = opt.Type(dict, default = dict())
62-
cards_font = opt.Optional(opt.Type(str))
61+
cards_layout_options = opt.Type(dict, default = {})
62+
63+
# Deprecated options
64+
cards_color = opt.Deprecated(
65+
message =
66+
"Deprecated, use 'cards_layout_options.background_color' "
67+
"and 'cards_layout_options.color' with 'default' layout"
68+
)
69+
cards_font = opt.Deprecated(
70+
message = "Deprecated, use 'cards_layout_options.font_family'"
71+
)
6372

6473
# -----------------------------------------------------------------------------
6574

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

88+
# Move color options
89+
if "cards_color" in self.config:
90+
91+
# Move background color to new option
92+
value = self.config.cards_color.get("fill")
93+
if value:
94+
self.config.cards_layout_options["background_color"] = value
95+
96+
# Move color to new option
97+
value = self.config.cards_color.get("text")
98+
if value:
99+
self.config.cards_layout_options["color"] = value
100+
101+
# Move font family to new option
102+
if "cards_font" in self.config:
103+
value = self.config.cards_font
104+
self.config.cards_layout_options["font_family"] = value
105+
79106
# Check if required dependencies are installed
80107
if not dependencies:
81108
log.error(
@@ -111,7 +138,13 @@ def on_config(self, config):
111138
self.color = colors.get(primary, self.color)
112139

113140
# Retrieve color overrides
114-
self.color = { **self.color, **self.config.cards_color }
141+
self.color = {
142+
**self.color,
143+
**{
144+
"fill": self.config.cards_layout_options.get("background_color"),
145+
"text": self.config.cards_layout_options.get("color")
146+
}
147+
}
115148

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

407440
# Retrieve font
408441
def _load_font(self, config):
409-
name = self.config.cards_font
442+
name = self.config.cards_layout_options.get("font_family")
410443
if not name:
411444

412445
# Retrieve from theme (default: Roboto)

src/plugins/social/plugin.py

+37-4
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,17 @@ class SocialPluginConfig(Config):
5858
# Options for social cards
5959
cards = opt.Type(bool, default = True)
6060
cards_dir = opt.Type(str, default = "assets/images/social")
61-
cards_color = opt.Type(dict, default = dict())
62-
cards_font = opt.Optional(opt.Type(str))
61+
cards_layout_options = opt.Type(dict, default = {})
62+
63+
# Deprecated options
64+
cards_color = opt.Deprecated(
65+
message =
66+
"Deprecated, use 'cards_layout_options.background_color' "
67+
"and 'cards_layout_options.color' with 'default' layout"
68+
)
69+
cards_font = opt.Deprecated(
70+
message = "Deprecated, use 'cards_layout_options.font_family'"
71+
)
6372

6473
# -----------------------------------------------------------------------------
6574

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

88+
# Move color options
89+
if "cards_color" in self.config:
90+
91+
# Move background color to new option
92+
value = self.config.cards_color.get("fill")
93+
if value:
94+
self.config.cards_layout_options["background_color"] = value
95+
96+
# Move color to new option
97+
value = self.config.cards_color.get("text")
98+
if value:
99+
self.config.cards_layout_options["color"] = value
100+
101+
# Move font family to new option
102+
if "cards_font" in self.config:
103+
value = self.config.cards_font
104+
self.config.cards_layout_options["font_family"] = value
105+
79106
# Check if required dependencies are installed
80107
if not dependencies:
81108
log.error(
@@ -111,7 +138,13 @@ def on_config(self, config):
111138
self.color = colors.get(primary, self.color)
112139

113140
# Retrieve color overrides
114-
self.color = { **self.color, **self.config.cards_color }
141+
self.color = {
142+
**self.color,
143+
**{
144+
"fill": self.config.cards_layout_options.get("background_color"),
145+
"text": self.config.cards_layout_options.get("color")
146+
}
147+
}
115148

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

407440
# Retrieve font
408441
def _load_font(self, config):
409-
name = self.config.cards_font
442+
name = self.config.cards_layout_options.get("font_family")
410443
if not name:
411444

412445
# Retrieve from theme (default: Roboto)

0 commit comments

Comments
 (0)