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

@@ -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 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"""
<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):
# 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.")