@@ -68,6 +68,7 @@ class SocialPlugin(BasePlugin[SocialPluginConfig]):
68
68
69
69
def __init__ (self ):
70
70
self ._executor = concurrent .futures .ThreadPoolExecutor (4 )
71
+ self .custom_dir = None
71
72
72
73
# Retrieve configuration
73
74
def on_config (self , config ):
@@ -112,6 +113,13 @@ def on_config(self, config):
112
113
# Retrieve color overrides
113
114
self .color = { ** self .color , ** self .config .cards_color }
114
115
116
+ # Retrieve custom_dir path
117
+ for user_config in config .user_configs :
118
+ custom_dir = user_config .get ("theme" , {}).get ("custom_dir" )
119
+ if custom_dir :
120
+ self .custom_dir = custom_dir
121
+ break
122
+
115
123
# Retrieve logo and font
116
124
self ._resized_logo_promise = self ._executor .submit (self ._load_resized_logo , config )
117
125
self .font = self ._load_font (config )
@@ -344,28 +352,43 @@ def _load_logo(self, config):
344
352
if "logo" in theme :
345
353
_ , extension = os .path .splitext (theme ["logo" ])
346
354
347
- # Load SVG and convert to PNG
348
355
path = os .path .join (config .docs_dir , theme ["logo" ])
356
+
357
+ # Allow users to put the logo inside their custom_dir (theme["logo"] case)
358
+ if self .custom_dir :
359
+ custom_dir_logo = os .path .join (self .custom_dir , theme ["logo" ])
360
+ if os .path .exists (custom_dir_logo ):
361
+ path = custom_dir_logo
362
+
363
+ # Load SVG and convert to PNG
349
364
if extension == ".svg" :
350
365
return self ._load_logo_svg (path )
351
366
352
367
# Load PNG, JPEG, etc.
353
368
return Image .open (path ).convert ("RGBA" )
354
369
355
370
# Handle icons
356
- logo = "material/library"
357
371
icon = theme ["icon" ] or {}
358
372
if "logo" in icon and icon ["logo" ]:
359
373
logo = icon ["logo" ]
374
+ else :
375
+ logo = "material/library"
360
376
361
377
# Resolve path of package
362
378
base = os .path .abspath (os .path .join (
363
379
os .path .dirname (__file__ ),
364
380
"../.."
365
381
))
366
382
367
- # Load icon data and fill with color
368
383
path = f"{ base } /.icons/{ logo } .svg"
384
+
385
+ # Allow users to put the logo inside their custom_dir (theme["icon"]["logo"] case)
386
+ if self .custom_dir :
387
+ custom_dir_logo = os .path .join (self .custom_dir , ".icons" , f"{ logo } .svg" )
388
+ if os .path .exists (custom_dir_logo ):
389
+ path = custom_dir_logo
390
+
391
+ # Load icon data and fill with color
369
392
return self ._load_logo_svg (path , self .color ["text" ])
370
393
371
394
# Load SVG file and convert to PNG
0 commit comments