diff --git a/CHANGELOG.md b/CHANGELOG.md index c74d545..8f22119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,11 +44,6 @@ --- -## Removed Features -- Any obsolete or unused features from `export-docs.old.py` were removed to streamline the codebase. - ---- - ## Performance Improvements - Optimized file processing loop to handle large repositories more efficiently. - Improved Playwright's rendering performance by preloading images and resources. diff --git a/README.md b/README.md index bc9f4d0..aae096b 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ docs_dir = "docs" ``` ### Output -- PDF file: `Next.js_Docs_vXX.XX.X_YYYY-MM-DD.pdf` +- PDF file: `Next.js_Docs_vXX.XX.X_YYYY-MM-DD.pdf` or `Next.js_Documentation.pdf` - Logs: Process information printed to the terminal. --- diff --git a/export-docs.py b/export-docs.py index 4ca16f4..fa9a7a6 100644 --- a/export-docs.py +++ b/export-docs.py @@ -1,3 +1,30 @@ +""" +Nextjs Documentation PDF Generator +Modified version of Docs-Exporter for Astro documentation + +Original work Copyright (C) 2024 Riyooo +Modified work Copyright (C) 2024 PacNPal + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + +Modifications: +- Replaced wkhtmltopdf with Playwright for PDF generation +- Improved error handling and reporting +- Added support for custom headers, footers, and styles in the generated PDFs. +- Enhanced error handling with `try-except` blocks, especially for frontmatter parsing and file operations. +""" + import os import markdown import tempfile @@ -10,6 +37,33 @@ from packaging import version from tqdm import tqdm from playwright.sync_api import sync_playwright +def get_license_notice(): + """Return a formatted license notice for inclusion in output""" + return """ +This PDF was generated by Nextjs Documentation PDF Generator +Original work Copyright (C) 2024 Riyooo +Modified work Copyright (C) 2024 PacNPal + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License version 3. +Source code is available at: https://github.com/pacnpal/Docs-Exporter +""" + +def add_license_page(html_content): + """Add a license notice page to the HTML content""" + license_html = f""" +
+

License Notice

+
+            {get_license_notice()}
+        
+

Complete source code for this program is available at: https://github.com/pacnpal/Docs-Exporter

+

This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you + are welcome to redistribute it under certain conditions. See the GNU Affero General + Public License version 3 for details.

+
+ """ + return html_content + license_html def process_image_paths(md_content): # Define a regular expression pattern to find image tags @@ -304,7 +358,13 @@ if __name__ == "__main__": path_args = "&w=1920&q=75" clone_repo(repo_url, branch, docs_dir, repo_dir) - + print(f""" + Nextjs Documentation PDF Generator v1.0.0 + Copyright (C) 2024 PacNPal + This program comes with ABSOLUTELY NO WARRANTY; for details see the LICENSE file. + This is free software, and you are welcome to redistribute it + under certain conditions; see the LICENSE file for details. + """) print("Converting the Documentation to HTML...") docs_dir_full_path = os.path.join(repo_dir, docs_dir) files_to_process = get_files_sorted(docs_dir_full_path) @@ -372,6 +432,7 @@ if __name__ == "__main__": try: print("Generating PDF...") # Generate PDF with cover page and content + html_all_content = add_license_page(html_all_content) generate_pdf(cover_html + html_all_content, output_pdf, format_options) print("Created the PDF file successfully.")