Skip to content

Commit 37695bd

Browse files
committed
Review directory structure for printable documentation
1 parent a376cc6 commit 37695bd

16 files changed

+19
-17
lines changed

.DS_Store

0 Bytes
Binary file not shown.

pdf/docs.py renamed to pdf/ly_user_guide.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from reportlab.lib.pagesizes import A4
66

77
BASE_URL = "http://docs.nomana-it.fr"
8+
TEMP_FOLDER = "pdf-temp"
89
OUTPUT_FOLDER = "pdf-output"
910
COVER_FOLDER = "pdf-cover"
10-
PDF_NAME = "final_documentation.pdf"
11+
PDF_NAME = "Liberty_User_Guide.pdf"
1112
COVER_FILE = os.path.join(COVER_FOLDER, "liberty_cover.pdf")
1213

1314
# Hardcoded Navigation Structure
@@ -110,7 +111,7 @@ def generate_toc(pages_with_numbers):
110111
</body>
111112
</html>
112113
"""
113-
toc_file = os.path.join(OUTPUT_FOLDER, "toc.html")
114+
toc_file = os.path.join(TEMP_FOLDER, "toc.html")
114115
with open(toc_file, "w") as file:
115116
file.write(toc_html)
116117
print(f"TOC generated as {toc_file}")
@@ -156,8 +157,9 @@ def add_page_numbers(input_file, output_file):
156157
print(f"PDF with page numbers saved to {output_file}")
157158

158159
# Generate PDF with Playwright
159-
def generate_pdf_with_cover_and_toc(base_url, pages_with_titles, output_folder):
160-
os.makedirs(output_folder, exist_ok=True)
160+
def generate_pdf_with_cover_and_toc(base_url, pages_with_titles):
161+
os.makedirs(TEMP_FOLDER, exist_ok=True)
162+
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
161163

162164
with sync_playwright() as p:
163165
browser = p.chromium.launch()
@@ -174,7 +176,7 @@ def generate_pdf_with_cover_and_toc(base_url, pages_with_titles, output_folder):
174176
continue
175177

176178
url = f"{base_url}/{page_path}"
177-
output_path = os.path.join(output_folder, f"{page_path.replace('/', '_')}.pdf")
179+
output_path = os.path.join(TEMP_FOLDER, f"{page_path.replace('/', '_')}.pdf")
178180
page = context.new_page()
179181
page.goto(url, wait_until="networkidle")
180182
handle_cookie_consent(page)
@@ -200,7 +202,7 @@ def generate_pdf_with_cover_and_toc(base_url, pages_with_titles, output_folder):
200202

201203

202204

203-
toc_file = os.path.join(output_folder, "toc.pdf")
205+
toc_file = os.path.join(TEMP_FOLDER, "toc.pdf")
204206
generate_toc(page_numbers)
205207

206208
toc_page = context.new_page()
@@ -212,12 +214,12 @@ def generate_pdf_with_cover_and_toc(base_url, pages_with_titles, output_folder):
212214
)
213215

214216

215-
merged_output = os.path.join(output_folder, PDF_NAME)
217+
merged_output = os.path.join(TEMP_FOLDER, PDF_NAME)
216218
merge_pdfs(pdf_paths, merged_output)
217219
add_page_numbers(merged_output, merged_output)
218220

219221
final_pdf_paths = [COVER_FILE, toc_file, merged_output]
220-
final_output_path = os.path.join(output_folder, PDF_NAME)
222+
final_output_path = os.path.join(OUTPUT_FOLDER, PDF_NAME)
221223
merge_pdfs(final_pdf_paths, final_output_path)
222224

223225
browser.close()
@@ -233,4 +235,4 @@ def merge_pdfs(input_files, output_file):
233235

234236
if __name__ == "__main__":
235237
pages_with_titles = flatten_nav(NAV)
236-
generate_pdf_with_cover_and_toc(BASE_URL, pages_with_titles, OUTPUT_FOLDER)
238+
generate_pdf_with_cover_and_toc(BASE_URL, pages_with_titles)
-11.5 KB
Binary file not shown.

pdf/pdf-temp/Liberty_User_Guide.pdf

1.88 MB
Binary file not shown.
21.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)