Browse Source

🔨 Modify `mkdocs_hooks.py` to add `title` to page's metadata (remove permalinks in social cards) (#14125)

pull/14129/head
Motov Yurii 5 days ago
committed by GitHub
parent
commit
06367347e6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      .github/workflows/build-docs.yml
  2. 9
      scripts/mkdocs_hooks.py

1
.github/workflows/build-docs.yml

@ -40,6 +40,7 @@ jobs:
- mkdocs.no-insiders.yml - mkdocs.no-insiders.yml
- .github/workflows/build-docs.yml - .github/workflows/build-docs.yml
- .github/workflows/deploy-docs.yml - .github/workflows/deploy-docs.yml
- scripts/mkdocs_hooks.py
langs: langs:
needs: needs:
- changes - changes

9
scripts/mkdocs_hooks.py

@ -132,6 +132,15 @@ def on_pre_page(page: Page, *, config: MkDocsConfig, files: Files) -> Page:
def on_page_markdown( def on_page_markdown(
markdown: str, *, page: Page, config: MkDocsConfig, files: Files markdown: str, *, page: Page, config: MkDocsConfig, files: Files
) -> str: ) -> str:
# Set matadata["social"]["cards_layout_options"]["title"] to clean title (without
# permalink)
title = page.title
clean_title = title.split("{ #")[0]
if clean_title:
page.meta.setdefault("social", {})
page.meta["social"].setdefault("cards_layout_options", {})
page.meta["social"]["cards_layout_options"]["title"] = clean_title
if isinstance(page.file, EnFile): if isinstance(page.file, EnFile):
for excluded_section in non_translated_sections: for excluded_section in non_translated_sections:
if page.file.src_path.startswith(excluded_section): if page.file.src_path.startswith(excluded_section):

Loading…
Cancel
Save