Updated with more info, better LICENSE adherance

This commit is contained in:
pacnpal
2024-12-09 20:48:32 -05:00
parent c54abe94c9
commit 056c7956e7
3 changed files with 63 additions and 7 deletions

View File

@@ -44,11 +44,6 @@
--- ---
## Removed Features
- Any obsolete or unused features from `export-docs.old.py` were removed to streamline the codebase.
---
## Performance Improvements ## Performance Improvements
- Optimized file processing loop to handle large repositories more efficiently. - Optimized file processing loop to handle large repositories more efficiently.
- Improved Playwright's rendering performance by preloading images and resources. - Improved Playwright's rendering performance by preloading images and resources.

View File

@@ -70,7 +70,7 @@ docs_dir = "docs"
``` ```
### Output ### 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. - Logs: Process information printed to the terminal.
--- ---

View File

@@ -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 <https://www.gnu.org/licenses/>.
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 os
import markdown import markdown
import tempfile import tempfile
@@ -10,6 +37,33 @@ from packaging import version
from tqdm import tqdm from tqdm import tqdm
from playwright.sync_api import sync_playwright 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"""
<div class="license-notice" style="page-break-before: always;">
<h2>License Notice</h2>
<pre style="white-space: pre-wrap; font-family: monospace;">
{get_license_notice()}
</pre>
<p>Complete source code for this program is available at: https://github.com/pacnpal/Docs-Exporter</p>
<p>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.</p>
</div>
"""
return html_content + license_html
def process_image_paths(md_content): def process_image_paths(md_content):
# Define a regular expression pattern to find image tags # Define a regular expression pattern to find image tags
@@ -304,7 +358,13 @@ if __name__ == "__main__":
path_args = "&w=1920&q=75" path_args = "&w=1920&q=75"
clone_repo(repo_url, branch, docs_dir, repo_dir) 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...") print("Converting the Documentation to HTML...")
docs_dir_full_path = os.path.join(repo_dir, docs_dir) docs_dir_full_path = os.path.join(repo_dir, docs_dir)
files_to_process = get_files_sorted(docs_dir_full_path) files_to_process = get_files_sorted(docs_dir_full_path)
@@ -372,6 +432,7 @@ if __name__ == "__main__":
try: try:
print("Generating PDF...") print("Generating PDF...")
# Generate PDF with cover page and content # 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) generate_pdf(cover_html + html_all_content, output_pdf, format_options)
print("Created the PDF file successfully.") print("Created the PDF file successfully.")