Thanks to visit codestin.com
Credit goes to github.com

Skip to content

🔧 Update docs setup with latest configs and plugins#11953

Merged
tiangolo merged 11 commits into
masterfrom
mkdocs-updates
Aug 6, 2024
Merged

🔧 Update docs setup with latest configs and plugins#11953
tiangolo merged 11 commits into
masterfrom
mkdocs-updates

Conversation

@tiangolo

@tiangolo tiangolo commented Aug 6, 2024

Copy link
Copy Markdown
Member

🔧 Update docs setup with latest configs and plugins

Update docs

Tabs

To update the tabs I ran this script update_tabs.py in an interactive window:

import os
import re
from dataclasses import dataclass, field
from pathlib import Path

base_dir = Path(__file__).parent

@dataclass
class Tab:
    title: str
    content: list[str] = field(default_factory=list)

    def __str__(self) -> str:
        content = "\n".join(self.content).strip()
        return f"//// tab | {self.title}\n\n{content}\n\n////\n"


def generate_new_content(content: str) -> str:
    new_content_blocks = []
    open_tab: Tab | None = None
    lines = content.splitlines()
    for line in lines:
        if open_tab:
            if line.startswith("    "):
                open_tab.content.append(line[4:])
                continue
            elif line == "":
                open_tab.content.append(line)
                continue
            else:
                new_content_blocks.append(str(open_tab))
                open_tab = None
        if line.startswith("=== "):
            match = re.match(r'=== "(.*)"', line)
            assert match
            title = match.group(1)
            open_tab = Tab(title=title)
            continue
        new_content_blocks.append(line)
    if open_tab:
        new_content_blocks.append(str(open_tab))
    new_content = "\n".join(new_content_blocks)
    return new_content.strip() + "\n"


def update_md_files_tabs() -> None:
    os.chdir(base_dir)
    md_files = list(Path("docs").glob("**/*.md"))
    for md_file in md_files:
        content = md_file.read_text()
        new_content = generate_new_content(content)
        md_file.write_text(new_content)


if __name__ == "__main__":
    update_md_files_tabs()

Admonitions

To update the admonitions I ran this script update_admonitions.py in an interactive window:

import os
import re
from dataclasses import dataclass, field
from pathlib import Path

base_dir = Path(__file__).parent

@dataclass
class Admonition:
    type: str
    title: str = ""
    content: list[str] = field(default_factory=list)

    def __str__(self) -> str:
        content = "\n".join(self.content).strip()
        if self.title:
            return f"/// {self.type} | {self.title}\n\n{content}\n\n///\n"
        return f"/// {self.type}\n\n{content}\n\n///\n"


def generate_new_content(content: str) -> str:
    new_content_blocks = []
    open_admonition: Admonition | None = None
    lines = content.splitlines()
    for line in lines:
        if open_admonition:
            if line.startswith("    "):
                open_admonition.content.append(line[4:])
                continue
            elif line == "":
                open_admonition.content.append(line)
                continue
            else:
                new_content_blocks.append(str(open_admonition))
                open_admonition = None
        if line.startswith("!!! "):
            no_title_match = re.match(r'!!! (\S*)$', line)
            title_match = re.match(r'!!! (\S*) (.*)$', line)
            title_match_quotes = re.match(r'!!! (\S*) "(.*)"$', line)
            if no_title_match:
                type = no_title_match.group(1).lower()
                open_admonition = Admonition(type=type)
                continue
            elif title_match:
                type = title_match.group(1).lower()
                title = title_match.group(2)
                open_admonition = Admonition(type=type, title=title)
                continue
            elif title_match_quotes:
                type = title_match_quotes.group(1).lower()
                title = title_match_quotes.group(2)
                open_admonition = Admonition(type=type, title=title)
                continue
            raise RuntimeError("Should not reach here")
        new_content_blocks.append(line)
    if open_admonition:
        new_content_blocks.append(str(open_admonition))
    new_content = "\n".join(new_content_blocks)
    return new_content.strip() + "\n"


def update_md_files_tabs() -> None:
    os.chdir(base_dir)
    md_files = list(Path("docs").glob("**/*.md"))
    for md_file in md_files:
        content = md_file.read_text()
        new_content = generate_new_content(content)
        md_file.write_text(new_content)


if __name__ == "__main__":
    update_md_files_tabs()

@github-actions

github-actions Bot commented Aug 6, 2024

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit c0588d4 at: https://4301f451.fastapitiangolo.pages.dev

@github-actions

github-actions Bot commented Aug 6, 2024

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit 6901534 at: https://76acb0a8.fastapitiangolo.pages.dev

@github-actions

github-actions Bot commented Aug 6, 2024

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit 04b6487 at: https://d5e6ef06.fastapitiangolo.pages.dev

@github-actions

github-actions Bot commented Aug 6, 2024

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit 561d6cb at: https://1a8c2176.fastapitiangolo.pages.dev

@tiangolo tiangolo marked this pull request as ready for review August 6, 2024 04:48
@tiangolo tiangolo merged commit 0cd844d into master Aug 6, 2024
@tiangolo tiangolo deleted the mkdocs-updates branch August 6, 2024 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant