Skip to content

Commit c5052d7

Browse files
author
George Song
committed
fix: skip StubCards index files
Former-commit-id: 2111ad6
1 parent dc4adb9 commit c5052d7

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

Diff for: scripts/pdf/generate_pdf.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
import os
23
import re
34
from argparse import ArgumentParser, ArgumentTypeError
45
from dataclasses import dataclass
@@ -9,18 +10,20 @@
910

1011
BASE_DIR = Path(__file__).resolve().parent
1112

12-
ANSI_STOP = "\033[0m"
1313
ANSI_BLUE = "\033[34m"
14+
ANSI_STOP = "\033[0m"
15+
ANSI_YELLOW = "\033[33m"
1416

1517

1618
def main(args):
1719
doc_path, product, version, mdx_file, html_file, cover_file, pdf_file = setup(args)
1820

19-
print(f"{ANSI_BLUE}building {pdf_file}{ANSI_STOP}")
20-
2121
files = list_files(doc_path)
2222
if len(files) == 0:
23-
raise Exception(f"no files in {doc_path}")
23+
print(f"{ANSI_YELLOW}skipping {pdf_file}{ANSI_STOP}")
24+
return
25+
26+
print(f"{ANSI_BLUE}building {pdf_file}{ANSI_STOP}")
2427

2528
pattern = re.compile('div id="(.*?)" class="registered_link"')
2629
for elem in files:
@@ -91,11 +94,10 @@ def main(args):
9194
run(["open", html_file])
9295
else:
9396
print("generating cover page")
94-
with open(BASE_DIR / "cover.html") as source, open(cover_file, "w") as output:
95-
data = source.read()
96-
data = data.replace("[PRODUCT]", title)
97-
data = data.replace("[VERSION]", version)
98-
output.write(data)
97+
data = (BASE_DIR / "cover.html").read_text()
98+
data = data.replace("[PRODUCT]", title)
99+
data = data.replace("[VERSION]", version)
100+
cover_file.write_text(data)
99101

100102
header_footer_common = [
101103
"--header-font-name",
@@ -202,11 +204,15 @@ def filter_path(path):
202204
if path.is_dir() and not path.match("*images*"):
203205
return True
204206
elif path.suffix in [".mdx", ".md"]:
205-
with open(path) as f:
206-
content = re.sub(
207-
"^---$.*?^---$", "", f.read(), flags=re.DOTALL | re.MULTILINE
208-
).strip()
209-
return False if content == "" else True
207+
content = re.sub(
208+
"^---$.*?^---$", "", path.read_text(), flags=re.DOTALL | re.MULTILINE
209+
).strip()
210+
211+
no_content = content == "" or (
212+
len(content.split(os.linesep)) == 1 and "StubCards" in content
213+
)
214+
215+
return False if no_content else True
210216
else:
211217
return False
212218

0 commit comments

Comments
 (0)