|
6 | 6 |
|
7 | 7 | # standard library |
8 | 8 | import json |
9 | | -from hashlib import md5 |
10 | 9 | from pathlib import Path |
11 | 10 |
|
12 | 11 | # 3rd party |
@@ -98,8 +97,7 @@ def __init__(self, mkdocs_config: MkDocsConfig, switch_force: bool = True) -> No |
98 | 97 | mkdocs_config=mkdocs_config |
99 | 98 | ) |
100 | 99 |
|
101 | | - if self.is_mkdocs_theme_material_insiders(): |
102 | | - self.load_cache_cards_manifest() |
| 100 | + self.load_cache_cards_manifest() |
103 | 101 |
|
104 | 102 | # store some attributes used to compute social card hash |
105 | 103 | self.site_name = mkdocs_config.site_name |
@@ -307,61 +305,37 @@ def get_social_card_cache_path_for_page( |
307 | 305 | ) -> Path | None: |
308 | 306 | """Get social card path in social plugin cache folder for a specific page. |
309 | 307 |
|
310 | | - Note: |
311 | | - As we write this code (June 2024), the cache mechanism in Insiders edition |
312 | | - has stores images directly with the corresponding Page's path and name and |
313 | | - keep a correspondance matrix with hashes in a manifest.json; |
314 | | - the cache mechanism in Community edition uses the hash as file names without |
315 | | - any exposed matching criteria. |
| 308 | + The cache mechanism in stores images directly with the |
| 309 | + corresponding Page's path and name and keep a correspondance matrix with hashes |
| 310 | + in a manifest.json. |
316 | 311 |
|
317 | 312 | Args: |
318 | 313 | mkdocs_page: Mkdocs page object. |
319 | 314 |
|
320 | 315 | Returns: |
321 | 316 | path to the image in local cache folder if it exists |
322 | 317 | """ |
323 | | - if self.IS_INSIDERS: |
324 | | - |
325 | | - # if page is a blog post |
326 | | - if ( |
327 | | - self.integration_material_blog.IS_BLOG_PLUGIN_ENABLED |
328 | | - and self.integration_material_blog.is_page_a_blog_post(mkdocs_page) |
329 | | - ): |
330 | | - expected_cached_card_path = self.social_cards_cache_dir.joinpath( |
331 | | - f"assets/images/social/{Path(mkdocs_page.dest_uri).parent}.png" |
332 | | - ) |
333 | | - else: |
334 | | - expected_cached_card_path = self.social_cards_cache_dir.joinpath( |
335 | | - f"assets/images/social/{Path(mkdocs_page.src_uri).with_suffix('.png')}" |
336 | | - ) |
337 | | - |
338 | | - if expected_cached_card_path.is_file(): |
339 | | - logger.debug( |
340 | | - f"Social card file found in cache folder: {expected_cached_card_path}" |
341 | | - ) |
342 | | - return expected_cached_card_path |
343 | | - else: |
344 | | - logger.debug( |
345 | | - f"Social card not found in cache folder: {expected_cached_card_path}" |
346 | | - ) |
347 | | - |
348 | | - else: |
349 | | - if "description" in mkdocs_page.meta: |
350 | | - description = mkdocs_page.meta["description"] |
351 | | - else: |
352 | | - description = self.site_description |
353 | | - |
354 | | - page_hash = md5( |
355 | | - "".join( |
356 | | - [ |
357 | | - self.site_name, |
358 | | - str(mkdocs_page.meta.get("title", mkdocs_page.title)), |
359 | | - description, |
360 | | - ] |
361 | | - ).encode("utf-8") |
| 318 | + # if page is a blog post |
| 319 | + if ( |
| 320 | + self.integration_material_blog.IS_BLOG_PLUGIN_ENABLED |
| 321 | + and self.integration_material_blog.is_page_a_blog_post(mkdocs_page) |
| 322 | + ): |
| 323 | + expected_cached_card_path = self.social_cards_cache_dir.joinpath( |
| 324 | + f"assets/images/social/{Path(mkdocs_page.dest_uri).parent}.png" |
362 | 325 | ) |
| 326 | + else: |
363 | 327 | expected_cached_card_path = self.social_cards_cache_dir.joinpath( |
364 | | - f"{page_hash.hexdigest()}.png" |
| 328 | + f"assets/images/social/{Path(mkdocs_page.src_uri).with_suffix('.png')}" |
| 329 | + ) |
| 330 | + |
| 331 | + if expected_cached_card_path.is_file(): |
| 332 | + logger.debug( |
| 333 | + f"Social card file found in cache folder: {expected_cached_card_path}" |
| 334 | + ) |
| 335 | + return expected_cached_card_path |
| 336 | + else: |
| 337 | + logger.debug( |
| 338 | + f"Social card not found in cache folder: {expected_cached_card_path}" |
365 | 339 | ) |
366 | 340 |
|
367 | 341 | if expected_cached_card_path.is_file(): |
|
0 commit comments