Skip to content

Commit b82b140

Browse files
committed
formatting
1 parent 5fa8b44 commit b82b140

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

build.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,18 @@
1818

1919

2020
def clone(branch: str, tmp_dir: str) -> None:
21-
subprocess.run([
22-
"git",
23-
"clone",
24-
"--single-branch",
25-
"-b",
26-
branch,
27-
"--depth",
28-
"1",
29-
"https://github.com/openssl/openssl",
30-
tmp_dir
31-
])
21+
subprocess.run(
22+
["git", "clone", "--single-branch", "-b", branch, "--depth", "1", "https://github.com/openssl/openssl", tmp_dir]
23+
)
3224

3325

3426
def build_manpages(tmp_dir: str):
3527
if return_code := subprocess.run(["sh", "config"], cwd=tmp_dir).returncode != 0:
3628
raise SystemExit(return_code)
37-
if return_code := subprocess.run(["make", "-j", str(os.cpu_count()), "build_man_docs"], cwd=tmp_dir).returncode != 0:
29+
if (
30+
return_code := subprocess.run(["make", "-j", str(os.cpu_count()), "build_man_docs"], cwd=tmp_dir).returncode
31+
!= 0
32+
):
3833
raise SystemExit(return_code)
3934

4035

hooks.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import shutil
2+
13
import marko
2-
from marko.md_renderer import MarkdownRenderer
34
from marko.block import Heading
5+
from marko.md_renderer import MarkdownRenderer
6+
from mkdocs import plugins
7+
from mkdocs.config.defaults import MkDocsConfig
48
from mkdocs.structure.files import Files
59
from mkdocs.structure.nav import Link
610
from mkdocs.structure.nav import Navigation
711
from mkdocs.structure.pages import Page
8-
from mkdocs.config.defaults import MkDocsConfig
9-
import shutil
1012

1113
MAN_INDEXES = ["man1/index.md", "man3/index.md", "man5/index.md", "man7/index.md"]
1214
SKIP_FILES = ["index.md", "fips.md"]
@@ -24,7 +26,7 @@ def get_names_paragraph(content: str) -> str:
2426
if append:
2527
paragraph_lines.append(line)
2628
return " ".join(paragraph_lines)
27-
29+
2830

2931
def get_names(content: str) -> list[str]:
3032
names_paragraph = get_names_paragraph(content)
@@ -41,7 +43,9 @@ def on_pre_build(config: MkDocsConfig) -> None:
4143
shutil.copytree("scaffold", "docs", dirs_exist_ok=True)
4244

4345

44-
def populate_index_content(source_md: str, page: Page, files: Files) -> str:
46+
def populate_index_content(source_md: str, page: Page, config: MkDocsConfig, files: Files) -> str:
47+
if page.file.src_uri not in MAN_INDEXES:
48+
return source_md
4549
current_man_dir = page.parent.title.lower()
4650
rows = []
4751
for man_file in files.documentation_pages():
@@ -60,7 +64,9 @@ def populate_index_content(source_md: str, page: Page, files: Files) -> str:
6064
return source_md + "\n".join(sorted(rows))
6165

6266

63-
def fix_headings(source_md: str, page: Page) -> str:
67+
def fix_headings(source_md: str, page: Page, config: MkDocsConfig, files: Files) -> str:
68+
if page.file.src_uri in SKIP_FILES + MAN_INDEXES:
69+
return source_md
6470
parser = marko.Markdown(renderer=MarkdownRenderer)
6571
new_children = []
6672
h1_parsed = parser.parse(f"# {page.file.name}")
@@ -78,12 +84,13 @@ def fix_headings(source_md: str, page: Page) -> str:
7884
return parser.render(parsed)
7985

8086

81-
def on_page_markdown(source_md: str, page: Page, config: MkDocsConfig, files: Files) -> str:
82-
if page.file.src_uri in SKIP_FILES:
87+
def fix_img_links(source_md: str, page: Page, config: MkDocsConfig, files: Files) -> str:
88+
if not page.file.name.startswith("life_cycle-"):
8389
return source_md
84-
if page.file.src_uri in MAN_INDEXES:
85-
return populate_index_content(source_md, page, files)
86-
return fix_headings(source_md, page)
90+
return source_md.replace('<img src="', '<img src="../')
91+
92+
93+
on_page_markdown = plugins.CombinedEvent(fix_headings, fix_img_links, populate_index_content)
8794

8895

8996
def populate_nav(files: Files) -> dict[str, list[Link]]:
@@ -115,7 +122,7 @@ def on_nav(nav: Navigation, config: MkDocsConfig, files: Files) -> Navigation:
115122
"man1": "Commands",
116123
"man3": "Libraries",
117124
"man5": "File Formats",
118-
"man7": "Overviews"
125+
"man7": "Overviews",
119126
}
120127
nav_children = populate_nav(files)
121128
for item in nav.items:

0 commit comments

Comments
 (0)